jackye1995 commented on code in PR #5459:
URL: https://github.com/apache/iceberg/pull/5459#discussion_r940773875


##########
core/src/main/java/org/apache/iceberg/CatalogUtil.java:
##########
@@ -151,20 +174,32 @@ private static void deleteFiles(FileIO io, 
Set<ManifestFile> allManifests) {
         .run(
             manifest -> {
               try (ManifestReader<?> reader = ManifestFiles.open(manifest, 
io)) {
+                List<String> pathsToDelete = Lists.newArrayList();
                 for (ManifestEntry<?> entry : reader.entries()) {
                   // intern the file path because the weak key map uses 
identity (==) instead of
                   // equals
                   String path = entry.file().path().toString().intern();
                   Boolean alreadyDeleted = deletedFiles.putIfAbsent(path, 
true);
                   if (alreadyDeleted == null || !alreadyDeleted) {
                     try {
-                      io.deleteFile(path);
+                      if (io instanceof SupportsBulkOperations) {
+                        pathsToDelete.add(path);
+                      } else {
+                        io.deleteFile(path);
+                      }
                     } catch (RuntimeException e) {
                       // this may happen if the map of deleted files gets 
cleaned up by gc
                       LOG.warn("Delete failed for data file: {}", path, e);
                     }
                   }
                 }
+                if (io instanceof SupportsBulkOperations) {

Review Comment:
   nit: newline after one logic block



##########
core/src/main/java/org/apache/iceberg/CatalogUtil.java:
##########
@@ -102,6 +106,25 @@ public static void dropTableData(FileIO io, TableMetadata 
metadata) {
       deleteFiles(io, manifestsToDelete);
     }
 
+    if (io instanceof SupportsBulkOperations) {
+      SupportsBulkOperations bulkFileIO = (SupportsBulkOperations) io;
+      Iterable<String> manifestPaths = Iterables.transform(manifestsToDelete, 
ManifestFile::path);
+      Iterable<String> prevMetadataFiles =
+          Iterables.transform(metadata.previousFiles(), 
TableMetadata.MetadataLogEntry::file);
+      try {
+        Iterable<String> filesToDelete =
+            Iterables.concat(
+                manifestPaths,
+                manifestListsToDelete,
+                prevMetadataFiles,
+                ImmutableList.of(metadata.metadataFileLocation()));
+        bulkFileIO.deleteFiles(filesToDelete);
+      } catch (RuntimeException e) {
+        LOG.warn("Failed to bulk delete metadata and manifest files", e);
+      }
+      return;

Review Comment:
   nit: newline after one logic block



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to