Skip to content

Commit

Permalink
remove logic for handling down peers
Browse files Browse the repository at this point in the history
ref tikv#5568

Signed-off-by: Wenbo Zhang <[email protected]>
  • Loading branch information
ethercflow committed Oct 20, 2022
1 parent d63a15f commit 5148ea8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 67 deletions.
21 changes: 2 additions & 19 deletions server/schedule/checker/rule_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 {
Expand Down
39 changes: 0 additions & 39 deletions server/schedule/checker/rule_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down
9 changes: 0 additions & 9 deletions server/schedule/operator/create_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 5148ea8

Please sign in to comment.