김용덕 created HADOOP-20117:
----------------------------

             Summary: FsShell rmdir --ignore-fail-on-non-empty fails when a 
directory becomes non-empty between listing and deletion
                 Key: HADOOP-20117
                 URL: https://issues.apache.org/jira/browse/HADOOP-20117
             Project: Hadoop Common
          Issue Type: Bug
          Components: fs
         Environment: Hadoop 3.6.0-SNAPSHOT
Analyzed revision: 01761fd4443
macOS aarch64
JDK 17.0.19
Maven 3.9.15
MiniDFSCluster with one DataNode
            Reporter: 김용덕


h3. Problem

The {{--ignore-fail-on-non-empty}} option does not suppress a non-empty 
directory failure when the directory becomes non-empty between {{listStatus()}} 
and {{delete(path, false)}}.

In {{Delete.Rmdir.processPath()}}, {{ignoreNonEmpty}} is checked only when the 
initial listing is non-empty. If the listing is empty, the command calls 
{{delete()}} without handling {{PathIsNotEmptyDirectoryException}}.

For HDFS, these are separate RPCs. Another client can create a child between 
them. The NameNode correctly rejects the deletion, but FsShell reports failure 
even with the ignore option enabled.

h3. Reproduction

# Create an empty directory, {{/rmdir-race}}.
# Run {{hdfs dfs -rmdir --ignore-fail-on-non-empty /rmdir-race}}.
# Pause execution after the empty listing is obtained and before {{delete()}} 
is called.
# Use another HDFS client to create and close {{/rmdir-race/child}}.
# Resume execution.

Actual: the command reports "Directory is not empty" and exits with code 1.

Expected: the non-empty directory failure is ignored, the directory and child 
remain intact, and the command exits successfully if there are no other errors.

h3. Validation

Verified against commit {{01761fd4443}} using MiniDFSCluster.

A test-only DistributedFileSystem subclass obtains the real empty listing, 
creates a child through a separate HDFS client, then returns the previously 
obtained listing to FsShell. Deletion uses the real HDFS RPC; the exception is 
not mocked.

The original and patched Delete classes were tested against identical test and 
dependency binaries. Three repeated runs produced the same results:

* Original, option enabled: exit code 1 and non-empty error.
* Patched, option enabled: exit code 0 and no error.
* Both versions, option disabled: exit code 1.
* The child file remained intact in every case.

The patched version also passed six unit tests and two MiniDFSCluster test 
cases in a fresh Maven build.

h3. Proposed fix

Catch {{PathIsNotEmptyDirectoryException}} from {{delete(path, false)}} and 
suppress it only when {{ignoreNonEmpty}} is true. Other exceptions and a false 
deletion result should continue to report failure.

No NameNode locking or RPC changes are needed.

I would like to contribute a patch and regression tests.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

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

Reply via email to