-
Notifications
You must be signed in to change notification settings - Fork 728
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
checker: replace down check with disconnect check when fixing orphan peer #7294
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -447,7 +447,7 @@ func (c *RuleChecker) fixOrphanPeers(region *core.RegionInfo, fit *placement.Reg | |
if len(fit.OrphanPeers) == 0 { | ||
return nil, nil | ||
} | ||
var pinDownPeer *metapb.Peer | ||
|
||
isUnhealthyPeer := func(id uint64) bool { | ||
for _, downPeer := range region.GetDownPeers() { | ||
if downPeer.Peer.GetId() == id { | ||
|
@@ -461,31 +461,41 @@ func (c *RuleChecker) fixOrphanPeers(region *core.RegionInfo, fit *placement.Reg | |
} | ||
return false | ||
} | ||
|
||
isDisconnectedPeer := func(p *metapb.Peer) bool { | ||
// avoid to meet down store when fix orphan peers, | ||
// Isdisconnected is more strictly than IsUnhealthy. | ||
return c.cluster.GetStore(p.GetStoreId()).IsDisconnected() | ||
} | ||
|
||
checkDownPeer := func(peers []*metapb.Peer) (*metapb.Peer, bool) { | ||
for _, p := range peers { | ||
if isUnhealthyPeer(p.GetId()) { | ||
// make sure is down peer. | ||
if region.GetDownPeer(p.GetId()) != nil { | ||
return p, true | ||
} | ||
return nil, true | ||
} | ||
if isDisconnectedPeer(p) { | ||
return p, true | ||
} | ||
} | ||
return nil, false | ||
} | ||
|
||
// remove orphan peers only when all rules are satisfied (count+role) and all peers selected | ||
// by RuleFits is not pending or down. | ||
var pinDownPeer *metapb.Peer | ||
hasUnhealthyFit := false | ||
loopFits: | ||
for _, rf := range fit.RuleFits { | ||
if !rf.IsSatisfied() { | ||
hasUnhealthyFit = true | ||
break | ||
} | ||
for _, p := range rf.Peers { | ||
if isUnhealthyPeer(p.GetId()) { | ||
// make sure is down peer. | ||
if region.GetDownPeer(p.GetId()) != nil { | ||
pinDownPeer = p | ||
} | ||
hasUnhealthyFit = true | ||
break loopFits | ||
} | ||
// avoid to meet down store when fix orpahn peers, | ||
// Isdisconnected is more strictly than IsUnhealthy. | ||
if c.cluster.GetStore(p.GetStoreId()).IsDisconnected() { | ||
hasUnhealthyFit = true | ||
pinDownPeer = p | ||
break loopFits | ||
} | ||
pinDownPeer, hasUnhealthyFit = checkDownPeer(rf.Peers) | ||
if hasUnhealthyFit { | ||
break | ||
} | ||
} | ||
|
||
|
@@ -502,15 +512,15 @@ loopFits: | |
continue | ||
} | ||
// make sure the orphan peer is healthy. | ||
if isUnhealthyPeer(orphanPeer.GetId()) { | ||
if isUnhealthyPeer(orphanPeer.GetId()) || isDisconnectedPeer(orphanPeer) { | ||
continue | ||
} | ||
// no consider witness in this path. | ||
if pinDownPeer.GetIsWitness() || orphanPeer.GetIsWitness() { | ||
continue | ||
} | ||
// down peer's store should be down. | ||
if !c.isStoreDownTimeHitMaxDownTime(pinDownPeer.GetStoreId()) { | ||
// down peer's store should be disconnected | ||
if !isDisconnectedPeer(pinDownPeer) { | ||
continue | ||
} | ||
// check if down peer can replace with orphan peer. | ||
|
@@ -525,7 +535,7 @@ loopFits: | |
case orphanPeerRole == metapb.PeerRole_Voter && destRole == metapb.PeerRole_Learner: | ||
return operator.CreateDemoteLearnerOperatorAndRemovePeer("replace-down-peer-with-orphan-peer", c.cluster, region, orphanPeer, pinDownPeer) | ||
case orphanPeerRole == metapb.PeerRole_Voter && destRole == metapb.PeerRole_Voter && | ||
c.cluster.GetStore(pinDownPeer.GetStoreId()).IsDisconnected() && !dstStore.IsDisconnected(): | ||
isDisconnectedPeer(pinDownPeer) && !dstStore.IsDisconnected(): | ||
return operator.CreateRemovePeerOperator("remove-replaced-orphan-peer", c.cluster, 0, region, pinDownPeer.GetStoreId()) | ||
default: | ||
// destRole should not same with orphanPeerRole. if role is same, it fit with orphanPeer should be better than now. | ||
|
@@ -541,8 +551,12 @@ loopFits: | |
hasHealthPeer := false | ||
for _, orphanPeer := range fit.OrphanPeers { | ||
if isUnhealthyPeer(orphanPeer.GetId()) { | ||
ruleCheckerRemoveOrphanPeerCounter.Inc() | ||
return operator.CreateRemovePeerOperator("remove-orphan-peer", c.cluster, 0, region, orphanPeer.StoreId) | ||
checkerCounter.WithLabelValues("rule_checker", "remove-orphan-peer").Inc() | ||
return operator.CreateRemovePeerOperator("remove-unhealthy-orphan-peer", c.cluster, 0, region, orphanPeer.StoreId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use "remove-unhealthy-orphan-peer" and "remove-disconnected-orphan-peer" to distinguish |
||
} | ||
if isDisconnectedPeer(orphanPeer) { | ||
checkerCounter.WithLabelValues("rule_checker", "remove-orphan-peer").Inc() | ||
return operator.CreateRemovePeerOperator("remove-disconnected-orphan-peer", c.cluster, 0, region, orphanPeer.StoreId) | ||
} | ||
if hasHealthPeer { | ||
// there already exists a healthy orphan peer, so we can remove other orphan Peers. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
isDisconnectedPeer
rather thanisStoreDownTimeHitMaxDownTime
, because we use stricter check inisDisconnectedPeer