Skip to content

Commit

Permalink
Update S3BlobStoreDAO to ignore NoSuchBucketException when deleting b…
Browse files Browse the repository at this point in the history
…lobs or bucket (linagora#2453)

Co-authored-by: hung phan <hphan@linagora.com>
  • Loading branch information
hungphan227 and hung phan authored Oct 16, 2024
1 parent e2ee7f2 commit 81674bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ default void deleteShouldNotThrowWhenBucketDoesNotExist() {
.doesNotThrowAnyException();
}

@Test
default void deleteBlobsShouldNotThrowWhenBucketDoesNotExist() {
BlobStoreDAO store = testee();

assertThatCode(() -> Mono.from(store.delete(TEST_BUCKET_NAME, ImmutableList.of(TEST_BLOB_ID, OTHER_TEST_BLOB_ID))).block())
.doesNotThrowAnyException();
}

@Test
default void deleteShouldDeleteExistingBlobData() {
BlobStoreDAO store = testee();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;
Expand Down Expand Up @@ -313,7 +314,8 @@ public Publisher<Void> delete(BucketName bucketName, Collection<BlobId> blobIds)
.map(BlobId::asString)
.map(id -> ObjectIdentifier.builder().key(id).build())
.collect(ImmutableList.toImmutableList()))
.then();
.then()
.onErrorResume(NoSuchBucketException.class, e -> Mono.empty());
}

@Override
Expand All @@ -325,10 +327,10 @@ public Mono<Void> deleteBucket(BucketName bucketName) {

private Mono<Void> deleteResolvedBucket(BucketName bucketName) {
return emptyBucket(bucketName)
.onErrorResume(t -> Mono.just(bucketName))
.onErrorResume(throwable -> throwable instanceof CompletionException && throwable.getCause() instanceof NoSuchBucketException, t -> Mono.just(bucketName))
.flatMap(ignore -> Mono.fromFuture(() ->
client.deleteBucket(builder -> builder.bucket(bucketName.asString()))))
.onErrorResume(t -> Mono.empty())
.onErrorResume(NoSuchBucketException.class, t -> Mono.empty())
.then()
.publishOn(Schedulers.parallel());
}
Expand Down

0 comments on commit 81674bb

Please sign in to comment.