Skip to content

Commit

Permalink
reject modify store limit configuration if store limit version isn't v1
Browse files Browse the repository at this point in the history
Signed-off-by: bufferflies <1045931706@qq.com>
  • Loading branch information
bufferflies committed Feb 1, 2024
1 parent 357ad3f commit d520787
Show file tree
Hide file tree
Showing 2 changed files with 47 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 @@ -429,6 +429,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 @@ -529,6 +533,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]interface{}
if err := apiutil.ReadJSONRespondError(h.rd, w, r.Body, &input); err != nil {
return
Expand Down Expand Up @@ -609,7 +618,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

0 comments on commit d520787

Please sign in to comment.