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

Fix panic of adjacent-region-scheduler after pd transfer leader #1250

Merged
merged 2 commits into from
Sep 20, 2018
Merged
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
9 changes: 7 additions & 2 deletions server/schedulers/adjacent_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func (l *balanceAdjacentRegionScheduler) Schedule(cluster schedule.Cluster, opIn
regions := cluster.ScanRegions(l.lastKey, scanLimit)
// scan to the end
if len(regions) <= 1 {
l.adjacentRegionsCount = 0
schedulerStatus.WithLabelValues(l.GetName(), "adjacent_count").Set(float64(l.adjacentRegionsCount))
l.adjacentRegionsCount = 0
l.lastKey = []byte("")
return nil
}
Expand Down Expand Up @@ -199,7 +199,9 @@ func (l *balanceAdjacentRegionScheduler) process(cluster schedule.Cluster) []*sc
l.cacheRegions.head = head + 1
l.lastKey = r2.GetStartKey()
}()
if l.unsafeToBalance(cluster, r1) {
// after the cluster is prepared, there is a gap that some regions heartbeats are not received.
// Leader of those region is nil, and we should skip them.
if r1.GetLeader() == nil || r2.GetLeader() == nil || l.unsafeToBalance(cluster, r1) {
schedulerCounter.WithLabelValues(l.GetName(), "skip").Inc()
return nil
}
Expand All @@ -221,6 +223,9 @@ func (l *balanceAdjacentRegionScheduler) unsafeToBalance(cluster schedule.Cluste
return true
}
store := cluster.GetStore(region.GetLeader().GetStoreId())
if store == nil {
return true
}
s := l.selector.SelectSource(cluster, []*core.StoreInfo{store})
if s == nil {
return true
Expand Down