Skip to content

Commit

Permalink
*: clean up code
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <[email protected]>
  • Loading branch information
BornChanger committed Jan 3, 2024
1 parent 760b3e9 commit 995932c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/backup-manager/app/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (bo *Options) deleteVolumeSnapshots(meta *bkutil.EBSBasedBRMeta) error {
return err
}
if err = ec2Session.DeleteSnapshots(newVolumeIDMap); err != nil {
klog.Errorf("delete snapshot failure.")
klog.Errorf("delete snapshots failure.")
return err
}

Expand Down
14 changes: 1 addition & 13 deletions pkg/backup/util/aws_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"context"
"os"
"strings"
"sync"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -32,7 +31,6 @@ import (
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/backup/constants"
"go.uber.org/atomic"
"go.uber.org/multierr"
"golang.org/x/sync/errgroup"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -148,8 +146,6 @@ func NewEC2Session(concurrency uint) (*EC2Session, error) {
func (e *EC2Session) DeleteSnapshots(snapIDMap map[string]string) error {
var (
deletedCnt atomic.Int32
errs error
lock sync.Mutex
)

eg, _ := errgroup.WithContext(context.Background())
Expand Down Expand Up @@ -187,23 +183,15 @@ func (e *EC2Session) DeleteSnapshots(snapIDMap map[string]string) error {
err := retry.OnError(backoff, isRetry, delSnapshots)
if err != nil {
klog.Errorf("failed to delete snapshot id=%s, error=%s", snapID, err.Error())
lock.Lock()
defer lock.Unlock()
errs = multierr.Combine(errs, err)
}

return errs
return err
})
}

if err := eg.Wait(); err != nil {
klog.Errorf("failed to delete snapshots error=%s, already delete=%d", err, deletedCnt.Load())
return err
}

if errs != nil {
return errs
}
return nil
}

Expand Down

0 comments on commit 995932c

Please sign in to comment.