Class FSTreeTraverser
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.FSTreeTraverser
FSTreeTraverser traverse directory recursively and process files
in batches.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass will represent the additional info required for traverse. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleancanTraverseDir(INode inode) Check whether dir is traversable or not.protected abstract voidcheckINodeReady(long startId) Check whether inode is ready for traverse.protected abstract voidprotected abstract booleanprocessFileInode(INode inode, FSTreeTraverser.TraverseInfo traverseInfo) Process an Inode.protected voidreadLock()protected voidprotected abstract booleanCheck whether current batch can be submitted for the processing.protected abstract voidsubmitCurrentBatch(Long startId) Submit the current batch for processing.protected abstract voidthrottle()Throttles the FSTreeTraverser.protected voidtraverseDir(INodeDirectory parent, long startId, byte[] startAfter, FSTreeTraverser.TraverseInfo traverseInfo) Iterate through all files directly inside parent, and recurse down directories.protected INodetraverseDirInt(long startId, INode curr, List<byte[]> startAfters, FSTreeTraverser.TraverseInfo traverseInfo) Iterates the parent directory, and add direct children files to current batch.
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG
-
-
Constructor Details
-
FSTreeTraverser
-
-
Method Details
-
getFSDirectory
-
traverseDir
protected void traverseDir(INodeDirectory parent, long startId, byte[] startAfter, FSTreeTraverser.TraverseInfo traverseInfo) throws IOException, InterruptedException Iterate through all files directly inside parent, and recurse down directories. The listing is done in batch, and can optionally start after a position. The iteration of the inode tree is done in a depth-first fashion. But instead of holding allINodeDirectory's in memory on the fly, only the path components to the current inode is held. This is to reduce memory consumption.- Parameters:
parent- The inode id of parent directorystartId- Id of the start inode.startAfter- Full path of a file the traverse should start after.traverseInfo- info which may required for processing the child's.- Throws:
IOExceptionInterruptedException
-
traverseDirInt
protected INode traverseDirInt(long startId, INode curr, List<byte[]> startAfters, FSTreeTraverser.TraverseInfo traverseInfo) throws IOException, InterruptedException Iterates the parent directory, and add direct children files to current batch. If batch size meets configured threshold, current batch will be submitted for the processing.Locks could be released and reacquired when a batch submission is finished.
- Parameters:
startId- Id of the start inode.- Returns:
- The inode which was just processed, if lock is held in the entire process. Null if lock is released.
- Throws:
IOExceptionInterruptedException
-
readLock
protected void readLock() -
readUnlock
protected void readUnlock() -
checkPauseForTesting
- Throws:
InterruptedException
-
processFileInode
protected abstract boolean processFileInode(INode inode, FSTreeTraverser.TraverseInfo traverseInfo) throws IOException, InterruptedException Process an Inode. Add to current batch if it's a file, no-op otherwise.- Parameters:
inode- the inode- Returns:
- true if inode is added to currentBatch and should be process for next operation. false otherwise: could be inode is not a file.
- Throws:
IOExceptionInterruptedException
-
shouldSubmitCurrentBatch
protected abstract boolean shouldSubmitCurrentBatch()Check whether current batch can be submitted for the processing.- Returns:
- true if batch size meets the condition, otherwise false.
-
checkINodeReady
Check whether inode is ready for traverse. Throws IOE if it's not.- Parameters:
startId- Id of the start inode.- Throws:
IOException
-
submitCurrentBatch
Submit the current batch for processing.- Parameters:
startId- Id of the start inode.- Throws:
IOExceptionInterruptedException
-
throttle
Throttles the FSTreeTraverser.- Throws:
InterruptedException
-
canTraverseDir
Check whether dir is traversable or not.- Parameters:
inode- Dir inode- Returns:
- true if dir is traversable otherwise false.
- Throws:
IOException
-