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

region_scatter: fix a bug that PD may panic when scatter region if region is unhealthy #6128

Merged
merged 3 commits into from
Mar 9, 2023
Merged
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
10 changes: 6 additions & 4 deletions server/schedule/region_scatterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,14 @@ func allowLeader(fit *placement.RegionFit, peer *metapb.Peer) bool {
if peer.IsWitness {
return false
}

rule := fit.GetRuleFit(peer.GetId()).Rule
if rule.IsWitness {
peerFit := fit.GetRuleFit(peer.GetId())
if peerFit == nil || peerFit.Rule == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not add one condition peerFit.Rule.IsWitness?

return false
}
if peerFit.Rule.IsWitness {
return false
}
switch rule.Role {
switch peerFit.Rule.Role {
case placement.Voter, placement.Leader:
return true
}
Expand Down
5 changes: 5 additions & 0 deletions server/schedule/region_scatterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,11 @@ func TestBalanceRegion(t *testing.T) {
re.Equal(uint64(150), scatterer.ordinaryEngine.selectedPeer.Get(i, group))
re.Equal(uint64(50), scatterer.ordinaryEngine.selectedLeader.Get(i, group))
}
// Test for unhealthy region
// ref https://github.com/tikv/pd/issues/6099
region := tc.AddLeaderRegion(1500, 2, 3, 4, 6)
op := scatterer.scatterRegion(region, group)
re.False(isPeerCountChanged(op))
}

func isPeerCountChanged(op *operator.Operator) bool {
Expand Down