maobaolong commented on pull request #2437:
URL: https://github.com/apache/hadoop/pull/2437#issuecomment-722182138


   Thanks @ferhui @Hexiaoqiao for your review. I have did some debug for your 
question.
   
   > This case is same as delete one directory without any children files or 
all files are empty?
   
   remove a empty dir, `toRemovedBlocks` isn't `null`, its toDeleteList size is 
0.
   
   
![image](https://user-images.githubusercontent.com/17329931/98206403-cb281080-1f74-11eb-8828-4ae257b508dc.png)
   
   > when will return null?
   
   Through this screenshot, we can find that if `fileRemoved = -1`, then 
`toRemovedBlocks = null`
   
![image](https://user-images.githubusercontent.com/17329931/98206697-4db0d000-1f75-11eb-81c2-2ca544913f8e.png)
   
   
   And when `deleteAllowed(iip)` return false,  fileRemoved can be `-1`,
   
   ```java
     private static boolean deleteAllowed(final INodesInPath iip) {
       if (iip.length() < 1 || iip.getLastINode() == null) {
         if (NameNode.stateChangeLog.isDebugEnabled()) {
           NameNode.stateChangeLog.debug(
               "DIR* FSDirectory.unprotectedDelete: failed to remove "
                   + iip.getPath() + " because it does not exist");
         }
         return false;
       } else if (iip.length() == 1) { // src is the root
         NameNode.stateChangeLog.warn(
             "DIR* FSDirectory.unprotectedDelete: failed to remove " +
                 iip.getPath() + " because the root is not allowed to be 
deleted");
         return false;
       }
       return true;
     }
   ```
   
   Through the code of `deleteAllowed`, we can find that when src is the root, 
it can return false.
   
   So without this PR, when I execute `bin/hdfs dfs -rm  -r /`
   
   I find the confusing auditlog line like following
   
   ```
   2020-11-05 14:32:53,420 INFO  FSNamesystem.audit 
(FSNamesystem.java:logAuditMessage(8102)) - allowed=true    ugi=mbl 
(auth:SIMPLE)   ip=/127.0.0.1   cmd=delete      src=/   dst=null        
perm=null       proto=rpc
   ```
   
   
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to