From 26f55472c6b6b92c256fb328497d8bedd294691e Mon Sep 17 00:00:00 2001 From: Poorna K Date: Tue, 2 Nov 2021 00:52:45 -0400 Subject: [PATCH] fix: clean up dangling buckets during bucket delete (#13523) --- cmd/erasure-bucket.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/cmd/erasure-bucket.go b/cmd/erasure-bucket.go index 7222ac2e7..22f451781 100644 --- a/cmd/erasure-bucket.go +++ b/cmd/erasure-bucket.go @@ -172,19 +172,25 @@ func (er erasureObjects) DeleteBucket(ctx context.Context, bucket string, opts D if err == errErasureWriteQuorum && !opts.NoRecreate { undoDeleteBucket(storageDisks, bucket) } - if err != nil { - return toObjectErr(err, bucket) - } - // At this point we have `err == nil` but some errors might be `errVolumeNotEmpty` - // we should proceed to attempt a force delete of such buckets. - for index, err := range dErrs { - if err == errVolumeNotEmpty && storageDisks[index] != nil { - storageDisks[index].RenameFile(ctx, bucket, "", minioMetaTmpDeletedBucket, mustGetUUID()) + if err == nil || errors.Is(err, errVolumeNotFound) { + var purgedDangling bool + // At this point we have `err == nil` but some errors might be `errVolumeNotEmpty` + // we should proceed to attempt a force delete of such buckets. + for index, err := range dErrs { + if err == errVolumeNotEmpty && storageDisks[index] != nil { + storageDisks[index].RenameFile(ctx, bucket, "", minioMetaTmpDeletedBucket, mustGetUUID()) + purgedDangling = true + } } + // if we purged dangling buckets, ignore errVolumeNotFound error. + if purgedDangling { + err = nil + } + } - return nil + return toObjectErr(err, bucket) } // IsNotificationSupported returns whether bucket notification is applicable for this layer.