From f9953398f787b87d4398fcb8c20cde5d447d6670 Mon Sep 17 00:00:00 2001 From: disksing Date: Thu, 5 Jul 2018 15:45:19 +0800 Subject: [PATCH 1/4] schedule: add options to disable replica checker features --- server/cluster_info.go | 20 +++++++++ server/config.go | 54 ++++++++++++++++-------- server/option.go | 20 +++++++++ server/schedule/mockcluster.go | 66 ++++++++++++++++++++++-------- server/schedule/opts.go | 7 ++++ server/schedule/replica_checker.go | 16 +++++++- 6 files changed, 147 insertions(+), 36 deletions(-) diff --git a/server/cluster_info.go b/server/cluster_info.go index 2820bc06e43..1050fad7ecd 100644 --- a/server/cluster_info.go +++ b/server/cluster_info.go @@ -621,6 +621,26 @@ func (c *clusterInfo) IsRaftLearnerEnabled() bool { return c.opt.IsRaftLearnerEnabled() } +func (c *clusterInfo) IsRemoveDownReplicaEnabled() bool { + return c.opt.IsRemoveDownReplicaEnabled() +} + +func (c *clusterInfo) IsMakeUpOfflineReplicaEnabled() bool { + return c.opt.IsMakeUpOfflineReplicaEnabled() +} + +func (c *clusterInfo) IsMakeUpReplicaEnabled() bool { + return c.opt.IsMakeUpReplicaEnabled() +} + +func (c *clusterInfo) IsRemoveExtraReplicaEnabled() bool { + return c.opt.IsRemoveExtraReplicaEnabled() +} + +func (c *clusterInfo) IsLocationReplacementEnabled() bool { + return c.opt.IsLocationReplacementEnabled() +} + func (c *clusterInfo) CheckLabelProperty(typ string, labels []*metapb.StoreLabel) bool { return c.opt.CheckLabelProperty(typ, labels) } diff --git a/server/config.go b/server/config.go index c5b00d4db95..99e68e94a46 100644 --- a/server/config.go +++ b/server/config.go @@ -410,6 +410,23 @@ type ScheduleConfig struct { HighSpaceRatio float64 `toml:"high-space-ratio,omitempty" json:"high-space-ratio"` // DisableLearner is the option to disable using AddLearnerNode instead of AddNode DisableLearner bool `toml:"disable-raft-learner" json:"disable-raft-learner,string"` + + // DisableRemoveDownReplica is the option to prevent replica checker from + // removing down replicas. + DisableRemoveDownReplica bool `toml:"disable-remove-down-replica" json:"disable-remove-down-replica"` + // DisableMakeUpOfflineReplica is the option to prevent replica checker from + // making up offline replicas. + DisableMakeUpOfflineReplica bool `toml:"disable-make-up-offline-replica" json:"disable-make-up-offline-replica"` + // DisableMakeUpReplica is the option to prevent replica checker from making up + // replicas when replica count is less than expected. + DisableMakeUpReplica bool `toml:"disable-make-up-replica" json:"disable-make-up-replica"` + // DisableRemoveExtraReplica is the option to prevent replica checker from + // removing extra replicas. + DisableRemoveExtraReplica bool `toml:"disable-remove-extra-replica" json:"disable-remove-extra-replica"` + // DisableLocationReplacement is the option to prevent replica checker from + // moving replica to a better location. + DisableLocationReplacement bool `toml:"disable-location-replacement" json:"disable-location-replacement"` + // Schedulers support for loding customized schedulers Schedulers SchedulerConfigs `toml:"schedulers,omitempty" json:"schedulers-v2"` // json v2 is for the sake of compatible upgrade } @@ -418,22 +435,27 @@ func (c *ScheduleConfig) clone() *ScheduleConfig { schedulers := make(SchedulerConfigs, len(c.Schedulers)) copy(schedulers, c.Schedulers) return &ScheduleConfig{ - MaxSnapshotCount: c.MaxSnapshotCount, - MaxPendingPeerCount: c.MaxPendingPeerCount, - MaxMergeRegionSize: c.MaxMergeRegionSize, - MaxMergeRegionRows: c.MaxMergeRegionRows, - SplitMergeInterval: c.SplitMergeInterval, - PatrolRegionInterval: c.PatrolRegionInterval, - MaxStoreDownTime: c.MaxStoreDownTime, - LeaderScheduleLimit: c.LeaderScheduleLimit, - RegionScheduleLimit: c.RegionScheduleLimit, - ReplicaScheduleLimit: c.ReplicaScheduleLimit, - MergeScheduleLimit: c.MergeScheduleLimit, - TolerantSizeRatio: c.TolerantSizeRatio, - LowSpaceRatio: c.LowSpaceRatio, - HighSpaceRatio: c.HighSpaceRatio, - DisableLearner: c.DisableLearner, - Schedulers: schedulers, + MaxSnapshotCount: c.MaxSnapshotCount, + MaxPendingPeerCount: c.MaxPendingPeerCount, + MaxMergeRegionSize: c.MaxMergeRegionSize, + MaxMergeRegionRows: c.MaxMergeRegionRows, + SplitMergeInterval: c.SplitMergeInterval, + PatrolRegionInterval: c.PatrolRegionInterval, + MaxStoreDownTime: c.MaxStoreDownTime, + LeaderScheduleLimit: c.LeaderScheduleLimit, + RegionScheduleLimit: c.RegionScheduleLimit, + ReplicaScheduleLimit: c.ReplicaScheduleLimit, + MergeScheduleLimit: c.MergeScheduleLimit, + TolerantSizeRatio: c.TolerantSizeRatio, + LowSpaceRatio: c.LowSpaceRatio, + HighSpaceRatio: c.HighSpaceRatio, + DisableLearner: c.DisableLearner, + DisableRemoveDownReplica: c.DisableRemoveDownReplica, + DisableMakeUpOfflineReplica: c.DisableMakeUpOfflineReplica, + DisableMakeUpReplica: c.DisableMakeUpReplica, + DisableRemoveExtraReplica: c.DisableRemoveExtraReplica, + DisableLocationReplacement: c.DisableLocationReplacement, + Schedulers: schedulers, } } diff --git a/server/option.go b/server/option.go index 645a31df647..38ee9ee107f 100644 --- a/server/option.go +++ b/server/option.go @@ -144,6 +144,26 @@ func (o *scheduleOption) IsRaftLearnerEnabled() bool { return !o.load().DisableLearner } +func (o *scheduleOption) IsRemoveDownReplicaEnabled() bool { + return !o.load().DisableRemoveDownReplica +} + +func (o *scheduleOption) IsMakeUpOfflineReplicaEnabled() bool { + return !o.load().DisableMakeUpOfflineReplica +} + +func (o *scheduleOption) IsMakeUpReplicaEnabled() bool { + return !o.load().DisableMakeUpReplica +} + +func (o *scheduleOption) IsRemoveExtraReplicaEnabled() bool { + return !o.load().DisableRemoveExtraReplica +} + +func (o *scheduleOption) IsLocationReplacementEnabled() bool { + return !o.load().DisableLocationReplacement +} + func (o *scheduleOption) GetSchedulers() SchedulerConfigs { return o.load().Schedulers } diff --git a/server/schedule/mockcluster.go b/server/schedule/mockcluster.go index 2c4a07ac69a..39aaa9edbed 100644 --- a/server/schedule/mockcluster.go +++ b/server/schedule/mockcluster.go @@ -432,24 +432,29 @@ const ( // MockSchedulerOptions is a mock of SchedulerOptions // which implements Options interface type MockSchedulerOptions struct { - RegionScheduleLimit uint64 - LeaderScheduleLimit uint64 - ReplicaScheduleLimit uint64 - MergeScheduleLimit uint64 - MaxSnapshotCount uint64 - MaxPendingPeerCount uint64 - MaxMergeRegionSize uint64 - MaxMergeRegionRows uint64 - SplitMergeInterval time.Duration - MaxStoreDownTime time.Duration - MaxReplicas int - LocationLabels []string - HotRegionLowThreshold int - TolerantSizeRatio float64 - LowSpaceRatio float64 - HighSpaceRatio float64 - DisableLearner bool - LabelProperties map[string][]*metapb.StoreLabel + RegionScheduleLimit uint64 + LeaderScheduleLimit uint64 + ReplicaScheduleLimit uint64 + MergeScheduleLimit uint64 + MaxSnapshotCount uint64 + MaxPendingPeerCount uint64 + MaxMergeRegionSize uint64 + MaxMergeRegionRows uint64 + SplitMergeInterval time.Duration + MaxStoreDownTime time.Duration + MaxReplicas int + LocationLabels []string + HotRegionLowThreshold int + TolerantSizeRatio float64 + LowSpaceRatio float64 + HighSpaceRatio float64 + DisableLearner bool + DisableRemoveDownReplica bool + DisableMakeUpOfflineReplica bool + DisableMakeUpReplica bool + DisableRemoveExtraReplica bool + DisableLocationReplacement bool + LabelProperties map[string][]*metapb.StoreLabel } // NewMockSchedulerOptions creates a mock schedule option. @@ -562,3 +567,28 @@ func (mso *MockSchedulerOptions) SetMaxReplicas(replicas int) { func (mso *MockSchedulerOptions) IsRaftLearnerEnabled() bool { return !mso.DisableLearner } + +// IsRemoveDownReplicaEnabled mock method. +func (mso *MockSchedulerOptions) IsRemoveDownReplicaEnabled() bool { + return !mso.DisableRemoveDownReplica +} + +// IsMakeUpOfflineReplicaEnabled mock method. +func (mso *MockSchedulerOptions) IsMakeUpOfflineReplicaEnabled() bool { + return !mso.DisableMakeUpOfflineReplica +} + +// IsMakeUpReplicaEnabled mock method. +func (mso *MockSchedulerOptions) IsMakeUpReplicaEnabled() bool { + return !mso.DisableMakeUpReplica +} + +// IsRemoveExtraReplicaEnabled mock method. +func (mso *MockSchedulerOptions) IsRemoveExtraReplicaEnabled() bool { + return !mso.DisableRemoveExtraReplica +} + +// IsLocationReplacementEnabled mock method. +func (mso *MockSchedulerOptions) IsLocationReplacementEnabled() bool { + return !mso.DisableLocationReplacement +} diff --git a/server/schedule/opts.go b/server/schedule/opts.go index 73849de5428..4fe1a561ef4 100644 --- a/server/schedule/opts.go +++ b/server/schedule/opts.go @@ -46,6 +46,13 @@ type Options interface { GetHighSpaceRatio() float64 IsRaftLearnerEnabled() bool + + IsRemoveDownReplicaEnabled() bool + IsMakeUpOfflineReplicaEnabled() bool + IsMakeUpReplicaEnabled() bool + IsRemoveExtraReplicaEnabled() bool + IsLocationReplacementEnabled() bool + CheckLabelProperty(typ string, labels []*metapb.StoreLabel) bool } diff --git a/server/schedule/replica_checker.go b/server/schedule/replica_checker.go index 0ce3ccfb229..f1c0c3c0a20 100644 --- a/server/schedule/replica_checker.go +++ b/server/schedule/replica_checker.go @@ -55,7 +55,7 @@ func (r *ReplicaChecker) Check(region *core.RegionInfo) *Operator { return op } - if len(region.GetPeers()) < r.cluster.GetMaxReplicas() { + if len(region.GetPeers()) < r.cluster.GetMaxReplicas() && r.cluster.IsMakeUpReplicaEnabled() { log.Debugf("[region %d] has %d peers fewer than max replicas", region.GetId(), len(region.GetPeers())) newPeer, _ := r.selectBestPeerToAddReplica(region, NewStorageThresholdFilter()) if newPeer == nil { @@ -79,7 +79,7 @@ func (r *ReplicaChecker) Check(region *core.RegionInfo) *Operator { // when add learner peer, the number of peer will exceed max replicas for a wille, // just comparing the the number of voters to avoid too many cancel add operator log. - if len(region.GetVoters()) > r.cluster.GetMaxReplicas() { + if len(region.GetVoters()) > r.cluster.GetMaxReplicas() && r.cluster.IsRemoveExtraReplicaEnabled() { log.Debugf("[region %d] has %d peers more than max replicas", region.GetId(), len(region.GetPeers())) oldPeer, _ := r.selectWorstPeer(region) if oldPeer == nil { @@ -150,6 +150,10 @@ func (r *ReplicaChecker) selectWorstPeer(region *core.RegionInfo) (*metapb.Peer, } func (r *ReplicaChecker) checkDownPeer(region *core.RegionInfo) *Operator { + if !r.cluster.IsRemoveDownReplicaEnabled() { + return nil + } + for _, stats := range region.DownPeers { peer := stats.GetPeer() if peer == nil { @@ -172,6 +176,10 @@ func (r *ReplicaChecker) checkDownPeer(region *core.RegionInfo) *Operator { } func (r *ReplicaChecker) checkOfflinePeer(region *core.RegionInfo) *Operator { + if !r.cluster.IsMakeUpOfflineReplicaEnabled() { + return nil + } + // just skip learner if len(region.Learners) != 0 { return nil @@ -216,6 +224,10 @@ func (r *ReplicaChecker) checkOfflinePeer(region *core.RegionInfo) *Operator { } func (r *ReplicaChecker) checkBestReplacement(region *core.RegionInfo) *Operator { + if !r.cluster.IsLocationReplacementEnabled() { + return nil + } + oldPeer, oldScore := r.selectWorstPeer(region) if oldPeer == nil { checkerCounter.WithLabelValues("replica_checker", "all_right").Inc() From 3f502eebe847ffa64986caddc6abdd3774ca8390 Mon Sep 17 00:00:00 2001 From: disksing Date: Thu, 5 Jul 2018 16:18:28 +0800 Subject: [PATCH 2/4] add tests --- server/schedulers/balance_test.go | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/server/schedulers/balance_test.go b/server/schedulers/balance_test.go index fbd99db5eea..ff028989095 100644 --- a/server/schedulers/balance_test.go +++ b/server/schedulers/balance_test.go @@ -496,6 +496,11 @@ func (s *testReplicaCheckerSuite) TestBasic(c *C) { region := tc.GetRegion(1) testutil.CheckAddPeer(c, rc.Check(region), schedule.OpReplica, 4) + // Disable make up replica feature. + opt.DisableMakeUpReplica = true + c.Assert(rc.Check(region), IsNil) + opt.DisableMakeUpReplica = false + // Test healthFilter. // If store 4 is down, we add to store 3. tc.SetStoreDown(4) @@ -520,6 +525,12 @@ func (s *testReplicaCheckerSuite) TestBasic(c *C) { peer3, _ := tc.AllocPeer(3) region.AddPeer(peer3) testutil.CheckRemovePeer(c, rc.Check(region), 1) + + // Disable remove extra replica feature. + opt.DisableRemoveExtraReplica = true + c.Assert(rc.Check(region), IsNil) + opt.DisableRemoveExtraReplica = false + region.RemoveStorePeer(1) // Peer in store 2 is down, remove it. @@ -663,6 +674,10 @@ func (s *testReplicaCheckerSuite) TestDistinctScore(c *C) { // Replace peer in store 1 with store 6 because it has a different rack. testutil.CheckTransferPeer(c, rc.Check(region), schedule.OpReplica, 1, 6) + // Disable locationReplacement feature. + opt.DisableLocationReplacement = true + c.Assert(rc.Check(region), IsNil) + opt.DisableLocationReplacement = false peer6, _ := tc.AllocPeer(6) region.AddPeer(peer6) testutil.CheckRemovePeer(c, rc.Check(region), 1) @@ -751,6 +766,35 @@ func (s *testReplicaCheckerSuite) TestStorageThreshold(c *C) { testutil.CheckAddPeer(c, rc.Check(region), schedule.OpReplica, 2) } +func (s *testReplicaCheckerSuite) TestOpts(c *C) { + opt := schedule.NewMockSchedulerOptions() + tc := schedule.NewMockCluster(opt) + rc := schedule.NewReplicaChecker(tc, namespace.DefaultClassifier) + + tc.AddRegionStore(1, 100) + tc.AddRegionStore(2, 100) + tc.AddRegionStore(3, 100) + tc.AddRegionStore(4, 100) + tc.AddLeaderRegion(1, 1, 2, 3) + + region := tc.GetRegion(1) + // Test remove down replica and make up offline replica. + tc.SetStoreDown(1) + region.DownPeers = []*pdpb.PeerStats{ + { + Peer: region.GetStorePeer(1), + DownSeconds: 24 * 60 * 60, + }, + } + tc.SetStoreOffline(2) + // RemoveDownReplica has higher priority than MakeUpOfflineReplica. + testutil.CheckRemovePeer(c, rc.Check(region), 1) + opt.DisableRemoveDownReplica = true + testutil.CheckTransferPeer(c, rc.Check(region), schedule.OpReplica, 2, 4) + opt.DisableMakeUpOfflineReplica = true + c.Assert(rc.Check(region), IsNil) +} + var _ = Suite(&testMergeCheckerSuite{}) type testMergeCheckerSuite struct { From 9cb35f44aaf930e2a1b2061af080a1f9f8a40f5a Mon Sep 17 00:00:00 2001 From: disksing Date: Thu, 5 Jul 2018 16:34:13 +0800 Subject: [PATCH 3/4] fix json marshal issue --- server/config.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/config.go b/server/config.go index 99e68e94a46..aadf78f4a73 100644 --- a/server/config.go +++ b/server/config.go @@ -413,19 +413,19 @@ type ScheduleConfig struct { // DisableRemoveDownReplica is the option to prevent replica checker from // removing down replicas. - DisableRemoveDownReplica bool `toml:"disable-remove-down-replica" json:"disable-remove-down-replica"` + DisableRemoveDownReplica bool `toml:"disable-remove-down-replica" json:"disable-remove-down-replica,string"` // DisableMakeUpOfflineReplica is the option to prevent replica checker from // making up offline replicas. - DisableMakeUpOfflineReplica bool `toml:"disable-make-up-offline-replica" json:"disable-make-up-offline-replica"` + DisableMakeUpOfflineReplica bool `toml:"disable-make-up-offline-replica" json:"disable-make-up-offline-replica,string"` // DisableMakeUpReplica is the option to prevent replica checker from making up // replicas when replica count is less than expected. - DisableMakeUpReplica bool `toml:"disable-make-up-replica" json:"disable-make-up-replica"` + DisableMakeUpReplica bool `toml:"disable-make-up-replica" json:"disable-make-up-replica,string"` // DisableRemoveExtraReplica is the option to prevent replica checker from // removing extra replicas. - DisableRemoveExtraReplica bool `toml:"disable-remove-extra-replica" json:"disable-remove-extra-replica"` + DisableRemoveExtraReplica bool `toml:"disable-remove-extra-replica" json:"disable-remove-extra-replica,string"` // DisableLocationReplacement is the option to prevent replica checker from // moving replica to a better location. - DisableLocationReplacement bool `toml:"disable-location-replacement" json:"disable-location-replacement"` + DisableLocationReplacement bool `toml:"disable-location-replacement" json:"disable-location-replacement,string"` // Schedulers support for loding customized schedulers Schedulers SchedulerConfigs `toml:"schedulers,omitempty" json:"schedulers-v2"` // json v2 is for the sake of compatible upgrade From 102cae98576f50f72eac6a95ff683093c55ed613 Mon Sep 17 00:00:00 2001 From: disksing Date: Tue, 10 Jul 2018 10:23:16 +0800 Subject: [PATCH 4/4] address comment --- server/cluster_info.go | 4 +-- server/config.go | 48 +++++++++++++-------------- server/option.go | 4 +-- server/schedule/mockcluster.go | 52 +++++++++++++++--------------- server/schedule/opts.go | 2 +- server/schedule/replica_checker.go | 4 +-- server/schedulers/balance_test.go | 6 ++-- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/server/cluster_info.go b/server/cluster_info.go index 1050fad7ecd..6b2c3f5b8ae 100644 --- a/server/cluster_info.go +++ b/server/cluster_info.go @@ -625,8 +625,8 @@ func (c *clusterInfo) IsRemoveDownReplicaEnabled() bool { return c.opt.IsRemoveDownReplicaEnabled() } -func (c *clusterInfo) IsMakeUpOfflineReplicaEnabled() bool { - return c.opt.IsMakeUpOfflineReplicaEnabled() +func (c *clusterInfo) IsReplaceOfflineReplicaEnabled() bool { + return c.opt.IsReplaceOfflineReplicaEnabled() } func (c *clusterInfo) IsMakeUpReplicaEnabled() bool { diff --git a/server/config.go b/server/config.go index aadf78f4a73..791da94314c 100644 --- a/server/config.go +++ b/server/config.go @@ -414,9 +414,9 @@ type ScheduleConfig struct { // DisableRemoveDownReplica is the option to prevent replica checker from // removing down replicas. DisableRemoveDownReplica bool `toml:"disable-remove-down-replica" json:"disable-remove-down-replica,string"` - // DisableMakeUpOfflineReplica is the option to prevent replica checker from - // making up offline replicas. - DisableMakeUpOfflineReplica bool `toml:"disable-make-up-offline-replica" json:"disable-make-up-offline-replica,string"` + // DisableReplaceOfflineReplica is the option to prevent replica checker from + // repalcing offline replicas. + DisableReplaceOfflineReplica bool `toml:"disable-replace-offline-replica" json:"disable-replace-offline-replica,string"` // DisableMakeUpReplica is the option to prevent replica checker from making up // replicas when replica count is less than expected. DisableMakeUpReplica bool `toml:"disable-make-up-replica" json:"disable-make-up-replica,string"` @@ -435,27 +435,27 @@ func (c *ScheduleConfig) clone() *ScheduleConfig { schedulers := make(SchedulerConfigs, len(c.Schedulers)) copy(schedulers, c.Schedulers) return &ScheduleConfig{ - MaxSnapshotCount: c.MaxSnapshotCount, - MaxPendingPeerCount: c.MaxPendingPeerCount, - MaxMergeRegionSize: c.MaxMergeRegionSize, - MaxMergeRegionRows: c.MaxMergeRegionRows, - SplitMergeInterval: c.SplitMergeInterval, - PatrolRegionInterval: c.PatrolRegionInterval, - MaxStoreDownTime: c.MaxStoreDownTime, - LeaderScheduleLimit: c.LeaderScheduleLimit, - RegionScheduleLimit: c.RegionScheduleLimit, - ReplicaScheduleLimit: c.ReplicaScheduleLimit, - MergeScheduleLimit: c.MergeScheduleLimit, - TolerantSizeRatio: c.TolerantSizeRatio, - LowSpaceRatio: c.LowSpaceRatio, - HighSpaceRatio: c.HighSpaceRatio, - DisableLearner: c.DisableLearner, - DisableRemoveDownReplica: c.DisableRemoveDownReplica, - DisableMakeUpOfflineReplica: c.DisableMakeUpOfflineReplica, - DisableMakeUpReplica: c.DisableMakeUpReplica, - DisableRemoveExtraReplica: c.DisableRemoveExtraReplica, - DisableLocationReplacement: c.DisableLocationReplacement, - Schedulers: schedulers, + MaxSnapshotCount: c.MaxSnapshotCount, + MaxPendingPeerCount: c.MaxPendingPeerCount, + MaxMergeRegionSize: c.MaxMergeRegionSize, + MaxMergeRegionRows: c.MaxMergeRegionRows, + SplitMergeInterval: c.SplitMergeInterval, + PatrolRegionInterval: c.PatrolRegionInterval, + MaxStoreDownTime: c.MaxStoreDownTime, + LeaderScheduleLimit: c.LeaderScheduleLimit, + RegionScheduleLimit: c.RegionScheduleLimit, + ReplicaScheduleLimit: c.ReplicaScheduleLimit, + MergeScheduleLimit: c.MergeScheduleLimit, + TolerantSizeRatio: c.TolerantSizeRatio, + LowSpaceRatio: c.LowSpaceRatio, + HighSpaceRatio: c.HighSpaceRatio, + DisableLearner: c.DisableLearner, + DisableRemoveDownReplica: c.DisableRemoveDownReplica, + DisableReplaceOfflineReplica: c.DisableReplaceOfflineReplica, + DisableMakeUpReplica: c.DisableMakeUpReplica, + DisableRemoveExtraReplica: c.DisableRemoveExtraReplica, + DisableLocationReplacement: c.DisableLocationReplacement, + Schedulers: schedulers, } } diff --git a/server/option.go b/server/option.go index 38ee9ee107f..5298d9288b7 100644 --- a/server/option.go +++ b/server/option.go @@ -148,8 +148,8 @@ func (o *scheduleOption) IsRemoveDownReplicaEnabled() bool { return !o.load().DisableRemoveDownReplica } -func (o *scheduleOption) IsMakeUpOfflineReplicaEnabled() bool { - return !o.load().DisableMakeUpOfflineReplica +func (o *scheduleOption) IsReplaceOfflineReplicaEnabled() bool { + return !o.load().DisableReplaceOfflineReplica } func (o *scheduleOption) IsMakeUpReplicaEnabled() bool { diff --git a/server/schedule/mockcluster.go b/server/schedule/mockcluster.go index 39aaa9edbed..d0aa69f22f4 100644 --- a/server/schedule/mockcluster.go +++ b/server/schedule/mockcluster.go @@ -432,29 +432,29 @@ const ( // MockSchedulerOptions is a mock of SchedulerOptions // which implements Options interface type MockSchedulerOptions struct { - RegionScheduleLimit uint64 - LeaderScheduleLimit uint64 - ReplicaScheduleLimit uint64 - MergeScheduleLimit uint64 - MaxSnapshotCount uint64 - MaxPendingPeerCount uint64 - MaxMergeRegionSize uint64 - MaxMergeRegionRows uint64 - SplitMergeInterval time.Duration - MaxStoreDownTime time.Duration - MaxReplicas int - LocationLabels []string - HotRegionLowThreshold int - TolerantSizeRatio float64 - LowSpaceRatio float64 - HighSpaceRatio float64 - DisableLearner bool - DisableRemoveDownReplica bool - DisableMakeUpOfflineReplica bool - DisableMakeUpReplica bool - DisableRemoveExtraReplica bool - DisableLocationReplacement bool - LabelProperties map[string][]*metapb.StoreLabel + RegionScheduleLimit uint64 + LeaderScheduleLimit uint64 + ReplicaScheduleLimit uint64 + MergeScheduleLimit uint64 + MaxSnapshotCount uint64 + MaxPendingPeerCount uint64 + MaxMergeRegionSize uint64 + MaxMergeRegionRows uint64 + SplitMergeInterval time.Duration + MaxStoreDownTime time.Duration + MaxReplicas int + LocationLabels []string + HotRegionLowThreshold int + TolerantSizeRatio float64 + LowSpaceRatio float64 + HighSpaceRatio float64 + DisableLearner bool + DisableRemoveDownReplica bool + DisableReplaceOfflineReplica bool + DisableMakeUpReplica bool + DisableRemoveExtraReplica bool + DisableLocationReplacement bool + LabelProperties map[string][]*metapb.StoreLabel } // NewMockSchedulerOptions creates a mock schedule option. @@ -573,9 +573,9 @@ func (mso *MockSchedulerOptions) IsRemoveDownReplicaEnabled() bool { return !mso.DisableRemoveDownReplica } -// IsMakeUpOfflineReplicaEnabled mock method. -func (mso *MockSchedulerOptions) IsMakeUpOfflineReplicaEnabled() bool { - return !mso.DisableMakeUpOfflineReplica +// IsReplaceOfflineReplicaEnabled mock method. +func (mso *MockSchedulerOptions) IsReplaceOfflineReplicaEnabled() bool { + return !mso.DisableReplaceOfflineReplica } // IsMakeUpReplicaEnabled mock method. diff --git a/server/schedule/opts.go b/server/schedule/opts.go index 4fe1a561ef4..45b954cccc2 100644 --- a/server/schedule/opts.go +++ b/server/schedule/opts.go @@ -48,7 +48,7 @@ type Options interface { IsRaftLearnerEnabled() bool IsRemoveDownReplicaEnabled() bool - IsMakeUpOfflineReplicaEnabled() bool + IsReplaceOfflineReplicaEnabled() bool IsMakeUpReplicaEnabled() bool IsRemoveExtraReplicaEnabled() bool IsLocationReplacementEnabled() bool diff --git a/server/schedule/replica_checker.go b/server/schedule/replica_checker.go index f1c0c3c0a20..571d19941f2 100644 --- a/server/schedule/replica_checker.go +++ b/server/schedule/replica_checker.go @@ -176,7 +176,7 @@ func (r *ReplicaChecker) checkDownPeer(region *core.RegionInfo) *Operator { } func (r *ReplicaChecker) checkOfflinePeer(region *core.RegionInfo) *Operator { - if !r.cluster.IsMakeUpOfflineReplicaEnabled() { + if !r.cluster.IsReplaceOfflineReplicaEnabled() { return nil } @@ -217,7 +217,7 @@ func (r *ReplicaChecker) checkOfflinePeer(region *core.RegionInfo) *Operator { if err != nil { return nil } - return CreateMovePeerOperator("makeUpOfflineReplica", r.cluster, region, OpReplica, peer.GetStoreId(), newPeer.GetStoreId(), newPeer.GetId()) + return CreateMovePeerOperator("replaceOfflineReplica", r.cluster, region, OpReplica, peer.GetStoreId(), newPeer.GetStoreId(), newPeer.GetId()) } return nil diff --git a/server/schedulers/balance_test.go b/server/schedulers/balance_test.go index ff028989095..e1968c51b74 100644 --- a/server/schedulers/balance_test.go +++ b/server/schedulers/balance_test.go @@ -778,7 +778,7 @@ func (s *testReplicaCheckerSuite) TestOpts(c *C) { tc.AddLeaderRegion(1, 1, 2, 3) region := tc.GetRegion(1) - // Test remove down replica and make up offline replica. + // Test remove down replica and replace offline replica. tc.SetStoreDown(1) region.DownPeers = []*pdpb.PeerStats{ { @@ -787,11 +787,11 @@ func (s *testReplicaCheckerSuite) TestOpts(c *C) { }, } tc.SetStoreOffline(2) - // RemoveDownReplica has higher priority than MakeUpOfflineReplica. + // RemoveDownReplica has higher priority than replaceOfflineReplica. testutil.CheckRemovePeer(c, rc.Check(region), 1) opt.DisableRemoveDownReplica = true testutil.CheckTransferPeer(c, rc.Check(region), schedule.OpReplica, 2, 4) - opt.DisableMakeUpOfflineReplica = true + opt.DisableReplaceOfflineReplica = true c.Assert(rc.Check(region), IsNil) }