This is an automated email from the ASF dual-hosted git repository.
mthakur pushed a commit to branch branch-3.4
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.4 by this push:
new 5693cc69b8a HADOOP-19196. Allow base path to be deleted as well using
Bulk Delete. (#6872)
5693cc69b8a is described below
commit 5693cc69b8ad50e40744213deb5c0447443570e2
Author: Mukund Thakur <[email protected]>
AuthorDate: Tue Jun 11 14:06:53 2024 -0500
HADOOP-19196. Allow base path to be deleted as well using Bulk Delete.
(#6872)
Contributed by: Mukund Thakur
---
.../src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java | 8 ++++----
.../hadoop-common/src/site/markdown/filesystem/bulkdelete.md | 1 +
.../hadoop/fs/contract/AbstractContractBulkDeleteTest.java | 12 ++++++++++++
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java
index d9916429425..23f6e631576 100644
---
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java
+++
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java
@@ -48,14 +48,14 @@ public final class BulkDeleteUtils {
}
/**
- * Check if a path is under a base path.
+ * Check if a given path is the base path or under the base path.
* @param p path to check.
* @param basePath base path.
- * @return true if the path is under the base path.
+ * @return true if the given path is the base path or under the base path.
*/
public static boolean validatePathIsUnderParent(Path p, Path basePath) {
- while (p.getParent() != null) {
- if (p.getParent().equals(basePath)) {
+ while (p != null) {
+ if (p.equals(basePath)) {
return true;
}
p = p.getParent();
diff --git
a/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/bulkdelete.md
b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/bulkdelete.md
index de0e4e893ba..14048da43a3 100644
---
a/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/bulkdelete.md
+++
b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/bulkdelete.md
@@ -23,6 +23,7 @@ in an object store or filesystem.
* An API for submitting a list of paths to delete.
* This list must be no larger than the "page size" supported by the client;
This size is also exposed as a method.
+* This list must not have any path outside the base path.
* Triggers a request to delete files at the specific paths.
* Returns a list of which paths were reported as delete failures by the store.
* Does not consider a nonexistent file to be a failure.
diff --git
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractBulkDeleteTest.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractBulkDeleteTest.java
index 1413e74a7e0..daeb9d48088 100644
---
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractBulkDeleteTest.java
+++
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractBulkDeleteTest.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.fs.contract;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -167,6 +168,17 @@ public abstract class AbstractContractBulkDeleteTest
extends AbstractFSContractT
() -> bulkDelete_delete(getFileSystem(), basePath, paths));
}
+ /**
+ * We should be able to delete the base path itself
+ * using bulk delete operation.
+ */
+ @Test
+ public void testDeletePathSameAsBasePath() throws Exception {
+ assertSuccessfulBulkDelete(bulkDelete_delete(getFileSystem(),
+ basePath,
+ Arrays.asList(basePath)));
+ }
+
/**
* This test should fail as path is not absolute.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]