From bce31330fc838cb40a3cf0dbeedbe0ff95bf9f08 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 31 Aug 2023 18:12:39 +0800 Subject: [PATCH] operator: remove cancel reason for successfully finishing operator (#7019) close tikv/pd#4399 Signed-off-by: Ryan Leung Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- pkg/schedule/operator/operator.go | 8 +++----- pkg/schedule/operator/operator_controller.go | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/schedule/operator/operator.go b/pkg/schedule/operator/operator.go index 755c69d00fd8..a8c54e824fb3 100644 --- a/pkg/schedule/operator/operator.go +++ b/pkg/schedule/operator/operator.go @@ -50,8 +50,6 @@ var ( AdminStop CancelReasonType = "admin stop" // NotInRunningState is the cancel reason when the operator is not in running state. NotInRunningState CancelReasonType = "not in running state" - // Succeed is the cancel reason when the operator is finished successfully. - Succeed CancelReasonType = "succeed" // Timeout is the cancel reason when the operator is timeout. Timeout CancelReasonType = "timeout" // Expired is the cancel reason when the operator is expired. @@ -265,9 +263,9 @@ func (o *Operator) CheckSuccess() bool { } // Cancel marks the operator canceled. -func (o *Operator) Cancel(reason CancelReasonType) bool { - if _, ok := o.AdditionalInfos[cancelReason]; !ok { - o.AdditionalInfos[cancelReason] = string(reason) +func (o *Operator) Cancel(reason ...CancelReasonType) bool { + if _, ok := o.AdditionalInfos[cancelReason]; !ok && len(reason) != 0 { + o.AdditionalInfos[cancelReason] = string(reason[0]) } return o.status.To(CANCELED) } diff --git a/pkg/schedule/operator/operator_controller.go b/pkg/schedule/operator/operator_controller.go index 96fa961e95e5..3e9d2f3abcbd 100644 --- a/pkg/schedule/operator/operator_controller.go +++ b/pkg/schedule/operator/operator_controller.go @@ -125,7 +125,7 @@ func (oc *Controller) Dispatch(region *core.RegionInfo, source string, recordOpS if op.ContainNonWitnessStep() { recordOpStepWithTTL(op.RegionID()) } - if oc.RemoveOperator(op, Succeed) { + if oc.RemoveOperator(op) { operatorCounter.WithLabelValues(op.Desc(), "promote-success").Inc() oc.PromoteWaitingOperator() } @@ -544,8 +544,6 @@ func (oc *Controller) RemoveOperator(op *Operator, reasons ...CancelReasonType) var cancelReason CancelReasonType if len(reasons) > 0 { cancelReason = reasons[0] - } else { - cancelReason = Unknown } if removed { if op.Cancel(cancelReason) {