flyrain commented on code in PR #516: URL: https://github.com/apache/polaris/pull/516#discussion_r1941668187
########## 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: I agreed that leveraging object-storage batch requests would be a nice improvement. There are alternative ways as well. I'd consider a followup PR for that. With that, it isn't a blocker for this PR. WDYT? -- 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]
