Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulator: scale-in and scale out test for store-limit-version=v2 #8220

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion server/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@
// @Router /store/{id}/limit [post]
func (h *storeHandler) SetStoreLimit(w http.ResponseWriter, r *http.Request) {
rc := getCluster(r)
if version := rc.GetScheduleConfig().StoreLimitVersion; version != storelimit.VersionV1 {
h.rd.JSON(w, http.StatusBadRequest, fmt.Sprintf("current store limit version:%s not support set limit", version))
return
}
vars := mux.Vars(r)
storeID, errParse := apiutil.ParseUint64VarsField(vars, "id")
if errParse != nil {
Expand Down Expand Up @@ -405,6 +409,11 @@
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /stores/limit [post]
func (h *storesHandler) SetAllStoresLimit(w http.ResponseWriter, r *http.Request) {
cfg := h.GetScheduleConfig()
if version := cfg.StoreLimitVersion; version != storelimit.VersionV1 {
h.rd.JSON(w, http.StatusBadRequest, fmt.Sprintf("current store limit version:%s not support get limit", version))
return

Check warning on line 415 in server/api/store.go

View check run for this annotation

Codecov / codecov/patch

server/api/store.go#L414-L415

Added lines #L414 - L415 were not covered by tests
}
var input map[string]any
if err := apiutil.ReadJSONRespondError(h.rd, w, r.Body, &input); err != nil {
return
Expand Down Expand Up @@ -485,7 +494,12 @@
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /stores/limit [get]
func (h *storesHandler) GetAllStoresLimit(w http.ResponseWriter, r *http.Request) {
limits := h.GetScheduleConfig().StoreLimit
cfg := h.GetScheduleConfig()
if version := cfg.StoreLimitVersion; version != storelimit.VersionV1 {
h.rd.JSON(w, http.StatusBadRequest, fmt.Sprintf("current store limit version:%s not support get limit", version))
return
}
Comment on lines +497 to +501
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do SetStoreLimitSceneandGetStoreLimitScene` only need to support v2 as well?

limits := cfg.StoreLimit
includeTombstone := false
var err error
if includeStr := r.URL.Query().Get("include_tombstone"); includeStr != "" {
Expand Down
32 changes: 32 additions & 0 deletions tools/pd-ctl/tests/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ import (
"go.etcd.io/etcd/pkg/transport"
)

func TestStoreLimitV2(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
pdAddr := cluster.GetConfig().GetClientURL()
cmd := ctl.GetRootCmd()

leaderServer := cluster.GetLeaderServer()
re.NoError(leaderServer.BootstrapCluster())
defer cluster.Destroy()

// store command
args := []string{"-u", pdAddr, "config", "set", "store-limit-version", "v2"}
_, err = tests.ExecuteCommand(cmd, args...)
re.NoError(err)

args = []string{"-u", pdAddr, "store", "limit"}
output, err := tests.ExecuteCommand(cmd, args...)
re.NoError(err)
re.Contains(string(output), "not support get limit")

args = []string{"-u", pdAddr, "store", "limit", "1", "10"}
output, err = tests.ExecuteCommand(cmd, args...)
re.NoError(err)
re.Contains(string(output), "not support set limit")
}

func TestStore(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
Expand Down
11 changes: 11 additions & 0 deletions tools/pd-simulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,14 @@ Run a specific case with an external PD:
```shell
./pd-simulator -pd="http://127.0.0.1:2379" -case="casename"
```

Run with tiup playgroudn :
```shell
tiup playground nightly --host 127.0.0.1 --kv.binpath ./pd-simulator --kv=1 --db=0 --kv.config=./tikv.conf
```
tikv conf
```
case-name="redundant-balance-region"
sim-tick-interval="1s"
store-io-per-second=100
```
1 change: 1 addition & 0 deletions tools/pd-simulator/simulator/cases/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var IDAllocator idAllocator
var CaseMap = map[string]func(*config.SimConfig) *Case{
"balance-leader": newBalanceLeader,
"redundant-balance-region": newRedundantBalanceRegion,
"scale-in-out": newScaleInOut,
"region-split": newRegionSplit,
"region-merge": newRegionMerge,
"hot-read": newHotRead,
Expand Down
83 changes: 83 additions & 0 deletions tools/pd-simulator/simulator/cases/scale_tikv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2024 TiKV Project Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cases

import (
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/tikv/pd/pkg/core"
sc "github.com/tikv/pd/tools/pd-simulator/simulator/config"
"github.com/tikv/pd/tools/pd-simulator/simulator/info"
"github.com/tikv/pd/tools/pd-simulator/simulator/simutil"
)

func newScaleInOut(config *sc.SimConfig) *Case {
var simCase Case

totalStore := config.TotalStore
totalRegion := config.TotalRegion
replica := int(config.ServerConfig.Replication.MaxReplicas)
if totalStore == 0 || totalRegion == 0 {
totalStore, totalRegion = 6, 4000
}

for i := 0; i < totalStore; i++ {
s := &Store{
ID: IDAllocator.nextID(),
Status: metapb.StoreState_Up,
}
if i%2 == 1 {
s.HasExtraUsedSpace = true
}
simCase.Stores = append(simCase.Stores, s)
}

for i := 0; i < totalRegion; i++ {
peers := make([]*metapb.Peer, 0, replica)
for j := 0; j < replica; j++ {
peers = append(peers, &metapb.Peer{
Id: simutil.IDAllocator.NextID(),
StoreId: uint64((i+j)%totalStore + 1),
})
}
simCase.Regions = append(simCase.Regions, Region{
ID: IDAllocator.nextID(),
Peers: peers,
Leader: peers[0],
})
}

scaleInTick := int64(totalRegion * 3 / totalStore)
addEvent := &AddNodesDescriptor{}
addEvent.Step = func(tick int64) uint64 {
if tick == scaleInTick {
return uint64(totalStore + 1)
}
return 0
}

removeEvent := &DeleteNodesDescriptor{}
removeEvent.Step = func(tick int64) uint64 {
if tick == scaleInTick*2 {
return uint64(totalStore + 1)
}
return 0
}
simCase.Events = []EventDescriptor{addEvent, removeEvent}

simCase.Checker = func(_ *core.RegionsInfo, _ []info.StoreStats) bool {
return false
}
return &simCase
}