mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-17 20:56:08 +00:00
Use thread safe map for cancel recorder (#10255)
* use thread safe map for cancel recorder Signed-off-by: Lyndon-Li <lyonghui@vmware.com> * use atomic load and store Signed-off-by: Lyndon-Li <lyonghui@vmware.com> --------- Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
@@ -81,7 +82,7 @@ type DataUploadReconciler struct {
|
||||
podResources corev1api.ResourceRequirements
|
||||
preparingTimeout time.Duration
|
||||
metrics *metrics.ServerMetrics
|
||||
cancelledDataUpload map[string]time.Time
|
||||
cancelledDataUpload sync.Map
|
||||
dataMovePriorityClass string
|
||||
podLabels map[string]string
|
||||
podAnnotations map[string]string
|
||||
@@ -130,7 +131,6 @@ func NewDataUploadReconciler(
|
||||
podResources: podResources,
|
||||
preparingTimeout: preparingTimeout,
|
||||
metrics: metrics,
|
||||
cancelledDataUpload: make(map[string]time.Time),
|
||||
dataMovePriorityClass: dataMovePriorityClass,
|
||||
podLabels: podLabels,
|
||||
podAnnotations: podAnnotations,
|
||||
@@ -207,7 +207,7 @@ func (r *DataUploadReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete(r.cancelledDataUpload, du.Name)
|
||||
r.cancelledDataUpload.Delete(du.Name)
|
||||
|
||||
// put the finalizer remove action here for all cr will goes to the final status, we could check finalizer and do remove action in final status
|
||||
// instead of intermediate state.
|
||||
@@ -232,9 +232,9 @@ func (r *DataUploadReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||
}
|
||||
|
||||
if du.Spec.Cancel {
|
||||
if spotted, found := r.cancelledDataUpload[du.Name]; !found {
|
||||
r.cancelledDataUpload[du.Name] = r.Clock.Now()
|
||||
} else {
|
||||
v, loaded := r.cancelledDataUpload.LoadOrStore(du.Name, r.Clock.Now())
|
||||
if loaded {
|
||||
spotted := v.(time.Time)
|
||||
delay := cancelDelayOthers
|
||||
if du.Status.Phase == velerov2alpha1api.DataUploadPhaseInProgress {
|
||||
delay = cancelDelayInProgress
|
||||
@@ -243,7 +243,7 @@ func (r *DataUploadReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||
if time.Since(spotted) > delay {
|
||||
log.Infof("Data upload %s is canceled in Phase %s but not handled in reasonable time", du.GetName(), du.Status.Phase)
|
||||
if r.tryCancelDataUpload(ctx, du, "") {
|
||||
delete(r.cancelledDataUpload, du.Name)
|
||||
r.cancelledDataUpload.Delete(du.Name)
|
||||
}
|
||||
|
||||
return ctrl.Result{}, nil
|
||||
@@ -577,7 +577,7 @@ func (r *DataUploadReconciler) OnDataUploadCancelled(ctx context.Context, namesp
|
||||
log.WithError(err).Error("error updating DataUpload status")
|
||||
} else {
|
||||
r.metrics.RegisterDataUploadCancel(r.nodeName)
|
||||
delete(r.cancelledDataUpload, du.Name)
|
||||
r.cancelledDataUpload.Delete(du.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user