zentol commented on a change in pull request #18979:
URL: https://github.com/apache/flink/pull/18979#discussion_r822773571



##########
File path: 
flink-filesystems/flink-s3-fs-presto/src/main/java/org/apache/flink/fs/s3presto/FlinkS3PrestoFileSystem.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.flink.fs.s3presto;
+
+import org.apache.flink.core.fs.FileStatus;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.fs.s3.common.FlinkS3FileSystem;
+import org.apache.flink.fs.s3.common.writer.S3AccessHelper;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.hadoop.fs.FileSystem;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Optional;
+
+/**
+ * {@code FlinkS3PrestoFileSystem} provides custom recursive deletion 
functionality to work around a
+ * bug in the internally used Presto file system.
+ *
+ * <p>https://github.com/prestodb/presto/issues/17416
+ */
+public class FlinkS3PrestoFileSystem extends FlinkS3FileSystem {
+
+    public FlinkS3PrestoFileSystem(
+            FileSystem hadoopS3FileSystem,
+            String localTmpDirectory,
+            @Nullable String entropyInjectionKey,
+            int entropyLength,
+            @Nullable S3AccessHelper s3UploadHelper,
+            long s3uploadPartSize,
+            int maxConcurrentUploadsPerStream) {
+        super(
+                hadoopS3FileSystem,
+                localTmpDirectory,
+                entropyInjectionKey,
+                entropyLength,
+                s3UploadHelper,
+                s3uploadPartSize,
+                maxConcurrentUploadsPerStream);
+    }
+
+    @Override
+    public boolean delete(Path path, boolean recursive) throws IOException {
+        if (recursive) {
+            deleteRecursively(path);
+        } else {
+            deleteObject(path);
+        }
+
+        return true;
+    }
+
+    private void deleteRecursively(Path path) throws IOException {
+        final FileStatus[] containingFiles =
+                Preconditions.checkNotNull(
+                        listStatus(path),
+                        "Hadoop FileSystem.listStatus should never return null 
based on its contract.");
+
+        if (containingFiles.length == 0) {
+            deleteObject(path);
+            return;
+        }

Review comment:
       I'm again wondering why we do this.
   
   Under what circumstance can an empty directory exist when using the presto 
filesystem? Mkdirs can't cause it, and deleting the contents is supposed to 
cleanup the directory.
   (Is this actually something that happens automatically, or is that just 
caused by the FS implementation which also explicitly issues a delete call for 
the directory).




-- 
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-unsubscr...@flink.apache.org

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


Reply via email to