jerryshao commented on code in PR #14951:
URL: https://github.com/apache/gravitino/pull/14951#discussion_r4550465692


##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/cleanup/IcebergCleanupManager.java:
##########
@@ -231,25 +233,25 @@ void deleteAll(FileIO io, Iterable<String> files) {
     List<Future<?>> futures = new ArrayList<>();
     Iterators.partition(files.iterator(), deleteBatchSize)
         .forEachRemaining(
-            batch ->
-                futures.add(
-                    deleteExecutor.submit(
-                        () -> CatalogUtil.deleteFiles(io, batch, "cleanup", 
true))));
+            batch -> futures.add(deleteExecutor.submit(() -> deleteBatch(io, 
batch))));
 
-    for (Future<?> future : futures) {
-      try {
-        future.get();
-      } catch (InterruptedException e) {
-        Thread.currentThread().interrupt();
-        throw new RuntimeException("Interrupted during bulk delete", e);
-      } catch (ExecutionException e) {
-        if 
(Throwables.getCausalChain(e).stream().anyMatch(NotFoundException.class::isInstance))
 {
-          LOG.debug("Ignoring already-deleted file during async cleanup", e);
-          continue;
-        }
-        throw new RuntimeException("Bulk delete batch failed", e);
-      }
-    }
+    // Drain every submitted batch before propagating a failure so runJob 
cannot close the FileIO
+    // while another batch is still deleting files.
+    Tasks.foreach(futures)
+        .noRetry()
+        .throwFailureWhenFinished()
+        .run(
+            future -> {
+              try {
+                future.get();
+              } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();

Review Comment:
   If the thread is interrupted, the remaining future.get calls fail 
immediately, so the 'drain every batch' guarantee no longer holds and FileIO 
could be closed while batches still run. Consider documenting this or 
cancelling the remaining futures explicitly in that case.



-- 
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]

Reply via email to