diff --git a/pkg/core/store.go b/pkg/core/store.go index 6551ee7a4e1..cafb443bb7d 100644 --- a/pkg/core/store.go +++ b/pkg/core/store.go @@ -51,23 +51,23 @@ const ( type StoreInfo struct { meta *metapb.Store *storeStats - pauseLeaderTransfer bool // not allow to be used as source or target of transfer leader - slowStoreEvicted bool // this store has been evicted as a slow store, should not transfer leader to it - slowTrendEvicted bool // this store has been evicted as a slow store by trend, should not transfer leader to it - leaderCount int - regionCount int - learnerCount int - witnessCount int - leaderSize int64 - regionSize int64 - pendingPeerCount int - lastPersistTime time.Time - leaderWeight float64 - regionWeight float64 - limiter storelimit.StoreLimit - minResolvedTS uint64 - lastAwakenTime time.Time - lastSplitTime time.Time + pauseLeaderTransfer bool // not allow to be used as source or target of transfer leader + slowStoreEvicted bool // this store has been evicted as a slow store, should not transfer leader to it + slowTrendEvicted bool // this store has been evicted as a slow store by trend, should not transfer leader to it + leaderCount int + regionCount int + learnerCount int + witnessCount int + leaderSize int64 + regionSize int64 + pendingPeerCount int + lastPersistTime time.Time + leaderWeight float64 + regionWeight float64 + limiter storelimit.StoreLimit + minResolvedTS uint64 + lastAwakenTime time.Time + recentlySplitRegionsTime time.Time } // NewStoreInfo creates StoreInfo with meta data. @@ -541,9 +541,9 @@ func (s *StoreInfo) NeedAwakenStore() bool { return s.GetLastHeartbeatTS().Sub(s.lastAwakenTime) > awakenStoreInterval } -// IsSplitStore checks if there are some region are splitted in this store. -func (s *StoreInfo) IsSplitStore() bool { - return time.Since(s.lastSplitTime) < splitStoreWait +// HasRecentlySplitRegions checks if there are some region are splitted in this store. +func (s *StoreInfo) HasRecentlySplitRegions() bool { + return time.Since(s.recentlySplitRegionsTime) < splitStoreWait } var ( diff --git a/pkg/core/store_option.go b/pkg/core/store_option.go index 41f9d6d4414..c6038b5a824 100644 --- a/pkg/core/store_option.go +++ b/pkg/core/store_option.go @@ -282,9 +282,9 @@ func SetLastAwakenTime(lastAwaken time.Time) StoreCreateOption { } } -// SetLastSplitTime sets last split time for the store. -func SetLastSplitTime(lastSplit time.Time) StoreCreateOption { +// SetRecentlySplitRegionsTime sets last split time for the store. +func SetRecentlySplitRegionsTime(recentlySplitRegionsTime time.Time) StoreCreateOption { return func(store *StoreInfo) { - store.lastSplitTime = lastSplit + store.recentlySplitRegionsTime = recentlySplitRegionsTime } } diff --git a/pkg/schedule/filter/filters.go b/pkg/schedule/filter/filters.go index 886414137bd..3a2896839d5 100644 --- a/pkg/schedule/filter/filters.go +++ b/pkg/schedule/filter/filters.go @@ -332,8 +332,8 @@ type StoreStateFilter struct { // If it checks failed, the operator will be put back to the waiting queue util the limit is available. // But the scheduler should keep the same with the operator level. OperatorLevel constant.PriorityLevel - // set true if not allow balance leader from this store - ForbidSplit bool + // check the store not split recently in it if set true. + ForbidRecentlySplitRegions bool // Reason is used to distinguish the reason of store state filter Reason filterType } @@ -474,7 +474,7 @@ func (f *StoreStateFilter) hasRejectLeaderProperty(conf config.SharedConfigProvi } func (f *StoreStateFilter) hasSplitRegion(_ config.SharedConfigProvider, store *core.StoreInfo) *plan.Status { - if f.ForbidSplit && store.IsSplitStore() { + if f.ForbidRecentlySplitRegions && store.HasRecentlySplitRegions() { f.Reason = storeStateSplitRegion return statusStoreSplitRegion } diff --git a/pkg/schedule/filter/status.go b/pkg/schedule/filter/status.go index fc3f3a52080..79cd706fac5 100644 --- a/pkg/schedule/filter/status.go +++ b/pkg/schedule/filter/status.go @@ -41,7 +41,7 @@ var ( statusStoreNotMatchRule = plan.NewStatus(plan.StatusStoreNotMatchRule) statusStoreNotMatchIsolation = plan.NewStatus(plan.StatusStoreNotMatchIsolation) - statusStoreSplitRegion = plan.NewStatus(plan.StatusStoreSplitRegion) + statusStoreSplitRegion = plan.NewStatus(plan.StatusStoreRecentlySplitRegions) // region filter status statusRegionPendingPeer = plan.NewStatus(plan.StatusRegionUnhealthy) diff --git a/pkg/schedule/plan/status.go b/pkg/schedule/plan/status.go index 639bce51f79..847d03a17ff 100644 --- a/pkg/schedule/plan/status.go +++ b/pkg/schedule/plan/status.go @@ -72,8 +72,8 @@ const ( StatusStoreLowSpace = iota + 500 // StatusStoreNotExisted represents the store cannot be found in PD. StatusStoreNotExisted - // StatusStoreSplitRegion represents the store cannot be selected due to the region is splitting. - StatusStoreSplitRegion + // StatusStoreRecentlySplitRegions represents the store cannot be selected due to the region is splitting. + StatusStoreRecentlySplitRegions ) // TODO: define region status priority @@ -129,8 +129,8 @@ var statusText = map[StatusCode]string{ StatusStoreDown: "StoreDown", StatusStoreBusy: "StoreBusy", - StatusStoreNotExisted: "StoreNotExisted", - StatusStoreSplitRegion: "StoreSplitRegion", + StatusStoreNotExisted: "StoreNotExisted", + StatusStoreRecentlySplitRegions: "StoreRecentlySplitRegions", // region StatusRegionHot: "RegionHot", diff --git a/pkg/schedule/schedulers/balance_leader.go b/pkg/schedule/schedulers/balance_leader.go index 778c6826384..cb380724f4b 100644 --- a/pkg/schedule/schedulers/balance_leader.go +++ b/pkg/schedule/schedulers/balance_leader.go @@ -57,14 +57,14 @@ const ( var ( // WithLabelValues is a heavy operation, define variable to avoid call it every time. - balanceLeaderScheduleCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "schedule") - balanceLeaderNoLeaderRegionCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "no-leader-region") - balanceLeaderRegionHotCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "region-hot") - balanceLeaderNoTargetStoreCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "no-target-store") - balanceLeaderNoFollowerRegionCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "no-follower-region") - balanceLeaderSkipCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "skip") - balanceLeaderNewOpCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "new-operator") - balanceLeaderSourceSplitRegion = schedulerCounter.WithLabelValues(BalanceLeaderName, "source-split-region") + balanceLeaderScheduleCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "schedule") + balanceLeaderNoLeaderRegionCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "no-leader-region") + balanceLeaderRegionHotCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "region-hot") + balanceLeaderNoTargetStoreCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "no-target-store") + balanceLeaderNoFollowerRegionCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "no-follower-region") + balanceLeaderSkipCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "skip") + balanceLeaderNewOpCounter = schedulerCounter.WithLabelValues(BalanceLeaderName, "new-operator") + balanceLeaderStoreRecentlySplitRegions = schedulerCounter.WithLabelValues(BalanceLeaderName, "source-split-region") ) type balanceLeaderSchedulerConfig struct { @@ -182,7 +182,7 @@ func newBalanceLeaderScheduler(opController *operator.Controller, conf *balanceL option(s) } s.filters = []filter.Filter{ - &filter.StoreStateFilter{ActionScope: s.GetName(), TransferLeader: true, ForbidSplit: true, OperatorLevel: constant.High}, + &filter.StoreStateFilter{ActionScope: s.GetName(), TransferLeader: true, ForbidRecentlySplitRegions: true, OperatorLevel: constant.High}, filter.NewSpecialUseFilter(s.GetName()), } return s @@ -491,12 +491,12 @@ func (l *balanceLeaderScheduler) transferLeaderIn(solver *solver, collector *pla return nil } - if solver.Source.IsSplitStore() { - log.Debug("source store split region in one minutes", + if solver.Source.HasRecentlySplitRegions() { + log.Debug("source store recently splits region in one minutes", zap.String("scheduler", l.GetName()), zap.Uint64("store-id", leaderStoreID), ) - balanceLeaderSourceSplitRegion.Inc() + balanceLeaderStoreRecentlySplitRegions.Inc() return nil } finalFilters := l.filters diff --git a/pkg/schedule/schedulers/balance_test.go b/pkg/schedule/schedulers/balance_test.go index 43de62da5c7..3231716c681 100644 --- a/pkg/schedule/schedulers/balance_test.go +++ b/pkg/schedule/schedulers/balance_test.go @@ -298,7 +298,7 @@ func (suite *balanceLeaderSchedulerTestSuite) TestBalanceLimit() { // can't balance leader from 4 to 1 when store 1 has split in it. store := suite.tc.GetStore(4) - store = store.Clone(core.SetLastSplitTime(time.Now())) + store = store.Clone(core.SetRecentlySplitRegionsTime(time.Now())) suite.tc.PutStore(store) op := suite.schedule() suite.Empty(op) diff --git a/server/cluster/cluster_worker.go b/server/cluster/cluster_worker.go index 08302fdab63..f194c8014a5 100644 --- a/server/cluster/cluster_worker.go +++ b/server/cluster/cluster_worker.go @@ -91,7 +91,7 @@ func (c *RaftCluster) ProcessRegionSplit(regions []*metapb.Region) []error { } // If the number of regions exceeds the threshold, update the last split time. if len(regions) >= maxSplitThreshold { - newStore := leaderStore.Clone(core.SetLastSplitTime(time.Now())) + newStore := leaderStore.Clone(core.SetRecentlySplitRegionsTime(time.Now())) c.core.PutStore(newStore) } return errList diff --git a/server/cluster/cluster_worker_test.go b/server/cluster/cluster_worker_test.go index bacbacd95da..98b9b8380f1 100644 --- a/server/cluster/cluster_worker_test.go +++ b/server/cluster/cluster_worker_test.go @@ -111,7 +111,7 @@ func TestReportBatchSplit(t *testing.T) { cluster.coordinator = schedule.NewCoordinator(ctx, cluster, nil) store := newTestStores(1, "2.0.0") cluster.core.PutStore(store[0]) - re.False(cluster.GetStore(1).IsSplitStore()) + re.False(cluster.GetStore(1).HasRecentlySplitRegions()) regions := []*metapb.Region{ {Id: 1, StartKey: []byte(""), EndKey: []byte("a"), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3})}, {Id: 2, StartKey: []byte("a"), EndKey: []byte("b"), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3})}, @@ -142,5 +142,5 @@ func TestReportBatchSplit(t *testing.T) { _, err = cluster.HandleBatchReportSplit(&pdpb.ReportBatchSplitRequest{Regions: regions}) re.NoError(err) - re.True(cluster.GetStore(1).IsSplitStore()) + re.True(cluster.GetStore(1).HasRecentlySplitRegions()) }