Skip to content

Commit

Permalink
rename splitRegions
Browse files Browse the repository at this point in the history
Signed-off-by: bufferflies <1045931706@qq.com>
  • Loading branch information
bufferflies committed Sep 12, 2023
1 parent 64d6e95 commit def9e63
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 47 deletions.
40 changes: 20 additions & 20 deletions pkg/core/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 (
Expand Down
6 changes: 3 additions & 3 deletions pkg/core/store_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 3 additions & 3 deletions pkg/schedule/filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/filter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/schedule/plan/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,8 +129,8 @@ var statusText = map[StatusCode]string{
StatusStoreDown: "StoreDown",
StatusStoreBusy: "StoreBusy",

StatusStoreNotExisted: "StoreNotExisted",
StatusStoreSplitRegion: "StoreSplitRegion",
StatusStoreNotExisted: "StoreNotExisted",
StatusStoreRecentlySplitRegions: "StoreRecentlySplitRegions",

// region
StatusRegionHot: "RegionHot",
Expand Down
24 changes: 12 additions & 12 deletions pkg/schedule/schedulers/balance_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/cluster/cluster_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/cluster/cluster_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})},
Expand Down Expand Up @@ -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())
}

0 comments on commit def9e63

Please sign in to comment.