From 1316a22f0738f48fe73e7e016105b7ec63657aa9 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Fri, 20 Oct 2023 16:43:09 +0800 Subject: [PATCH] fix test Signed-off-by: lhy1024 --- pkg/schedule/checker/rule_checker.go | 12 ++++++++---- server/cluster/cluster_test.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/schedule/checker/rule_checker.go b/pkg/schedule/checker/rule_checker.go index feb5434579d1..cec8e80ed118 100644 --- a/pkg/schedule/checker/rule_checker.go +++ b/pkg/schedule/checker/rule_checker.go @@ -463,6 +463,7 @@ loopFits: // Isdisconnected is more strictly than IsUnhealthy. if c.cluster.GetStore(p.GetStoreId()).IsDisconnected() { hasUnhealthyFit = true + pinDownPeer = p break loopFits } } @@ -481,6 +482,10 @@ loopFits: if isUnhealthyPeer(orphanPeer.GetId()) { continue } + // make sure the orphan peer is not in disconnect store. + if c.cluster.GetStore(orphanPeer.GetStoreId()).IsDisconnected() { + continue + } // no consider witness in this path. if pinDownPeer.GetIsWitness() || orphanPeer.GetIsWitness() { continue @@ -500,6 +505,8 @@ loopFits: return operator.CreatePromoteLearnerOperatorAndRemovePeer("replace-down-peer-with-orphan-peer", c.cluster, region, orphanPeer, pinDownPeer) 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: + return operator.CreateRemovePeerOperator("remove-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. // destRole never be leader, so we not consider it. @@ -522,10 +529,7 @@ loopFits: ruleCheckerRemoveOrphanPeerCounter.Inc() return operator.CreateRemovePeerOperator("remove-orphan-peer", c.cluster, 0, region, orphanPeer.StoreId) } - // If the store is disconnected, we cannot be sure whether it is healthy. - if !c.cluster.GetStore(orphanPeer.GetStoreId()).IsDisconnected() { - hasHealthPeer = true - } + hasHealthPeer = true } } ruleCheckerSkipRemoveOrphanPeerCounter.Inc() diff --git a/server/cluster/cluster_test.go b/server/cluster/cluster_test.go index b7b9dcfb736d..89c9ea32f19e 100644 --- a/server/cluster/cluster_test.go +++ b/server/cluster/cluster_test.go @@ -2796,7 +2796,7 @@ func TestReplica(t *testing.T) { re.NoError(tc.addLeaderRegion(2, 1, 2, 3, 4)) region = tc.GetRegion(2) re.NoError(dispatchHeartbeat(co, region, stream)) - region = waitRemovePeer(re, stream, region, 4) + region = waitRemovePeer(re, stream, region, 3) // store3 is down, we should remove it firstly. re.NoError(dispatchHeartbeat(co, region, stream)) waitNoResponse(re, stream)