Fix panic of adjacent-region-scheduler after pd transfer leader #1250
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
If
adjacent-region
scheduler is enabled, after pd transfers leader and the new leader is prepared,there is a gap that heartbeats of some regions are not received, and leaders are not updated.
store id of a nil peer is
0
, see https://github.com/pingcap/pd/blob/fa5f08c252a4c5025cdef5bf0f2bdab78d7c0a36/vendor/github.com/pingcap/kvproto/pkg/metapb/metapb.pb.go#L256, so this line https://github.com/pingcap/pd/blob/fa5f08c252a4c5025cdef5bf0f2bdab78d7c0a36/server/schedulers/adjacent_region.go#L223 return anil
store, which causes panic.What is changed and how it works?
This change makes sure that region's leader is not nil, and leader's store is not nil, and also fix metric value of adjacent-count.
Another solution is skip holes of not heartbeat-ed regions when calculating adjacent-regions, which prevents the issue at front.
Check List
Tests
make test
No side effects