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

schedule: fix panic when setting store-limit-mode to auto (#2544) #2547

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}