Skip to content

Commit

Permalink
schedule: fix panic when setting store-limit-mode to auto (#2544) (#2547
Browse files Browse the repository at this point in the history
)

Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
ti-srebot committed Jun 17, 2020
1 parent 85a49d5 commit 330768a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/mock/mockoption/mockoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
defaultLeaderSchedulePolicy = "count"
defaultEnablePlacementRules = false
defaultKeyType = "table"
defaultStoreLimitMode = "manual"
)

// ScheduleOptions is a mock of ScheduleOptions
Expand Down Expand Up @@ -71,6 +72,7 @@ type ScheduleOptions struct {
TolerantSizeRatio float64
LowSpaceRatio float64
HighSpaceRatio float64
StoreLimitMode string
EnableRemoveDownReplica bool
EnableReplaceOfflineReplica bool
EnableMakeUpReplica bool
Expand Down Expand Up @@ -110,6 +112,7 @@ 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 Expand Up @@ -279,3 +282,8 @@ func (mso *ScheduleOptions) GetLeaderSchedulePolicy() core.SchedulePolicy {
func (mso *ScheduleOptions) GetKeyType() core.KeyType {
return core.StringToKeyType(mso.KeyType)
}

// GetStoreLimitMode returns the limit mode of store.
func (mso *ScheduleOptions) GetStoreLimitMode() string {
return mso.StoreLimitMode
}
3 changes: 2 additions & 1 deletion server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,8 @@ func (oc *OperatorController) SetAllStoresLimitAuto(rate float64, limitType stor
for _, s := range stores {
sid := s.GetID()
if old, ok := oc.storesLimit[sid]; ok {
if old[limitType].Mode() == storelimit.Manual {
limit, ok1 := old[limitType]
if ok1 && limit.Mode() == storelimit.Manual {
continue
}
}
Expand Down
12 changes: 12 additions & 0 deletions server/schedule/operator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,15 @@ func (t *testOperatorControllerSuite) TestAddWaitingOperator(c *C) {
// no space left, new operator can not be added.
c.Assert(controller.AddWaitingOperator(addPeerOp(0)), Equals, 0)
}

func (t *testOperatorControllerSuite) TestAutoStoreLimitMode(c *C) {
opt := mockoption.NewScheduleOptions()
opt.StoreLimitMode = "auto"
tc := mockcluster.NewCluster(opt)
stream := mockhbstream.NewHeartbeatStreams(tc.ID, true /* no need to run */)
oc := NewOperatorController(t.ctx, tc, stream)

tc.AddLeaderStore(1, 10)
oc.SetStoreLimit(1, 10, storelimit.Auto, storelimit.RegionAdd)
oc.SetAllStoresLimitAuto(10, storelimit.RegionRemove)
}

0 comments on commit 330768a

Please sign in to comment.