Skip to content

Commit

Permalink
scheduler: simplify the limit judgment of hot-region-scheduler
Browse files Browse the repository at this point in the history
Signed-off-by: HunDunDM <hundundm@gmail.com>
  • Loading branch information
HunDunDM committed Jul 5, 2021
1 parent f6fc8fb commit 1711722
Showing 1 changed file with 1 addition and 32 deletions.
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

0 comments on commit 1711722

Please sign in to comment.