Skip to content
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

server/schedule: use ChangePeerV2 to demote single voter directly #4445

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about add unit test?

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