Skip to content

Commit

Permalink
Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
losipiuk committed Jun 18, 2022
1 parent bff15e3 commit ca665a8
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,7 @@ public ListenableFuture<Void> createEmptyFile(URI file)
public ListenableFuture<Void> deleteRecursively(List<URI> directories)
{
if (compatibilityMode == GCP) {
// GCS is not compatible with S3's multi-object delete API https://cloud.google.com/storage/docs/migrating#methods-comparison
Storage storage = gcsClient.orElseThrow(() -> new IllegalStateException("gcsClient is expected to be initialized"));
ListeningExecutorService deleteExecutor = gcsDeleteExecutor.orElseThrow(() -> new IllegalStateException("gcsDeleteExecutor is expected to be initialized"));
return stats.getDeleteRecursively().record(asVoid(deleteExecutor.submit(() -> {
StorageBatch batch = storage.batch();
for (URI dir : directories) {
Page<Blob> blobs = storage.list(getBucketName(dir), Storage.BlobListOption.prefix(keyFromUri(dir)));
for (Blob blob : blobs.iterateAll()) {
batch.delete(blob.getBlobId());
}
}
batch.submit();
})));
return deleteRecursivelyGcp(directories);
}

ImmutableMultimap.Builder<String, ListenableFuture<List<String>>> bucketToListObjectsFuturesBuilder = ImmutableMultimap.builder();
Expand Down Expand Up @@ -272,6 +260,23 @@ public ListenableFuture<Void> deleteRecursively(List<URI> directories)
return translateFailures(Futures.allAsList(deleteObjectsFutures.build()));
}

private ListenableFuture<Void> deleteRecursivelyGcp(List<URI> directories)
{
// GCS is not compatible with S3's multi-object delete API https://cloud.google.com/storage/docs/migrating#methods-comparison
Storage storage = gcsClient.orElseThrow(() -> new IllegalStateException("gcsClient is expected to be initialized"));
ListeningExecutorService deleteExecutor = gcsDeleteExecutor.orElseThrow(() -> new IllegalStateException("gcsDeleteExecutor is expected to be initialized"));
return stats.getDeleteRecursively().record(asVoid(deleteExecutor.submit(() -> {
StorageBatch batch = storage.batch();
for (URI dir : directories) {
Page<Blob> blobs = storage.list(getBucketName(dir), Storage.BlobListOption.prefix(keyFromUri(dir)));
for (Blob blob : blobs.iterateAll()) {
batch.delete(blob.getBlobId());
}
}
batch.submit();
})));
}

@Override
public ListenableFuture<List<FileStatus>> listFilesRecursively(URI dir)
{
Expand Down

0 comments on commit ca665a8

Please sign in to comment.