From 7aa3525deb0ed2a1287c8ee32cd4308ba5eea662 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 02a2f1a8a5f..ab956d79c9e 100644 --- a/pkg/schedule/operator/operator.go +++ b/pkg/schedule/operator/operator.go @@ -49,8 +49,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. @@ -260,9 +258,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 e6845f05c91..d6b94d2996f 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() } @@ -543,8 +543,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) {