From c21656e2f1c837132568a611790b9f6348ed6409 Mon Sep 17 00:00:00 2001 From: p4tr1ck Date: Thu, 9 Dec 2021 16:25:37 +0800 Subject: [PATCH] server/schedule: use ChangePeerV2 to demote single voter directly ref #4444. Signed-off-by: p4tr1ck --- server/schedule/operator/step.go | 14 ++++++++++++++ server/schedule/operator_controller.go | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/server/schedule/operator/step.go b/server/schedule/operator/step.go index 29f30fe769b..66db0f2132a 100644 --- a/server/schedule/operator/step.go +++ b/server/schedule/operator/step.go @@ -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 { diff --git a/server/schedule/operator_controller.go b/server/schedule/operator_controller.go index 36d28e60bb0..bfd0b947c60 100644 --- a/server/schedule/operator_controller.go +++ b/server/schedule/operator_controller.go @@ -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{