You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/08/08 00:11:16 UTC

[GitHub] [iceberg] amogh-jahagirdar commented on a diff in pull request #5459: Core: Use Bulk Delete when dropping table data and metadata

amogh-jahagirdar commented on code in PR #5459:
URL: https://github.com/apache/iceberg/pull/5459#discussion_r939742639


##########
core/src/main/java/org/apache/iceberg/CatalogUtil.java:
##########
@@ -102,45 +106,53 @@ public static void dropTableData(FileIO io, TableMetadata metadata) {
       deleteFiles(io, manifestsToDelete);
     }
 
-    Tasks.foreach(Iterables.transform(manifestsToDelete, ManifestFile::path))
-        .executeWith(ThreadPools.getWorkerPool())
-        .noRetry()
-        .suppressFailureWhenFinished()
-        .onFailure((manifest, exc) -> LOG.warn("Delete failed for manifest: {}", manifest, exc))
-        .run(io::deleteFile);
-
-    Tasks.foreach(manifestListsToDelete)
-        .executeWith(ThreadPools.getWorkerPool())
-        .noRetry()
-        .suppressFailureWhenFinished()
-        .onFailure((list, exc) -> LOG.warn("Delete failed for manifest list: {}", list, exc))
-        .run(io::deleteFile);
-
-    Tasks.foreach(
-            Iterables.transform(metadata.previousFiles(), TableMetadata.MetadataLogEntry::file))
-        .executeWith(ThreadPools.getWorkerPool())
-        .noRetry()
-        .suppressFailureWhenFinished()
-        .onFailure(
-            (metadataFile, exc) ->
-                LOG.warn("Delete failed for previous metadata file: {}", metadataFile, exc))
-        .run(io::deleteFile);
-
-    Tasks.foreach(metadata.metadataFileLocation())
-        .noRetry()
-        .suppressFailureWhenFinished()
-        .onFailure(
-            (metadataFile, exc) ->
-                LOG.warn("Delete failed for metadata file: {}", metadataFile, exc))
-        .run(io::deleteFile);
+    if (io instanceof SupportsBulkOperations) {
+      SupportsBulkOperations bulkFileIO = (SupportsBulkOperations) io;
+      bulkFileIO.deleteFiles(Iterables.transform(manifestsToDelete, ManifestFile::path));
+      bulkFileIO.deleteFiles(manifestListsToDelete);
+      bulkFileIO.deleteFiles(
+          Iterables.transform(metadata.previousFiles(), TableMetadata.MetadataLogEntry::file));
+      bulkFileIO.deleteFiles(ImmutableList.of(metadata.metadataFileLocation()));
+    } else {
+      Tasks.foreach(Iterables.transform(manifestsToDelete, ManifestFile::path))
+          .executeWith(ThreadPools.getWorkerPool())
+          .noRetry()
+          .suppressFailureWhenFinished()
+          .onFailure((manifest, exc) -> LOG.warn("Delete failed for manifest: {}", manifest, exc))
+          .run(io::deleteFile);
+
+      Tasks.foreach(manifestListsToDelete)
+          .executeWith(ThreadPools.getWorkerPool())
+          .noRetry()
+          .suppressFailureWhenFinished()
+          .onFailure((list, exc) -> LOG.warn("Delete failed for manifest list: {}", list, exc))
+          .run(io::deleteFile);
+
+      Tasks.foreach(
+              Iterables.transform(metadata.previousFiles(), TableMetadata.MetadataLogEntry::file))
+          .executeWith(ThreadPools.getWorkerPool())
+          .noRetry()
+          .suppressFailureWhenFinished()
+          .onFailure(
+              (metadataFile, exc) ->
+                  LOG.warn("Delete failed for previous metadata file: {}", metadataFile, exc))
+          .run(io::deleteFile);
+
+      Tasks.foreach(metadata.metadataFileLocation())
+          .noRetry()
+          .suppressFailureWhenFinished()
+          .onFailure(
+              (metadataFile, exc) ->
+                  LOG.warn("Delete failed for metadata file: {}", metadataFile, exc))
+          .run(io::deleteFile);
+    }
   }
 
   @SuppressWarnings("DangerousStringInternUsage")
   private static void deleteFiles(FileIO io, Set<ManifestFile> allManifests) {
     // keep track of deleted files in a map that can be cleaned up when memory runs low
     Map<String, Boolean> deletedFiles =
         new MapMaker().concurrencyLevel(ThreadPools.WORKER_THREAD_POOL_SIZE).weakKeys().makeMap();
-

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org