Skip to content

Commit

Permalink
dm: delete file ignore blob file not exist (#11913)
Browse files Browse the repository at this point in the history
close #11912
  • Loading branch information
River2000i authored Dec 20, 2024
1 parent fa598ba commit 086c93d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions dm/pkg/storage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"strings"

gstorage "cloud.google.com/go/storage"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/pingcap/errors"
backuppb "github.com/pingcap/kvproto/pkg/brpb"
bstorage "github.com/pingcap/tidb/br/pkg/storage"
)

Expand Down Expand Up @@ -133,25 +135,36 @@ func CollectDirFiles(ctx context.Context, dir string, storage bstorage.ExternalS
// RemoveAll remove files in dir.
func RemoveAll(ctx context.Context, dir string, storage bstorage.ExternalStorage) error {
var err error
var backend *backuppb.StorageBackend
if storage == nil {
storage, err = CreateStorage(ctx, dir)
if err != nil {
return err
}
backend, err = bstorage.ParseBackend(dir, nil)
if err != nil {
return err
}
}

err = storage.WalkDir(ctx, &bstorage.WalkOption{}, func(filePath string, size int64) error {
err2 := storage.DeleteFile(ctx, filePath)
if errors.Cause(err2) == gstorage.ErrObjectNotExist {
// ignore not exist error when we delete files
// ignore not exist error when we delete files and backend is gcs/azure blob storage
if backend != nil && backend.GetGcs() != nil && errors.Cause(err2) == gstorage.ErrObjectNotExist {
return nil
}
if backend != nil && backend.GetAzureBlobStorage() != nil && bloberror.HasCode(err2, bloberror.BlobNotFound) {
return nil
}
return err2
})
if err == nil {
err = storage.DeleteFile(ctx, "")
if errors.Cause(err) == gstorage.ErrObjectNotExist {
// ignore not exist error when we delete files
// ignore not exist error when we delete files and backend is gcs/azure blob storage
if backend != nil && backend.GetGcs() != nil && errors.Cause(err) == gstorage.ErrObjectNotExist {
return nil
}
if backend != nil && backend.GetAzureBlobStorage() != nil && bloberror.HasCode(err, bloberror.BlobNotFound) {
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23

require (
cloud.google.com/go/storage v1.39.1
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/IBM/sarama v1.41.2
Expand Down Expand Up @@ -129,7 +130,6 @@ require (

require (
cloud.google.com/go/kms v1.15.8 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
Expand Down

0 comments on commit 086c93d

Please sign in to comment.