Skip to content

Commit

Permalink
change the default behavior without specified type
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Jun 18, 2020
1 parent 8797c82 commit ce5764e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
1 change: 0 additions & 1 deletion pkg/mock/mockoption/mockoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func NewScheduleOptions() *ScheduleOptions {
mso.TolerantSizeRatio = defaultTolerantSizeRatio
mso.LowSpaceRatio = defaultLowSpaceRatio
mso.HighSpaceRatio = defaultHighSpaceRatio
mso.StoreLimitMode = defaultStoreLimitMode
mso.EnableRemoveDownReplica = true
mso.EnableReplaceOfflineReplica = true
mso.EnableMakeUpReplica = true
Expand Down
31 changes: 18 additions & 13 deletions server/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,17 @@ func (h *storeHandler) SetLimit(w http.ResponseWriter, r *http.Request) {
return
}

typeValue, err := getStoreLimitType(input)
typeValues, err := getStoreLimitType(input)
if err != nil {
h.rd.JSON(w, http.StatusBadRequest, err.Error())
return
}

if err := h.SetStoreLimit(storeID, ratePerMin, typeValue); err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
for _, typ := range typeValues {
if err := h.SetStoreLimit(storeID, ratePerMin, typ); err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
}

h.rd.JSON(w, http.StatusOK, nil)
Expand Down Expand Up @@ -436,15 +438,17 @@ func (h *storesHandler) SetAllLimit(w http.ResponseWriter, r *http.Request) {
return
}

typeValue, err := getStoreLimitType(input)
typeValues, err := getStoreLimitType(input)
if err != nil {
h.rd.JSON(w, http.StatusBadRequest, err.Error())
return
}

if err := h.SetAllStoresLimit(ratePerMin, typeValue); err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
for _, typ := range typeValues {
if err := h.SetAllStoresLimit(ratePerMin, typ); err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
}

h.rd.JSON(w, http.StatusOK, nil)
Expand Down Expand Up @@ -584,19 +588,20 @@ func (filter *storeStateFilter) filter(stores []*metapb.Store) []*metapb.Store {
return ret
}

func getStoreLimitType(input map[string]interface{}) (storelimit.Type, error) {
func getStoreLimitType(input map[string]interface{}) ([]storelimit.Type, error) {
typeNameIface, ok := input["type"]
typeValue := storelimit.AddPeer
var err error
if ok {
typeName, ok := typeNameIface.(string)
if !ok {
err = errors.New("bad format type")
} else {
return parseStoreLimitType(typeName)
return nil, err
}
typ, err := parseStoreLimitType(typeName)
return []storelimit.Type{typ}, err
}
return typeValue, err

return []storelimit.Type{storelimit.AddPeer, storelimit.RemovePeer}, err
}

func parseStoreLimitType(typeName string) (storelimit.Type, error) {
Expand Down
4 changes: 0 additions & 4 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,6 @@ const (
defaultHotRegionCacheHitsThreshold = 3
defaultSchedulerMaxWaitingOperator = 5
defaultLeaderSchedulePolicy = "count"
defaultStoreLimitMode = "manual"
)

func (c *ScheduleConfig) adjust(meta *configMetaData) error {
Expand Down Expand Up @@ -761,9 +760,6 @@ func (c *ScheduleConfig) adjust(meta *configMetaData) error {
if !meta.IsDefined("leader-schedule-policy") {
adjustString(&c.LeaderSchedulePolicy, defaultLeaderSchedulePolicy)
}
if !meta.IsDefined("store-limit-mode") {
adjustString(&c.StoreLimitMode, defaultStoreLimitMode)
}
adjustFloat64(&c.LowSpaceRatio, defaultLowSpaceRatio)
adjustFloat64(&c.HighSpaceRatio, defaultHighSpaceRatio)
adjustSchedulers(&c.Schedulers, defaultSchedulers)
Expand Down
10 changes: 9 additions & 1 deletion tests/pdctl/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func (s *storeTestSuite) TestStore(c *C) {
c.Assert(err, IsNil)
limit := leaderServer.GetRaftCluster().GetStoreLimitByType(1, storelimit.AddPeer)
c.Assert(limit, Equals, float64(10))
limit = leaderServer.GetRaftCluster().GetStoreLimitByType(1, storelimit.RemovePeer)
c.Assert(limit, Equals, float64(10))

// store limit <store_id> <rate> <type>
args = []string{"-u", pdAddr, "store", "limit", "1", "5", "remove-peer"}
Expand All @@ -171,11 +173,17 @@ func (s *storeTestSuite) TestStore(c *C) {
_, _, err = pdctl.ExecuteCommandC(cmd, args...)
c.Assert(err, IsNil)
limit1 := leaderServer.GetRaftCluster().GetStoreLimitByType(1, storelimit.AddPeer)
limit2 := leaderServer.GetRaftCluster().GetStoreLimitByType(2, storelimit.AddPeer)
limit3 := leaderServer.GetRaftCluster().GetStoreLimitByType(3, storelimit.AddPeer)
c.Assert(limit1, Equals, float64(20))
c.Assert(limit2, Equals, float64(20))
c.Assert(limit3, Equals, float64(20))
limit2 := leaderServer.GetRaftCluster().GetStoreLimitByType(2, storelimit.AddPeer)
limit1 = leaderServer.GetRaftCluster().GetStoreLimitByType(1, storelimit.RemovePeer)
limit2 = leaderServer.GetRaftCluster().GetStoreLimitByType(2, storelimit.RemovePeer)
limit3 = leaderServer.GetRaftCluster().GetStoreLimitByType(3, storelimit.RemovePeer)
c.Assert(limit1, Equals, float64(20))
c.Assert(limit2, Equals, float64(20))
c.Assert(limit3, Equals, float64(20))

// store limit all <rate> <type>
args = []string{"-u", pdAddr, "store", "limit", "all", "25", "remove-peer"}
Expand Down
16 changes: 8 additions & 8 deletions tools/pd-ctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,16 @@ Usage:
>> store label 1 zone cn // Set the value of the label with the "zone" key to "cn" for the store with the store id of 1
>> store weight 1 5 10 // Set the leader weight to 5 and region weight to 10 for the store with the store id of 1
>> store remove-tombstone // Remove stores that are in tombstone state
>> store limit // Show limits of adding peer operation for all stores
>> store limit // Show limits of adding peer and removing peer operation for all stores
>> store limit add-peer // Show limits of adding peer operation for all stores
>> store limit remove-peer // Show limits of removing peer operation for all stores
>> store limit all 5 // Limit 5 adding region operations per minute for all stores
>> store limit 1 5 // Limit 5 adding region operations per minute for store 1
>> store limit all 5 add-peer // Limit 5 adding region operations per minute for all stores
>> store limit 1 5 add-peer // Limit 5 adding region operations per minute for store 1
>> store limit 1 5 remove-peer // Limit 5 removing region operations per minute for store 1
>> store limit all 5 remove-peer // Limit 5 removing region operations per minute for all stores
>> store limit-scene // Show all limit scene
>> store limit all 5 // Limit 5 adding peer operations and 5 remove peer operations per minute for all stores
>> store limit 1 5 // Limit 5 adding peer operations and 5 remove peer operations per minute for store 1
>> store limit all 5 add-peer // Limit 5 adding peer operations per minute for all stores
>> store limit 1 5 add-peer // Limit 5 adding peer operations per minute for store 1
>> store limit 1 5 remove-peer // Limit 5 removing peer operations per minute for store 1
>> store limit all 5 remove-peer // Limit 5 removing peer operations per minute for all stores
>> store limit-scene // Show all limit scene
{
"Idle": 100,
"Low": 50,
Expand Down

0 comments on commit ce5764e

Please sign in to comment.