Skip to content

Commit

Permalink
server/schedule: use ChangePeerV2 to demote single voter directly
Browse files Browse the repository at this point in the history
ref tikv#4444.

Signed-off-by: p4tr1ck <patricknicholas@foxmail.com>
  • Loading branch information
w41ter committed Dec 9, 2021
1 parent b017ec5 commit c21656e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions server/schedule/operator/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,20 @@ func (df DemoteFollower) CheckInProgress(cluster opt.Cluster, region *core.Regio
// Influence calculates the store difference that current step makes.
func (df DemoteFollower) Influence(opInfluence OpInfluence, region *core.RegionInfo) {}

// GetRequest get the ChangePeerV2 request
func (df DemoteFollower) GetRequest() *pdpb.ChangePeerV2 {
return &pdpb.ChangePeerV2{
Changes: []*pdpb.ChangePeer{{
ChangeType: eraftpb.ConfChangeType_AddLearnerNode,
Peer: &metapb.Peer{
Id: df.PeerID,
StoreId: df.ToStore,
Role: metapb.PeerRole_Learner,
},
}},
}
}

// DemoteVoter is very similar to DemoteFollower. But it allows Demote Leader.
// Note: It is not an OpStep, only a sub step in ChangePeerV2Enter and ChangePeerV2Leave.
type DemoteVoter struct {
Expand Down
4 changes: 3 additions & 1 deletion server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,9 @@ func (oc *OperatorController) SendScheduleCommand(region *core.RegionInfo, step
case operator.PromoteLearner:
cmd = addNode(st.PeerID, st.ToStore)
case operator.DemoteFollower:
cmd = addLearnerNode(st.PeerID, st.ToStore)
cmd = &pdpb.RegionHeartbeatResponse{
ChangePeerV2: st.GetRequest(),
}
case operator.RemovePeer:
cmd = &pdpb.RegionHeartbeatResponse{
ChangePeer: &pdpb.ChangePeer{
Expand Down

0 comments on commit c21656e

Please sign in to comment.