From 5148ea862f5e24844a91c5e94add8f46c76cf56c Mon Sep 17 00:00:00 2001 From: Wenbo Zhang Date: Thu, 20 Oct 2022 15:34:11 +0800 Subject: [PATCH] remove logic for handling down peers ref tikv/pd#5568 Signed-off-by: Wenbo Zhang --- server/schedule/checker/rule_checker.go | 21 +---------- server/schedule/checker/rule_checker_test.go | 39 -------------------- server/schedule/operator/create_operator.go | 9 ----- 3 files changed, 2 insertions(+), 67 deletions(-) diff --git a/server/schedule/checker/rule_checker.go b/server/schedule/checker/rule_checker.go index 6a02e866f50..8596af39412 100644 --- a/server/schedule/checker/rule_checker.go +++ b/server/schedule/checker/rule_checker.go @@ -201,10 +201,9 @@ func (c *RuleChecker) replaceUnexpectRulePeer(region *core.RegionInfo, rf *place return nil, errNoStoreToReplace } newPeer := &metapb.Peer{StoreId: store, Role: rf.Rule.Role.MetaPeerRole(), IsWitness: rf.Rule.IsWitness} - leaderID := region.GetLeader().GetId() // pick the smallest leader store to avoid the Offline store be snapshot generator bottleneck. var newLeader *metapb.Peer - if leaderID == peer.GetId() { + if region.GetLeader().GetId() == peer.GetId() { minCount := uint64(math.MaxUint64) for _, p := range region.GetPeers() { count := c.record.getOfflineLeaderCount(p.GetStoreId()) @@ -224,27 +223,11 @@ func (c *RuleChecker) replaceUnexpectRulePeer(region *core.RegionInfo, rf *place } } - var witness *metapb.Peer - for _, witness = range region.GetWitnesses() { - if witness.StoreId != peer.StoreId && witness.Id != leaderID { - break - } - } - createOp := func() (*operator.Operator, error) { if newLeader != nil && newLeader.GetId() != peer.GetId() { return operator.CreateReplaceLeaderPeerOperator("replace-rule-"+status+"-leader-peer", c.cluster, region, operator.OpReplica, peer.StoreId, newPeer, newLeader) } - /* TODO: enable this after the pr balance witness merged - if newPeer.IsWitness { - return operator.CreateMoveWitnessOperator("replace-rule-"+status+"-witness-peer", c.cluster, region, peer.StoreId, newPeer.StoreId, operator.OpWitness) - } - */ - if witness == nil { - return operator.CreateMovePeerOperator("replace-rule-"+status+"-peer", c.cluster, region, operator.OpReplica, peer.StoreId, newPeer) - } - newPeer.IsWitness = true - return operator.CreateMovePeerAndPromoteWitnessToVoterOperator("replace-rule-"+status+"-peer", c.cluster, region, operator.OpReplica, peer.StoreId, newPeer, witness.StoreId) + return operator.CreateMovePeerOperator("replace-rule-"+status+"-peer", c.cluster, region, operator.OpReplica, peer.StoreId, newPeer) } op, err := createOp() if err != nil { diff --git a/server/schedule/checker/rule_checker_test.go b/server/schedule/checker/rule_checker_test.go index 9308288fb80..93691a549ec 100644 --- a/server/schedule/checker/rule_checker_test.go +++ b/server/schedule/checker/rule_checker_test.go @@ -368,45 +368,6 @@ func (suite *ruleCheckerTestSuite) TestFixRuleWitness3() { } func (suite *ruleCheckerTestSuite) TestFixRuleWitness4() { - suite.cluster.AddLabelsStore(1, 1, map[string]string{"A": "leader"}) - suite.cluster.AddLabelsStore(2, 1, map[string]string{"B": "voter"}) - suite.cluster.AddLabelsStore(3, 1, map[string]string{"C": "voter"}) - suite.cluster.AddLabelsStore(4, 1, map[string]string{"D": "voter"}) - suite.cluster.AddLeaderRegion(1, 1, 2, 3) - - suite.cluster.SetStoreDown(2) - r := suite.cluster.GetRegion(1) - // set peer2 to down - r = r.Clone(core.WithDownPeers([]*pdpb.PeerStats{{Peer: r.GetStorePeer(2), DownSeconds: 60000}})) - // set peer3 to witness - r = r.Clone(core.WithWitnesses([]*metapb.Peer{r.GetPeer(3)})) - - suite.ruleManager.SetRule(&placement.Rule{ - GroupID: "pd", - ID: "default", - Role: placement.Voter, - Count: 2, - }) - suite.ruleManager.SetRule(&placement.Rule{ - GroupID: "pd", - ID: "r1", - Role: placement.Voter, - Count: 1, - IsWitness: true, - }) - - op := suite.rc.Check(r) - - suite.NotNil(op) - suite.Equal("replace-rule-down-peer", op.Desc()) - suite.Equal(uint64(4), op.Step(0).(operator.AddLearner).ToStore) - suite.Equal(uint64(4), op.Step(1).(operator.PromoteLearner).ToStore) - suite.Equal(uint64(2), op.Step(2).(operator.RemovePeer).FromStore) - suite.Equal(uint64(3), op.Step(3).(operator.RemovePeer).FromStore) - suite.Equal(uint64(3), op.Step(4).(operator.AddLearner).ToStore) -} - -func (suite *ruleCheckerTestSuite) TestFixRuleWitness5() { suite.cluster.AddLabelsStore(1, 1, map[string]string{"A": "leader"}) suite.cluster.AddLabelsStore(2, 1, map[string]string{"B": "voter"}) suite.cluster.AddLabelsStore(3, 1, map[string]string{"C": "voter"}) diff --git a/server/schedule/operator/create_operator.go b/server/schedule/operator/create_operator.go index f53cea2c1ee..ef88cb397a1 100644 --- a/server/schedule/operator/create_operator.go +++ b/server/schedule/operator/create_operator.go @@ -302,12 +302,3 @@ func CreateNonWitnessPeerOperator(desc string, ci ClusterInformer, region *core. brief := fmt.Sprintf("promote to non-witness: region %v peer %v on store %v", region.GetID(), peer.Id, peer.StoreId) return NewOperator(desc, brief, region.GetID(), region.GetRegionEpoch(), OpRegion, region.GetApproximateSize(), BecomeNonWitness{StoreID: peer.StoreId, PeerID: peer.Id}), nil } - -// CreateMovePeerAndPromoteWitnessToVoterOperator creates an operator that replaces an old peer with a new peer, and promote a witness to voter. -func CreateMovePeerAndPromoteWitnessToVoterOperator(desc string, ci ClusterInformer, region *core.RegionInfo, kind OpKind, oldStore uint64, peer *metapb.Peer, witnessStore uint64) (*Operator, error) { - return NewBuilder(desc, ci, region). - RemovePeer(oldStore). - AddPeer(peer). - BecomeNonWitness(witnessStore). - Build(kind) -}