[ 
https://issues.apache.org/jira/browse/HADOOP-19801?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18111029#comment-18111029
 ] 

ASF GitHub Bot commented on HADOOP-19801:
-----------------------------------------

deepujain commented on code in PR #8306:
URL: https://github.com/apache/hadoop/pull/8306#discussion_r3923230016


##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/DeleteOperation.java:
##########
@@ -224,6 +253,9 @@ public Boolean execute() throws IOException {
       if (status.isEmptyDirectory() == Tristate.TRUE) {
         LOG.debug("deleting empty directory {}", path);
         deleteObjectAtPath(path, key, false);
+      } else if (deleteNonEmptyDirectoryEnabled) {
+        LOG.debug("deleting non-empty directory {} with single request 
(endpoint supports it)", path);

Review Comment:
   Addressed on the current head by splitting the long debug log line at the 
comma.



##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ADeleteNonEmptyDirectoryCapability.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.hadoop.fs.s3a;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.contract.AbstractContractDeleteTest;
+import org.apache.hadoop.fs.contract.AbstractFSContract;
+import org.apache.hadoop.fs.contract.s3a.S3AContract;
+import org.apache.hadoop.test.tags.IntegrationTest;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static 
org.apache.hadoop.fs.s3a.Constants.DELETE_NON_EMPTY_DIRECTORY_ENABLED;
+import static org.apache.hadoop.fs.s3a.S3ATestUtils.getTestBucketName;
+import static 
org.apache.hadoop.fs.s3a.S3ATestUtils.removeBaseAndBucketOverrides;
+
+/**
+ * Test that fs.s3a.delete.non-empty-directory.enabled is reflected in
+ * hasPathCapability(DELETE_NON_EMPTY_DIRECTORY_ENABLED). HADOOP-19801.
+ */
+@IntegrationTest
+public class ITestS3ADeleteNonEmptyDirectoryCapability extends
+    AbstractContractDeleteTest {

Review Comment:
   Addressed: the capability test now extends `AbstractS3ATestBase`, so the 
contract delete suite is not duplicated.



##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ADeleteNonEmptyDirectoryCapability.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.hadoop.fs.s3a;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.contract.AbstractContractDeleteTest;
+import org.apache.hadoop.fs.contract.AbstractFSContract;
+import org.apache.hadoop.fs.contract.s3a.S3AContract;
+import org.apache.hadoop.test.tags.IntegrationTest;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static 
org.apache.hadoop.fs.s3a.Constants.DELETE_NON_EMPTY_DIRECTORY_ENABLED;
+import static org.apache.hadoop.fs.s3a.S3ATestUtils.getTestBucketName;
+import static 
org.apache.hadoop.fs.s3a.S3ATestUtils.removeBaseAndBucketOverrides;
+
+/**
+ * Test that fs.s3a.delete.non-empty-directory.enabled is reflected in
+ * hasPathCapability(DELETE_NON_EMPTY_DIRECTORY_ENABLED). HADOOP-19801.
+ */
+@IntegrationTest
+public class ITestS3ADeleteNonEmptyDirectoryCapability extends
+    AbstractContractDeleteTest {
+
+  @Override
+  protected AbstractFSContract createContract(Configuration conf) {
+    return new S3AContract(conf);
+  }
+
+  /**
+   * Test that when the option is disabled (default), the capability is false.
+   */
+  @Test
+  public void testCapabilityDisabledByDefault() throws Throwable {
+    Assertions.assertThat(getFileSystem().hasPathCapability(new Path("/"),

Review Comment:
   Addressed: the tests use an isolated copy of the filesystem configuration 
and remove base and bucket overrides for this option.



##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Constants.java:
##########
@@ -1770,6 +1770,34 @@ private Constants() {
    */
   public static final boolean DIRECTORY_OPERATIONS_PURGE_UPLOADS_DEFAULT = 
false;
 
+  /**
+   * When true, recursive deletion of a non-empty directory uses a single 
delete
+   * request for the directory key (prefix) instead of listing and deleting 
contained
+   * objects first. Only enable this for S3-compatible endpoints that support
+   * deleting non-empty directories (path prefix) in one request (e.g. VAST).
+   * Value: {@value}.
+   */
+  public static final String DELETE_NON_EMPTY_DIRECTORY_ENABLED =
+      "fs.s3a.delete.non-empty-directory.enabled";
+
+  /**
+   * Custom delete header required by some S3-compatible stores to delete a
+   * non-empty directory key (prefix) in one request.
+   * Value: {@value}.
+   */
+  public static final String DELETE_NON_EMPTY_DIRECTORY_HEADER =
+      "x-amz-delete-contents";

Review Comment:
   Addressed: the proprietary hardcoded header was removed, and the generic 
request-header work was split into #8417.





> Allow to skip recursive file deletion for non-empty directory
> -------------------------------------------------------------
>
>                 Key: HADOOP-19801
>                 URL: https://issues.apache.org/jira/browse/HADOOP-19801
>             Project: Hadoop Common
>          Issue Type: New Feature
>          Components: fs/s3
>            Reporter: Enrico Minack
>            Priority: Major
>              Labels: pull-request-available
>
> A non-empty directory, as well as a directory where its emptiness is unknown, 
> is deleted by listing all contained files (or objects with matching key 
> prefix), then deleting those files (objects) in bulk delete requests, and 
> finally deleting the (then) empty directory itself.
> The recursive deletion of objects is not needed for S3 endpoints that support 
> deleting non-empty directories (or path prefixes).
> For example: The [VAST S3 endpoint supports deleting non-empty 
> directories|https://kb.vastdata.com/documentation/docs/using-trash-folder-for-s3-objects-6]
>  with a single request. Such a feature can only be fully leveraged if 
> {{hadoop-aws}} coupd skip the recursive deletion.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to