Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Mar 9, 2023
2 parents 07d9273 + fda6fef commit 88a02b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 3 additions & 9 deletions server/schedule/region_scatterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,11 @@ func allowLeader(fit *placement.RegionFit, peer *metapb.Peer) bool {
if peer.IsWitness {
return false
}

f := fit.GetRuleFit(peer.GetId())
if f == nil {
return false
}

rule := f.Rule
if rule == nil || rule.IsWitness {
peerFit := fit.GetRuleFit(peer.GetId())
if peerFit == nil || peerFit.Rule == nil || 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

0 comments on commit 88a02b4

Please sign in to comment.