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: speed up exit #5341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions server/schedulers/balance_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ func (l *balanceLeaderScheduler) Schedule(cluster schedule.Cluster, dryRun bool)

result := make([]*operator.Operator, 0, batch)
for sourceCandidate.hasStore() || targetCandidate.hasStore() {
// if coordinator is stopping, speed up exit.
if l.BaseScheduler.OpController.Ctx().Err() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can consider adding the context field for all schedulers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every scheduler have a BaseScheduler, and BaseScheduler have opController with a context filed, I think it's no difference.

break
}

// first choose source
if sourceCandidate.hasStore() {
op := createTransferLeaderOperator(sourceCandidate, transferOut, l, plan, usedRegions)
Expand Down
4 changes: 4 additions & 0 deletions server/schedulers/balance_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func (s *balanceRegionScheduler) Schedule(cluster schedule.Cluster, dryRun bool)
for _, plan.source = range stores {
retryLimit := s.retryQuota.GetLimit(plan.source)
for i := 0; i < retryLimit; i++ {
if s.BaseScheduler.OpController.Ctx().Err() != nil {
break
}

schedulerCounter.WithLabelValues(s.GetName(), "total").Inc()
// Priority pick the region that has a pending peer.
// Pending region may means the disk is overload, remove the pending region firstly.
Expand Down
14 changes: 14 additions & 0 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ func (bs *balanceSolver) solve() []*operator.Operator {
bs.cur.mainPeerStat = mainPeerStat

for _, dstStore := range bs.filterDstStores() {
if bs.sche.OpController.Ctx().Err() != nil {
goto fastExit
}

bs.cur.dstStore = dstStore
bs.calcProgressiveRank()
tryUpdateBestSolution(isUniformFirstPriority)
Expand Down Expand Up @@ -594,6 +598,8 @@ func (bs *balanceSolver) solve() []*operator.Operator {
}
}
}

fastExit:
searchRevertRegions = bs.allowSearchRevertRegions()
bs.sche.searchRevertRegions[bs.resourceTy] = searchRevertRegions
if searchRevertRegions {
Expand Down Expand Up @@ -660,6 +666,10 @@ func (bs *balanceSolver) filterSrcStores() map[uint64]*statistics.StoreLoadDetai
confSrcToleranceRatio := bs.sche.conf.GetSrcToleranceRatio()
confEnableForTiFlash := bs.sche.conf.GetEnableForTiFlash()
for id, detail := range bs.stLoadDetail {
if bs.sche.OpController.Ctx().Err() != nil {
break
}

srcToleranceRatio := confSrcToleranceRatio
if detail.IsTiFlash() {
if !confEnableForTiFlash {
Expand Down Expand Up @@ -863,6 +873,10 @@ func (bs *balanceSolver) pickDstStores(filters []filter.Filter, candidates []*st
confDstToleranceRatio := bs.sche.conf.GetDstToleranceRatio()
confEnableForTiFlash := bs.sche.conf.GetEnableForTiFlash()
for _, detail := range candidates {
if bs.sche.OpController.Ctx().Err() != nil {
break
}

store := detail.StoreInfo
dstToleranceRatio := confDstToleranceRatio
if detail.IsTiFlash() {
Expand Down