Skip to content

Commit

Permalink
speed up checkSuspectRegions and checkWaitingRegions
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Apr 18, 2024
1 parent 08e9e37 commit 6494b22
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions pkg/schedule/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ func (c *Coordinator) PatrolRegions() {
// Check priority regions first.
c.checkPriorityRegions()
// Check suspect regions first.
c.checkSuspectRegions()
c.checkSuspectRegions(regionChan)
// Check regions in the waiting list
c.checkWaitingRegions()
c.checkWaitingRegions(regionChan)

// Avoid to check the same regions repeatedly.
if len(key) == 0 && len(regionChan) != 0 {
Expand Down Expand Up @@ -255,19 +255,39 @@ func (c *Coordinator) isSchedulingHalted() bool {
return c.cluster.GetSchedulerConfig().IsSchedulingHalted()
}

func (c *Coordinator) checkSuspectRegions() {
func (c *Coordinator) checkSuspectRegions(regionChan chan *core.RegionInfo) {
for _, id := range c.checkers.GetSuspectRegions() {
region := c.cluster.GetRegion(id)
c.tryAddOperators(region)
regionChan <- region
}
for {
select {
case <-c.ctx.Done():
return
default:
if len(regionChan) == 0 {
return
}
}
}
}

func (c *Coordinator) checkWaitingRegions() {
func (c *Coordinator) checkWaitingRegions(regionChan chan *core.RegionInfo) {
items := c.checkers.GetWaitingRegions()
waitingListGauge.Set(float64(len(items)))
for _, item := range items {
region := c.cluster.GetRegion(item.Key)
c.tryAddOperators(region)
regionChan <- region
}
for {
select {
case <-c.ctx.Done():
return
default:
if len(regionChan) == 0 {
return
}
}
}
}

Expand Down

0 comments on commit 6494b22

Please sign in to comment.