From 5b18c57a54f9799430e28d89123d37480570cfe1 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 14 May 2021 12:40:54 -0700 Subject: [PATCH] fix: for deleteBucket delete on dnsStore first (#12298) attempt a delete on remote DNS store first before attempting locally, because removing at DNS store is cheaper than deleting locally, in case of errors locally we can cheaply recreate the bucket on dnsStore instead of. --- cmd/bucket-handlers.go | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index 42ddb58be..2e19ee23e 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -1242,22 +1242,6 @@ func (api objectAPIHandlers) DeleteBucketHandler(w http.ResponseWriter, r *http. } } - deleteBucket := objectAPI.DeleteBucket - - // Attempt to delete bucket. - if err := deleteBucket(ctx, bucket, forceDelete); err != nil { - if _, ok := err.(BucketNotEmpty); ok && (globalBucketVersioningSys.Enabled(bucket) || globalBucketVersioningSys.Suspended(bucket)) { - apiErr := toAPIError(ctx, err) - apiErr.Description = "The bucket you tried to delete is not empty. You must delete all versions in the bucket." - writeErrorResponse(ctx, w, apiErr, r.URL, guessIsBrowserReq(r)) - } else { - writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) - } - return - } - - globalNotificationSys.DeleteBucketMetadata(ctx, bucket) - if globalDNSConfig != nil { if err := globalDNSConfig.Delete(bucket); err != nil { logger.LogIf(ctx, fmt.Errorf("Unable to delete bucket DNS entry %w, please delete it manually", err)) @@ -1266,6 +1250,27 @@ func (api objectAPIHandlers) DeleteBucketHandler(w http.ResponseWriter, r *http. } } + deleteBucket := objectAPI.DeleteBucket + + // Attempt to delete bucket. + if err := deleteBucket(ctx, bucket, forceDelete); err != nil { + apiErr := toAPIError(ctx, err) + if _, ok := err.(BucketNotEmpty); ok { + if globalBucketVersioningSys.Enabled(bucket) || globalBucketVersioningSys.Suspended(bucket) { + apiErr.Description = "The bucket you tried to delete is not empty. You must delete all versions in the bucket." + } + } + if globalDNSConfig != nil { + if err2 := globalDNSConfig.Put(bucket); err2 != nil { + logger.LogIf(ctx, fmt.Errorf("Unable to restore bucket DNS entry %w, pl1ease fix it manually", err2)) + } + } + writeErrorResponse(ctx, w, apiErr, r.URL, guessIsBrowserReq(r)) + return + } + + globalNotificationSys.DeleteBucketMetadata(ctx, bucket) + // Write success response. writeSuccessNoContent(w)