danielhumanmod commented on code in PR #516:
URL: https://github.com/apache/polaris/pull/516#discussion_r1929657255


##########
polaris-service/src/main/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandler.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.task;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.function.Function;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.io.FileIO;
+import org.apache.polaris.core.entity.AsyncTaskType;
+import org.apache.polaris.core.entity.TaskEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link BatchFileCleanupTaskHandler} responsible for batch file cleanup by 
processing multiple
+ * file deletions in a single task handler. Valid files are deleted 
asynchronously with retries for
+ * transient errors, while missing files are logged and skipped.
+ */
+public class BatchFileCleanupTaskHandler extends FileCleanupTaskHandler {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(BatchFileCleanupTaskHandler.class);
+
+  public BatchFileCleanupTaskHandler(
+      Function<TaskEntity, FileIO> fileIOSupplier, ExecutorService 
executorService) {
+    super(fileIOSupplier, executorService);
+  }
+
+  @Override
+  public boolean canHandleTask(TaskEntity task) {
+    return task.getTaskType() == AsyncTaskType.BATCH_FILE_CLEANUP;
+  }
+
+  @Override
+  public boolean handleTask(TaskEntity task) {
+    BatchFileCleanupTask cleanupTask = 
task.readData(BatchFileCleanupTask.class);
+    TableIdentifier tableId = cleanupTask.tableId();
+    List<String> batchFiles = cleanupTask.batchFiles();
+    try (FileIO authorizedFileIO = fileIOSupplier.apply(task)) {
+      List<String> validFiles =
+          batchFiles.stream().filter(file -> TaskUtils.exists(file, 
authorizedFileIO)).toList();

Review Comment:
   > Here and in line 69 are exists-checks performed for each individual file, 
which is inefficient (slow) and also incurs unnecessary cost for cloud object 
storages.
   > 
   > I'd prefer an approach that a) leverages object-storage batch requests b) 
does not perform the same operation more than once
   
   Thanks for the suggestion @snazy , which is a good point! However, our 
current deletion operation rely on Iceberg's 
[`FileIO`](https://github.com/apache/iceberg/blob/main/api/src/main/java/org/apache/iceberg/io/FileIO.java)
 interface, which does not support batch operation for now. Would you be okay 
with keeping this implementation for now, and refine it once `FileIO` add batch 
support? (We could also consider contributing this feature to Iceberg as well)



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