INode unprotectedDelete ( String src , INode inodes [ ] , List < BlockInfo > toBeDeletedBlocks , int blocksLimit , long modificationTime ) { src = normalizePath ( src ) ; writeLock ( ) ; try { INode targetNode = inodes [ inodes . length - 1 ] ; if ( targetNode == null ) { // non-existent src if ( NameNode . stateChangeLog . isDebugEnabled ( ) ) { NameNode . stateChangeLog . debug ( "DIR* FSDirectory.unprotectedDelete: " + "failed to remove " + src + " because it does not exist" ) ; } return null ; } else if ( inodes . length == 1 ) { // src is the root NameNode . stateChangeLog . warn ( "DIR* FSDirectory.unprotectedDelete: " + "failed to remove " + src + " because the root is not allowed to be deleted" ) ; return null ; } else { try { // Remove the node from the namespace removeChild ( inodes , inodes . length - 1 ) ; // set the parent's modification time inodes [ inodes . length - 2 ] . setModificationTime ( modificationTime ) ; // GC all the blocks underneath the node. if ( toBeDeletedBlocks == null ) { toBeDeletedBlocks = new ArrayList < BlockInfo > ( ) ; blocksLimit = BLOCK_DELETION_NO_LIMIT ; } List < INode > removedINodes = new ArrayList < INode > ( ) ; int filesRemoved = targetNode . collectSubtreeBlocksAndClear ( toBeDeletedBlocks , blocksLimit , removedINodes ) ; FSNamesystem . incrDeletedFileCount ( getFSNamesystem ( ) , filesRemoved ) ; // Delete collected blocks immediately; // Remaining blocks need to be collected and deleted later on getFSNamesystem ( ) . removePathAndBlocks ( src , toBeDeletedBlocks ) ; if ( NameNode . stateChangeLog . isDebugEnabled ( ) ) { NameNode . stateChangeLog . debug ( "DIR* FSDirectory.unprotectedDelete: " + src + " is removed" ) ; } targetNode . parent = null ; //mark the node as deleted removeFromInodeMap ( removedINodes ) ; return targetNode ; } catch ( IOException e ) { NameNode . stateChangeLog . warn ( "DIR* FSDirectory.unprotectedDelete: " + "failed to remove " + src + " because " + e . getMessage ( ) ) ; return null ; } } } finally { writeUnlock ( ) ; } }
Delete a path from the name space Update the count at each ancestor directory with quota Up to blocksLimit blocks will be put in toBeDeletedBlocks to be removed later