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

scheduler: simplify the limit judgment of hot-region-scheduler #3834

Merged
merged 4 commits into from
Jul 8, 2021
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
33 changes: 1 addition & 32 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,6 @@ func (h *hotScheduler) GetNextInterval(interval time.Duration) time.Duration {
}

func (h *hotScheduler) IsScheduleAllowed(cluster opt.Cluster) bool {
return h.allowBalanceLeader(cluster) || h.allowBalanceRegion(cluster)
}

func (h *hotScheduler) allowBalanceLeader(cluster opt.Cluster) bool {
hotRegionAllowed := h.OpController.OperatorCount(operator.OpHotRegion) < cluster.GetOpts().GetHotRegionScheduleLimit()
leaderAllowed := h.OpController.OperatorCount(operator.OpLeader) < cluster.GetOpts().GetLeaderScheduleLimit()
if !hotRegionAllowed {
operator.OperatorLimitCounter.WithLabelValues(h.GetType(), operator.OpHotRegion.String()).Inc()
}
if !leaderAllowed {
operator.OperatorLimitCounter.WithLabelValues(h.GetType(), operator.OpLeader.String()).Inc()
}
return hotRegionAllowed && leaderAllowed
}

func (h *hotScheduler) allowBalanceRegion(cluster opt.Cluster) bool {
allowed := h.OpController.OperatorCount(operator.OpHotRegion) < cluster.GetOpts().GetHotRegionScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(h.GetType(), operator.OpHotRegion.String()).Inc()
Expand Down Expand Up @@ -507,7 +491,7 @@ func (bs *balanceSolver) isValid() bool {
// solve travels all the src stores, hot peers, dst stores and select each one of them to make a best scheduling solution.
// The comparing between solutions is based on calcProgressiveRank.
func (bs *balanceSolver) solve() []*operator.Operator {
if !bs.isValid() || !bs.allowBalance() {
if !bs.isValid() {
return nil
}
bs.cur = &solution{}
Expand Down Expand Up @@ -548,18 +532,6 @@ func (bs *balanceSolver) solve() []*operator.Operator {
return []*operator.Operator{op}
}

// allowBalance check whether the operator count have exceed the hot region limit by type
func (bs *balanceSolver) allowBalance() bool {
switch bs.opTy {
case movePeer:
return bs.sche.allowBalanceRegion(bs.cluster)
case transferLeader:
return bs.sche.allowBalanceLeader(bs.cluster)
default:
return false
}
}

// filterSrcStores compare the min rate and the ratio * expectation rate, if both key and byte rate is greater than
// its expectation * ratio, the store would be selected as hot source store
func (bs *balanceSolver) filterSrcStores() map[uint64]*storeLoadDetail {
Expand Down Expand Up @@ -1012,9 +984,6 @@ func (bs *balanceSolver) buildOperator() (op *operator.Operator, infl *Influence
dstPeer := &metapb.Peer{StoreId: bs.cur.dstStoreID, Role: srcPeer.Role}
typ := "move-peer"
if bs.rwTy == read && bs.cur.region.GetLeader().StoreId == bs.cur.srcStoreID { // move read leader
if !bs.sche.allowBalanceLeader(bs.cluster) {
return nil, nil
}
op, err = operator.CreateMoveLeaderOperator(
"move-hot-read-leader",
bs.cluster,
Expand Down
9 changes: 3 additions & 6 deletions server/schedulers/hot_region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,10 @@ func (s *testHotWriteRegionSchedulerSuite) checkByteRateOnly(c *C, tc *mockclust

// hot region scheduler is restricted by `hot-region-schedule-limit`.
tc.SetHotRegionScheduleLimit(0)
c.Assert(hb.Schedule(tc), HasLen, 0)
c.Assert(hb.IsScheduleAllowed(tc), IsFalse)
hb.(*hotScheduler).clearPendingInfluence()
tc.SetHotRegionScheduleLimit(int(config.NewTestOptions().GetScheduleConfig().HotRegionScheduleLimit))

// hot region scheduler is restricted by schedule limit.
tc.SetLeaderScheduleLimit(0)
for i := 0; i < 20; i++ {
op := hb.Schedule(tc)[0]
hb.(*hotScheduler).clearPendingInfluence()
Expand All @@ -248,7 +246,6 @@ func (s *testHotWriteRegionSchedulerSuite) checkByteRateOnly(c *C, tc *mockclust
testutil.CheckTransferPeerWithLeaderTransfer(c, op, operator.OpHotRegion, 1, 6)
}
}
tc.SetLeaderScheduleLimit(int(config.NewTestOptions().GetScheduleConfig().LeaderScheduleLimit))

// hot region scheduler is not affect by `balance-region-schedule-limit`.
tc.SetRegionScheduleLimit(0)
Expand Down Expand Up @@ -299,7 +296,7 @@ func (s *testHotWriteRegionSchedulerSuite) checkByteRateOnly(c *C, tc *mockclust
// Region 1 and 2 are the same, cannot move peer to store 5 due to the label.
// Region 3 can only move peer to store 5.
// Region 5 can only move peer to store 6.
tc.SetLeaderScheduleLimit(0)
tc.SetHotRegionScheduleLimit(0)
for i := 0; i < 30; i++ {
op := hb.Schedule(tc)[0]
hb.(*hotScheduler).clearPendingInfluence()
Expand Down Expand Up @@ -532,7 +529,7 @@ func (s *testHotWriteRegionSchedulerSuite) TestWithPendingInfluence(c *C) {
// 1: key rate
tc := mockcluster.NewCluster(ctx, opt)
tc.SetHotRegionCacheHitsThreshold(0)
tc.SetLeaderScheduleLimit(0)
tc.SetHotRegionScheduleLimit(0)
tc.DisableFeature(versioninfo.JointConsensus)
tc.AddRegionStore(1, 20)
tc.AddRegionStore(2, 20)
Expand Down
4 changes: 2 additions & 2 deletions server/schedulers/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (s *testHotRegionSchedulerSuite) TestAbnormalReplica(c *C) {
defer cancel()
opt := config.NewTestOptions()
tc := mockcluster.NewCluster(ctx, opt)
tc.SetLeaderScheduleLimit(0)
tc.SetHotRegionScheduleLimit(0)
hb, err := schedule.CreateScheduler(HotReadRegionType, schedule.NewOperatorController(ctx, nil, nil), core.NewStorage(kv.NewMemoryKV()), nil)
c.Assert(err, IsNil)

Expand All @@ -237,7 +237,7 @@ func (s *testHotRegionSchedulerSuite) TestAbnormalReplica(c *C) {
tc.AddRegionWithReadInfo(3, 1, 512*KB*statistics.ReadReportInterval, 0, statistics.ReadReportInterval, []uint64{2, 3})
tc.SetHotRegionCacheHitsThreshold(0)
c.Assert(tc.IsRegionHot(tc.GetRegion(1)), IsTrue)
c.Assert(hb.Schedule(tc), IsNil)
c.Assert(hb.IsScheduleAllowed(tc), IsFalse)
}

var _ = Suite(&testEvictLeaderSuite{})
Expand Down