Class INodeDirectory
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.INode
org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields
org.apache.hadoop.hdfs.server.namenode.INodeDirectory
- All Implemented Interfaces:
Comparable<byte[]>,INodeAttributes,INodeDirectoryAttributes,Diff.Element<byte[]>,org.apache.hadoop.util.LightWeightGSet.LinkedElement
- Direct Known Subclasses:
Snapshot.Root
Directory INode class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA pair of Snapshot and INode objects.Nested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.namenode.INode
INode.BlocksMapUpdateInfo, INode.Feature, INode.QuotaDelta, INode.ReclaimContextNested classes/interfaces inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeAttributes
INodeAttributes.SnapshotCopyNested classes/interfaces inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes
INodeDirectoryAttributes.CopyWithQuota, INodeDirectoryAttributes.SnapshotCopy -
Field Summary
FieldsFields inherited from class org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields
features -
Constructor Summary
ConstructorsConstructorDescriptionINodeDirectory(long id, byte[] name, org.apache.hadoop.fs.permission.PermissionStatus permissions, long mtime) constructorINodeDirectory(INodeDirectory other, boolean adopt, INode.Feature... featuresToCopy) Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(NamespaceVisitor visitor, int snapshot) Accept a visitor to visit thisINode.booleanbooleanAdd a child inode to the directory.booleanaddChildAtLoading(INode node) During image loading, the search is unnecessary since the insert position should always be at the end of the map given the sequence they are serialized on disk.addSnapshot(SnapshotManager snapshotManager, String name, LeaseManager leaseManager, long mtime) Add a snapshot.voidadd DirectorySnapshottableFeaturevoidaddSpaceConsumed(QuotaCounts counts) Check and add namespace/storagespace/storagetype consumed to itself and the ancestors.final INodeDirectoryCast this inode to anINodeDirectory.voidcleanSubtree(INode.ReclaimContext reclaimContext, int snapshotId, int priorSnapshotId) Clean the subtree under this inode and collect the blocks from the descents for further block deletion/update.voidcleanSubtreeRecursively(INode.ReclaimContext reclaimContext, int snapshot, int prior, Map<INode, INode> excludedNodes) Call cleanSubtree(..) recursively down the subtree.voidclear()Clear references to other objects.voidSet the children list to null.computeContentSummary(int snapshotId, ContentSummaryComputationContext summary) Count subtree content summary with aContentCounts.protected ContentSummaryComputationContextcomputeDirectoryContentSummary(ContentSummaryComputationContext summary, int snapshotId) computeQuotaUsage(BlockStoragePolicySuite bsps, byte blockStoragePolicyId, boolean useCache, int lastSnapshotId) Count subtreeQuota.NAMESPACEandQuota.STORAGESPACEusages.computeQuotaUsage4CurrentDirectory(BlockStoragePolicySuite bsps, byte storagePolicyId, QuotaCounts counts) Add quota usage for this inode excluding children.voiddestroyAndCollectBlocks(INode.ReclaimContext reclaimContext) Destroy self and clear everything!voiddumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshot) Dump tree recursively.static voiddumpTreeRecursively(PrintWriter out, StringBuilder prefix, Iterable<INodeDirectory.SnapshotAndINode> subs) Dump the given subtrees.getChild(byte[] name, int snapshotId) getChildrenList(int snapshotId) final intgetChildrenNum(int snapshotId) getDiffs()If the directory contains aDirectoryWithQuotaFeature, return it; otherwise, return null.If feature list contains aDirectoryWithSnapshotFeature, return it; otherwise, return null.byteGet the quota set for this inodegetSnapshot(byte[] snapshotName) getSnapshotINode(int snapshotId) bytebooleanisDescendantOfSnapshotRoot(INodeDirectory snapshotRootDir) Check if this directory is a descendant directory of a snapshot root directory.final booleanCheck whether it's a directorybooleanfinal booleanIs this file has the snapshot feature?booleanCompare the metadata with another INodeDirectoryvoidrecordModification(int latestSnapshotId) booleanremoveChild(INode child) Remove the specified child from this directory.booleanremoveChild(INode child, int latestSnapshotId) Remove the specified child from this directory.removeSnapshot(INode.ReclaimContext reclaimContext, String snapshotName, long mtime, SnapshotManager snapshotManager) Delete a snapshot.voidremove DirectorySnapshottableFeaturevoidrenameSnapshot(String path, String oldName, String newName, long mtime) Rename a snapshot.voidreplaceChild(INode oldChild, INode newChild, INodeMap inodeMap) Replace the given child with a new child.saveChild2Snapshot(INode child, int latestSnapshotId, INode snapshotCopy) Save the child to the latest snapshot.intsearchChild(INode inode) Search for the given INode in the children list and the deleted lists of snapshots.voidsetSnapshotQuota(int snapshotQuota) voidundoRename4DstParent(BlockStoragePolicySuite bsps, INode deletedChild, int latestSnapshotId) Undo the rename operation for the dst tree, i.e., if the rename operation (with OVERWRITE option) removes a file/dir from the dst tree, add it back and delete possible record in the deleted list.voidundoRename4ScrParent(INodeReference oldChild, INode newChild) This method is usually called by the undo section of rename.static INodeDirectoryCast INode to INodeDirectory.Methods inherited from class org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields
addAclFeature, addFeature, addXAttrFeature, getAclFeature, getFeature, getFeatures, getFsPermissionShort, getId, getLocalNameBytes, getNext, getPermissionLong, getPermissionStatus, removeAclFeature, removeFeature, removeXAttrFeature, setAccessTime, setLocalName, setModificationTime, setNext, updateModificationTimeMethods inherited from class org.apache.hadoop.hdfs.server.namenode.INode
asFile, asReference, asSymlink, compareTo, computeAndConvertContentSummary, computeContentSummary, computeQuotaUsage, computeQuotaUsage, dumpINode, dumpParentINodes, dumpTreeRecursively, dumpTreeRecursively, equals, getAccessTime, getAclFeature, getFsPermission, getFullPathAndObjectString, getFullPathName, getGroupName, getKey, getLocalName, getModificationTime, getObjectString, getParent, getParentReference, getParentString, getPathComponents, getPathComponents, getPathNames, getStoragePolicyIDForQuota, getUserName, getXAttrFeature, hashCode, isAncestorDirectory, isDeleted, isFile, isInCurrentState, isInLatestSnapshot, isLastReference, isQuotaSet, isReference, isSetStoragePolicy, isSymlink, setAccessTime, setModificationTime, setParent, setParentReference, shouldRecordInSrcSnapshot, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeAttributes
getAccessTime, getAclFeature, getFsPermission, getFsPermissionShort, getGroupName, getLocalNameBytes, getModificationTime, getPermissionLong, getUserName, getXAttrFeature
-
Field Details
-
DEFAULT_FILES_PER_DIRECTORY
public static final int DEFAULT_FILES_PER_DIRECTORY- See Also:
-
-
Constructor Details
-
INodeDirectory
public INodeDirectory(long id, byte[] name, org.apache.hadoop.fs.permission.PermissionStatus permissions, long mtime) constructor -
INodeDirectory
Copy constructor- Parameters:
other- The INodeDirectory to be copiedadopt- Indicate whether or not need to set the parent field of child INodes to the new nodefeaturesToCopy- any number of features to copy to the new node. The method will do a reference copy, not a deep copy.
-
-
Method Details
-
valueOf
public static INodeDirectory valueOf(INode inode, Object path) throws FileNotFoundException, org.apache.hadoop.fs.PathIsNotDirectoryException Cast INode to INodeDirectory.- Throws:
FileNotFoundExceptionorg.apache.hadoop.fs.PathIsNotDirectoryException
-
isDirectory
public final boolean isDirectory()Description copied from class:INodeCheck whether it's a directory- Specified by:
isDirectoryin interfaceINodeAttributes- Overrides:
isDirectoryin classINode- Returns:
- true unconditionally.
-
asDirectory
Description copied from class:INodeCast this inode to anINodeDirectory.- Overrides:
asDirectoryin classINode- Returns:
- this object.
-
getLocalStoragePolicyID
public byte getLocalStoragePolicyID()- Specified by:
getLocalStoragePolicyIDin classINode- Returns:
- the storage policy directly specified on the INode. Return
HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIEDif no policy has been specified.
-
getStoragePolicyID
public byte getStoragePolicyID()- Specified by:
getStoragePolicyIDin classINode- Returns:
- the latest block storage policy id of the INode. Specifically, if a storage policy is directly specified on the INode then return the ID of that policy. Otherwise follow the latest parental path and return the ID of the first specified storage policy.
-
getQuotaCounts
Description copied from class:INodeGet the quota set for this inode- Specified by:
getQuotaCountsin interfaceINodeDirectoryAttributes- Overrides:
getQuotaCountsin classINode- Returns:
- the quota counts. The count is -1 if it is not set.
-
addSpaceConsumed
Description copied from class:INodeCheck and add namespace/storagespace/storagetype consumed to itself and the ancestors.- Overrides:
addSpaceConsumedin classINode
-
getDirectoryWithQuotaFeature
If the directory contains aDirectoryWithQuotaFeature, return it; otherwise, return null. -
addSnapshotFeature
public DirectoryWithSnapshotFeature addSnapshotFeature(DirectoryWithSnapshotFeature.DirectoryDiffList diffs) -
getDirectoryWithSnapshotFeature
If feature list contains aDirectoryWithSnapshotFeature, return it; otherwise, return null. -
isWithSnapshot
public final boolean isWithSnapshot()Is this file has the snapshot feature? -
getDiffs
-
getSnapshotINode
- Overrides:
getSnapshotINodein classINode- Returns:
- if the given snapshot id is
Snapshot.CURRENT_STATE_ID, return this; otherwise return the corresponding snapshot inode.
-
toDetailString
- Overrides:
toDetailStringin classINode
-
getDirectorySnapshottableFeature
-
isSnapshottable
public boolean isSnapshottable() -
isDescendantOfSnapshotRoot
Check if this directory is a descendant directory of a snapshot root directory.- Parameters:
snapshotRootDir- the snapshot root directory- Returns:
- true if this directory is a descendant of snapshot root
-
getSnapshot
-
setSnapshotQuota
public void setSnapshotQuota(int snapshotQuota) -
addSnapshot
public Snapshot addSnapshot(SnapshotManager snapshotManager, String name, LeaseManager leaseManager, long mtime) throws SnapshotException Add a snapshot.- Parameters:
name- Name of the snapshot.mtime- The snapshot creation time set by Time.now().- Throws:
SnapshotException
-
removeSnapshot
public Snapshot removeSnapshot(INode.ReclaimContext reclaimContext, String snapshotName, long mtime, SnapshotManager snapshotManager) throws SnapshotException Delete a snapshot.- Parameters:
snapshotName- Name of the snapshot.mtime- The snapshot deletion time set by Time.now().- Throws:
SnapshotException
-
renameSnapshot
public void renameSnapshot(String path, String oldName, String newName, long mtime) throws SnapshotException Rename a snapshot.- Parameters:
path- The directory path where the snapshot was taken.oldName- Old name of the snapshotnewName- New name the snapshot will be renamed tomtime- The snapshot modification time set by Time.now().- Throws:
SnapshotException
-
addSnapshottableFeature
public void addSnapshottableFeature()add DirectorySnapshottableFeature -
removeSnapshottableFeature
public void removeSnapshottableFeature()remove DirectorySnapshottableFeature -
replaceChild
Replace the given child with a new child. Note that we no longer need to replace an normal INodeDirectory or INodeFile into an INodeDirectoryWithSnapshot or INodeFileUnderConstruction. The only cases for child replacement is for reference nodes. -
recordModification
public void recordModification(int latestSnapshotId) -
saveChild2Snapshot
Save the child to the latest snapshot.- Returns:
- the child inode, which may be replaced.
-
getChild
- Parameters:
name- the name of the childsnapshotId- if it is notSnapshot.CURRENT_STATE_ID, get the result from the corresponding snapshot; otherwise, get the result from the current directory.- Returns:
- the child inode.
-
searchChild
Search for the given INode in the children list and the deleted lists of snapshots.- Returns:
Snapshot.CURRENT_STATE_IDif the inode is in the children list;Snapshot.NO_SNAPSHOT_IDif the inode is neither in the children list nor in any snapshot; otherwise the snapshot id of the corresponding snapshot diff list.
-
getChildrenList
- Parameters:
snapshotId- if it is notSnapshot.CURRENT_STATE_ID, get the result from the corresponding snapshot; otherwise, get the result from the current directory.- Returns:
- the current children list if the specified snapshot is null; otherwise, return the children list corresponding to the snapshot. Note that the returned list is never null.
-
removeChild
Remove the specified child from this directory. -
removeChild
Remove the specified child from this directory. The basic remove method which actually calls children.remove(..).- Parameters:
child- the child inode to be removed- Returns:
- true if the child is removed; false if the child is not found.
-
addChild
Add a child inode to the directory.- Parameters:
node- INode to insertsetModTime- set modification time for the parent node not needed when replaying the addition and the parent already has the proper mod time- Returns:
- false if the child with this name already exists; otherwise, return true;
-
addChild
-
addChildAtLoading
During image loading, the search is unnecessary since the insert position should always be at the end of the map given the sequence they are serialized on disk. -
computeQuotaUsage
public QuotaCounts computeQuotaUsage(BlockStoragePolicySuite bsps, byte blockStoragePolicyId, boolean useCache, int lastSnapshotId) Description copied from class:INodeCount subtreeQuota.NAMESPACEandQuota.STORAGESPACEusages. With the existence ofINodeReference, the same inode and its subtree may be referred by multipleINodeReference.WithNamenodes and aINodeReference.DstReferencenode. To avoid circles while quota usage computation, we have the following rules:1. For a
INodeReference.DstReferencenode, since the node must be in the current tree (or has been deleted as the end point of a series of rename operations), we compute the quota usage of the referred node (and its subtree) in the regular manner, i.e., including every inode in the current tree and in snapshot copies, as well as the size of diff list. 2. For aINodeReference.WithNamenode, since the node must be in a snapshot, we only count the quota usage for those nodes that still existed at the creation time of the snapshot associated with theINodeReference.WithNamenode. We do not count in the size of the diff list.- Specified by:
computeQuotaUsagein classINode- Parameters:
bsps- Block storage policy suite to calculate intended storage type usageblockStoragePolicyId- block storage policy id of the current INodeuseCache- Whether to use cached quota usage. Note thatINodeReference.WithNamenode never uses cache for its subtree.lastSnapshotId-Snapshot.CURRENT_STATE_IDindicates the computation is in the current tree. Otherwise the id indicates the computation range for aINodeReference.WithNamenode.- Returns:
- The subtree quota counts.
-
computeQuotaUsage4CurrentDirectory
public QuotaCounts computeQuotaUsage4CurrentDirectory(BlockStoragePolicySuite bsps, byte storagePolicyId, QuotaCounts counts) Add quota usage for this inode excluding children. -
computeContentSummary
public ContentSummaryComputationContext computeContentSummary(int snapshotId, ContentSummaryComputationContext summary) throws org.apache.hadoop.security.AccessControlException Description copied from class:INodeCount subtree content summary with aContentCounts.- Specified by:
computeContentSummaryin classINode- Parameters:
snapshotId- Specify the time range for the calculation. If this parameter equals toSnapshot.CURRENT_STATE_ID, the result covers both the current states and all the snapshots. Otherwise the result only covers all the files/directories contained in the specific snapshot.summary- the context object holding counts for the subtree.- Returns:
- The same objects as summary.
- Throws:
org.apache.hadoop.security.AccessControlException
-
computeDirectoryContentSummary
protected ContentSummaryComputationContext computeDirectoryContentSummary(ContentSummaryComputationContext summary, int snapshotId) throws org.apache.hadoop.security.AccessControlException - Throws:
org.apache.hadoop.security.AccessControlException
-
undoRename4ScrParent
This method is usually called by the undo section of rename. Before calling this function, in the rename operation, we replace the original src node (of the rename operation) with a reference node (WithName instance) in both the children list and a created list, delete the reference node from the children list, and add it to the corresponding deleted list. To undo the above operations, we have the following steps in particular:1) remove the WithName node from the deleted list (if it exists) 2) replace the WithName node in the created list with srcChild 3) add srcChild back as a child of srcParent. Note that we already add the node into the created list of a snapshot diff in step 2, we do not need to add srcChild to the created list of the latest snapshot.
We do not need to update quota usage because the old child is in the deleted list before.- Parameters:
oldChild- The reference node to be removed/replacednewChild- The node to be added back
-
undoRename4DstParent
public void undoRename4DstParent(BlockStoragePolicySuite bsps, INode deletedChild, int latestSnapshotId) Undo the rename operation for the dst tree, i.e., if the rename operation (with OVERWRITE option) removes a file/dir from the dst tree, add it back and delete possible record in the deleted list. -
clearChildren
public void clearChildren()Set the children list to null. -
clear
public void clear()Description copied from class:INodeClear references to other objects. -
cleanSubtreeRecursively
public void cleanSubtreeRecursively(INode.ReclaimContext reclaimContext, int snapshot, int prior, Map<INode, INode> excludedNodes) Call cleanSubtree(..) recursively down the subtree. -
destroyAndCollectBlocks
Description copied from class:INodeDestroy self and clear everything! If the INode is a file, this method collects its blocks for further block deletion. If the INode is a directory, the method goes down the subtree and collects blocks from the descents, and clears its parent/children references as well. The method also clears the diff list if the INode contains snapshot diff list.- Specified by:
destroyAndCollectBlocksin classINode- Parameters:
reclaimContext- Record blocks and inodes that need to be reclaimed.
-
cleanSubtree
Description copied from class:INodeClean the subtree under this inode and collect the blocks from the descents for further block deletion/update. The current inode can either resides in the current tree or be stored as a snapshot copy.In general, we have the following rules. 1. When deleting a file/directory in the current tree, we have different actions according to the type of the node to delete. 1.1 The current inode (this) is an
INodeFile. 1.1.1 Ifprioris null, there is no snapshot taken on ancestors before. Thus we simply destroy (i.e., to delete completely, no need to save snapshot copy) the current INode and collect its blocks for further cleansing. 1.1.2 Else do nothing since the current INode will be stored as a snapshot copy. 1.2 The current inode is anINodeDirectory. 1.2.1 Ifprioris null, there is no snapshot taken on ancestors before. Similarly, we destroy the whole subtree and collect blocks. 1.2.2 Else do nothing with the current INode. Recursively clean its children. 1.3 The current inode is a file with snapshot. Call recordModification(..) to capture the current states. Mark the INode as deleted. 1.4 The current inode is anINodeDirectorywith snapshot feature. Call recordModification(..) to capture the current states. Destroy files/directories created after the latest snapshot (i.e., the inodes stored in the created list of the latest snapshot). Recursively clean remaining children. 2. When deleting a snapshot. 2.1 To cleanINodeFile: do nothing. 2.2 To cleanINodeDirectory: recursively clean its children. 2.3 To clean INodeFile with snapshot: delete the corresponding snapshot in its diff list. 2.4 To cleanINodeDirectorywith snapshot: delete the corresponding snapshot in its diff list. Recursively clean its children.- Specified by:
cleanSubtreein classINode- Parameters:
reclaimContext- Record blocks and inodes that need to be reclaimed.snapshotId- The id of the snapshot to delete.Snapshot.CURRENT_STATE_IDmeans to delete the current file/directory.priorSnapshotId- The id of the latest snapshot before the to-be-deleted snapshot. When deleting a current inode, this parameter captures the latest snapshot.
-
metadataEquals
Compare the metadata with another INodeDirectory- Specified by:
metadataEqualsin interfaceINodeDirectoryAttributes
-
dumpTreeRecursively
@VisibleForTesting public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshot) Description copied from class:INodeDump tree recursively.- Overrides:
dumpTreeRecursivelyin classINodeprefix- The prefix string that each line should print.
-
dumpTreeRecursively
@VisibleForTesting public static void dumpTreeRecursively(PrintWriter out, StringBuilder prefix, Iterable<INodeDirectory.SnapshotAndINode> subs) Dump the given subtrees.- Parameters:
prefix- The prefix string that each line should print.subs- The subtrees.
-
accept
Description copied from class:INodeAccept a visitor to visit thisINode. -
getChildrenNum
public final int getChildrenNum(int snapshotId)
-