Skip to content

Commit

Permalink
Merge commit 'refs/pull/7792/head' of github.com:tikv/pd into store-l…
Browse files Browse the repository at this point in the history
…imit-v2

Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Jun 12, 2024
2 parents c015f14 + e65ea40 commit 7f61697
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 1 deletion.
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 @@ func (h *storeHandler) SetStoreWeight(w http.ResponseWriter, r *http.Request) {
// @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 @@ func (h *storesHandler) RemoveTombStone(w http.ResponseWriter, r *http.Request)
// @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
}
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 @@ func (h *storesHandler) SetAllStoresLimit(w http.ResponseWriter, r *http.Request
// @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
}
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
```
79 changes: 79 additions & 0 deletions tools/pd-simulator/simulator/cases/scale_tikv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2018 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"
"github.com/tikv/pd/tools/pd-simulator/simulator/info"
"github.com/tikv/pd/tools/pd-simulator/simulator/simutil"
)

func newScaleInOut() *Case {
var simCase Case

storeNum := simutil.CaseConfigure.StoreNum
regionNum := simutil.CaseConfigure.RegionNum
if storeNum == 0 || regionNum == 0 {
storeNum, regionNum = 6, 4000
}

for i := 0; i < storeNum; 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 < regionNum; i++ {
peers := []*metapb.Peer{
{Id: IDAllocator.nextID(), StoreId: uint64(i%storeNum + 1)},
{Id: IDAllocator.nextID(), StoreId: uint64((i+1)%storeNum + 1)},
{Id: IDAllocator.nextID(), StoreId: uint64((i+2)%storeNum + 1)},
}
simCase.Regions = append(simCase.Regions, Region{
ID: IDAllocator.nextID(),
Peers: peers,
Leader: peers[0],
})
}

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

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

simCase.Checker = func(regions *core.RegionsInfo, stats []info.StoreStats) bool {
return false
}
return &simCase
}
1 change: 1 addition & 0 deletions tools/pd-simulator/simulator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func NewNode(s *cases.Store, pdAddr string, config *sc.SimConfig) (*Node, error)
StoreStats: pdpb.StoreStats{
StoreId: s.ID,
Capacity: uint64(config.RaftStore.Capacity),
Available: uint64(config.RaftStore.Capacity),
StartTime: uint32(time.Now().Unix()),
Available: uint64(config.RaftStore.Capacity),
},
Expand Down

0 comments on commit 7f61697

Please sign in to comment.