From ca665a8e023184e76372c62139af9e0764fb928e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Osipiuk?= Date: Fri, 10 Jun 2022 15:06:10 +0200 Subject: [PATCH] Extract method --- .../s3/S3FileSystemExchangeStorage.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/plugin/trino-exchange-filesystem/src/main/java/io/trino/plugin/exchange/filesystem/s3/S3FileSystemExchangeStorage.java b/plugin/trino-exchange-filesystem/src/main/java/io/trino/plugin/exchange/filesystem/s3/S3FileSystemExchangeStorage.java index 65507ff7c69d..e7a33bb6335f 100644 --- a/plugin/trino-exchange-filesystem/src/main/java/io/trino/plugin/exchange/filesystem/s3/S3FileSystemExchangeStorage.java +++ b/plugin/trino-exchange-filesystem/src/main/java/io/trino/plugin/exchange/filesystem/s3/S3FileSystemExchangeStorage.java @@ -229,19 +229,7 @@ public ListenableFuture createEmptyFile(URI file) public ListenableFuture deleteRecursively(List 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 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>> bucketToListObjectsFuturesBuilder = ImmutableMultimap.builder(); @@ -272,6 +260,23 @@ public ListenableFuture deleteRecursively(List directories) return translateFailures(Futures.allAsList(deleteObjectsFutures.build())); } + private ListenableFuture deleteRecursivelyGcp(List 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 blobs = storage.list(getBucketName(dir), Storage.BlobListOption.prefix(keyFromUri(dir))); + for (Blob blob : blobs.iterateAll()) { + batch.delete(blob.getBlobId()); + } + } + batch.submit(); + }))); + } + @Override public ListenableFuture> listFilesRecursively(URI dir) {