Skip to content

Commit

Permalink
scheduler: remove the useless code in hot-region-scheduler (#3833)
Browse files Browse the repository at this point in the history
Signed-off-by: HunDunDM <hundundm@gmail.com>
  • Loading branch information
HunDunDM committed Sep 8, 2021
1 parent 9a0d2b3 commit 5fa185c
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ type hotScheduler struct {
name string
*BaseScheduler
sync.RWMutex
leaderLimit uint64
peerLimit uint64
types []rwType
r *rand.Rand
types []rwType
r *rand.Rand

// states across multiple `Schedule` calls
pendings [resourceTypeLen]map[*pendingInfluence]struct{}
Expand All @@ -114,8 +112,6 @@ func newHotScheduler(opController *schedule.OperatorController, conf *hotRegionS
ret := &hotScheduler{
name: HotRegionName,
BaseScheduler: base,
leaderLimit: 1,
peerLimit: 1,
types: []rwType{write, read},
r: rand.New(rand.NewSource(time.Now().UnixNano())),
regionPendings: make(map[uint64]*operator.Operator),
Expand Down Expand Up @@ -580,9 +576,9 @@ func (bs *balanceSolver) solve() []*operator.Operator {
}
bs.cur = &solution{}
var (
best *solution
ops []*operator.Operator
infls []Influence
best *solution
op *operator.Operator
infl Influence
)

for srcStoreID := range bs.filterSrcStores() {
Expand All @@ -598,9 +594,9 @@ func (bs *balanceSolver) solve() []*operator.Operator {
bs.cur.dstStoreID = dstStoreID
bs.calcProgressiveRank()
if bs.cur.progressiveRank < 0 && bs.betterThan(best) {
if newOps, newInfls := bs.buildOperators(); len(newOps) > 0 {
ops = newOps
infls = newInfls
if newOp, newInfl := bs.buildOperator(); newOp != nil {
op = newOp
infl = newInfl
clone := *bs.cur
best = &clone
}
Expand All @@ -609,13 +605,11 @@ func (bs *balanceSolver) solve() []*operator.Operator {
}
}

for i := 0; i < len(ops); i++ {
// TODO: multiple operators need to be atomic.
if !bs.sche.addPendingInfluence(ops[i], best.srcStoreID, best.dstStoreID, infls[i], bs.rwTy, bs.opTy) {
return nil
}
if best == nil || !bs.sche.addPendingInfluence(op, best.srcStoreID, best.dstStoreID, infl, bs.rwTy, bs.opTy) {
return nil
}
return ops

return []*operator.Operator{op}
}

func (bs *balanceSolver) filterSrcStores() map[uint64]*storeLoadDetail {
Expand Down Expand Up @@ -1004,12 +998,11 @@ func (bs *balanceSolver) isReadyToBuild() bool {
return true
}

func (bs *balanceSolver) buildOperators() ([]*operator.Operator, []Influence) {
func (bs *balanceSolver) buildOperator() (op *operator.Operator, infl Influence) {
if !bs.isReadyToBuild() {
return nil, nil
return nil, Influence{}
}
var (
op *operator.Operator
counters []prometheus.Counter
err error
)
Expand All @@ -1031,7 +1024,7 @@ func (bs *balanceSolver) buildOperators() ([]*operator.Operator, []Influence) {
balanceHotRegionCounter.WithLabelValues("move-peer", strconv.FormatUint(dstPeer.GetStoreId(), 10)+"-in", bs.rwTy.String()))
case transferLeader:
if bs.cur.region.GetStoreVoter(bs.cur.dstStoreID) == nil {
return nil, nil
return nil, Influence{}
}
op, err = operator.CreateTransferLeaderOperator(
"transfer-hot-"+bs.rwTy.String()+"-leader",
Expand All @@ -1048,7 +1041,7 @@ func (bs *balanceSolver) buildOperators() ([]*operator.Operator, []Influence) {
if err != nil {
log.Debug("fail to create operator", zap.Stringer("rwType", bs.rwTy), zap.Stringer("opType", bs.opTy), errs.ZapError(err))
schedulerCounter.WithLabelValues(bs.sche.GetName(), "create-operator-fail").Inc()
return nil, nil
return nil, Influence{}
}

op.SetPriorityLevel(core.HighPriority)
Expand All @@ -1057,13 +1050,13 @@ func (bs *balanceSolver) buildOperators() ([]*operator.Operator, []Influence) {
schedulerCounter.WithLabelValues(bs.sche.GetName(), "new-operator"),
schedulerCounter.WithLabelValues(bs.sche.GetName(), bs.opTy.String()))

infl := Influence{
infl = Influence{
ByteRate: bs.cur.srcPeerStat.GetByteRate(),
KeyRate: bs.cur.srcPeerStat.GetKeyRate(),
Count: 1,
}

return []*operator.Operator{op}, []Influence{infl}
return op, infl
}

func (h *hotScheduler) GetHotReadStatus() *statistics.StoreHotPeersInfos {
Expand Down

0 comments on commit 5fa185c

Please sign in to comment.