Class INode
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.INode
- All Implemented Interfaces:
Comparable<byte[]>,INodeAttributes,Diff.Element<byte[]>
- Direct Known Subclasses:
INodeReference,INodeWithAdditionalFields
@Private
public abstract class INode
extends Object
implements INodeAttributes, Diff.Element<byte[]>
We keep an in-memory representation of the file/block hierarchy.
This is a base INode class containing common fields for file and
directory inodes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInformation used for updating the blocksMap when deleting files.static interfaceINode feature such asFileUnderConstructionFeatureandDirectoryWithQuotaFeature.static classInformation used to record quota usage delta.static classContext object to record blocks and inodes that need to be reclaimedNested classes/interfaces inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeAttributes
INodeAttributes.SnapshotCopy -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(NamespaceVisitor visitor, int snapshot) Accept a visitor to visit thisINode.voidaddSpaceConsumed(QuotaCounts counts) Check and add namespace/storagespace/storagetype consumed to itself and the ancestors.Cast this inode to anINodeDirectory.asFile()Cast this inode to anINodeFile.Cast this inode to anINodeReference.Cast this inode to anINodeSymlink.abstract 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.voidclear()Clear references to other objects.final intcompareTo(byte[] bytes) final org.apache.hadoop.fs.ContentSummarycomputeAndConvertContentSummary(int snapshotId, ContentSummaryComputationContext summary) ComputeContentSummary.abstract ContentSummaryComputationContextcomputeContentSummary(int snapshotId, ContentSummaryComputationContext summary) Count subtree content summary with aContentCounts.final org.apache.hadoop.fs.ContentSummaryComputeContentSummary.final QuotaCountsCount subtreeQuota.NAMESPACEandQuota.STORAGESPACEusages.final QuotaCountscomputeQuotaUsage(BlockStoragePolicySuite bsps, boolean useCache) abstract QuotaCountscomputeQuotaUsage(BlockStoragePolicySuite bsps, byte blockStoragePolicyId, boolean useCache, int lastSnapshotId) Count subtreeQuota.NAMESPACEandQuota.STORAGESPACEusages.abstract voiddestroyAndCollectBlocks(INode.ReclaimContext reclaimContext) Destroy self and clear everything!voiddumpINode(PrintWriter out, StringBuilder prefix, int snapshotId) final StringBuilderfinal StringBufferDump the subtree starting from this inode.final voidvoiddumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshotId) Dump tree recursively.final booleanfinal longThe same as getAccessTime(Snapshot.CURRENT_STATE_ID).final AclFeaturefinal org.apache.hadoop.fs.permission.FsPermissionThe same as getFsPermission(Snapshot.CURRENT_STATE_ID).final StringThe same as getGroupName(Snapshot.CURRENT_STATE_ID).abstract longgetId()Get inode idfinal byte[]getKey()final Stringabstract bytefinal longThe same as getModificationTime(Snapshot.CURRENT_STATE_ID).final Stringfinal INodeDirectoryfinal Stringbyte[][]static byte[][]getPathComponents(String path) Breakspathinto components.static String[]getPathNames(String path) Splits an absolutepathinto an array of path components.abstract org.apache.hadoop.fs.permission.PermissionStatusgetPermissionStatus(int snapshotId) Get thePermissionStatusGet the quota set for this inodegetSnapshotINode(int snapshotId) abstract bytebytegetStoragePolicyIDForQuota(byte parentStoragePolicyId) Get the storage policy ID while computing quota usagefinal StringThe same as getUserName(Snapshot.CURRENT_STATE_ID).final XAttrFeaturefinal inthashCode()final booleanbooleanbooleanCheck whether it's a directorybooleanisFile()Check whether it's a file.booleanIs this inode in the current state?final booleanisInLatestSnapshot(int latestSnapshotId) Is this inode in the latest snapshot?booleanfinal booleanbooleanCheck whether it's a reference.booleanCheck if this inode itself has a storage policy set.booleanCheck whether it's a symlinkabstract voidsetAccessTime(long accessTime) Set last access time of inode.final INodesetAccessTime(long accessTime, int latestSnapshotId, boolean skipCaptureAccessTimeOnlyChangeInSnapshot) Set last access time of inode.abstract voidsetLocalName(byte[] name) Set local file nameabstract voidsetModificationTime(long modificationTime) Set the last modification time of inode.final INodesetModificationTime(long modificationTime, int latestSnapshotId) Set the last modification time of inode.final voidsetParent(INodeDirectory parent) Set parent directoryfinal voidsetParentReference(INodeReference parent) Set container.final booleanshouldRecordInSrcSnapshot(int latestInDst) WhenrecordModification(int)is called on a referred node, this method tells which snapshot the modification should be associated with: the snapshot that belongs to the SRC tree of the rename operation, or the snapshot belonging to the DST tree.toString()abstract INodeupdateModificationTime(long mtime, int latestSnapshotId) Update modification time if it is larger than the current value.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeAttributes
getFsPermissionShort, getLocalNameBytes, getPermissionLong
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG
-
-
Method Details
-
getId
public abstract long getId()Get inode id -
getPermissionStatus
public abstract org.apache.hadoop.fs.permission.PermissionStatus getPermissionStatus(int snapshotId) Get thePermissionStatus -
getUserName
The same as getUserName(Snapshot.CURRENT_STATE_ID).- Specified by:
getUserNamein interfaceINodeAttributes- Returns:
- the user name.
-
getGroupName
The same as getGroupName(Snapshot.CURRENT_STATE_ID).- Specified by:
getGroupNamein interfaceINodeAttributes- Returns:
- the group name.
-
getFsPermission
public final org.apache.hadoop.fs.permission.FsPermission getFsPermission()The same as getFsPermission(Snapshot.CURRENT_STATE_ID).- Specified by:
getFsPermissionin interfaceINodeAttributes- Returns:
- the permission.
-
getAclFeature
- Specified by:
getAclFeaturein interfaceINodeAttributes- Returns:
- the ACL feature.
-
getXAttrFeature
- Specified by:
getXAttrFeaturein interfaceINodeAttributes- Returns:
- the XAttrs feature.
-
getSnapshotINode
- Returns:
- if the given snapshot id is
Snapshot.CURRENT_STATE_ID, return this; otherwise return the corresponding snapshot inode.
-
isInCurrentState
public boolean isInCurrentState()Is this inode in the current state? -
isInLatestSnapshot
public final boolean isInLatestSnapshot(int latestSnapshotId) Is this inode in the latest snapshot? -
isAncestorDirectory
- Returns:
- true if the given inode is an ancestor directory of this inode.
-
shouldRecordInSrcSnapshot
public final boolean shouldRecordInSrcSnapshot(int latestInDst) WhenrecordModification(int)is called on a referred node, this method tells which snapshot the modification should be associated with: the snapshot that belongs to the SRC tree of the rename operation, or the snapshot belonging to the DST tree.- Parameters:
latestInDst- id of the latest snapshot in the DST tree above the reference node- Returns:
- True: the modification should be recorded in the snapshot that belongs to the SRC tree. False: the modification should be recorded in the snapshot that belongs to the DST tree.
-
isReference
public boolean isReference()Check whether it's a reference. -
asReference
Cast this inode to anINodeReference. -
isFile
public boolean isFile()Check whether it's a file. -
isSetStoragePolicy
public boolean isSetStoragePolicy()Check if this inode itself has a storage policy set. -
asFile
Cast this inode to anINodeFile. -
isDirectory
public boolean isDirectory()Check whether it's a directory- Specified by:
isDirectoryin interfaceINodeAttributes
-
asDirectory
Cast this inode to anINodeDirectory. -
isSymlink
public boolean isSymlink()Check whether it's a symlink -
asSymlink
Cast this inode to anINodeSymlink. -
cleanSubtree
public abstract void cleanSubtree(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. 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.- 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.
-
destroyAndCollectBlocks
Destroy 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.- Parameters:
reclaimContext- Record blocks and inodes that need to be reclaimed.
-
computeContentSummary
public final org.apache.hadoop.fs.ContentSummary computeContentSummary(BlockStoragePolicySuite bsps) throws org.apache.hadoop.security.AccessControlException ComputeContentSummary. Blocking call- Throws:
org.apache.hadoop.security.AccessControlException
-
computeAndConvertContentSummary
public final org.apache.hadoop.fs.ContentSummary computeAndConvertContentSummary(int snapshotId, ContentSummaryComputationContext summary) throws org.apache.hadoop.security.AccessControlException ComputeContentSummary.- Throws:
org.apache.hadoop.security.AccessControlException
-
computeContentSummary
public abstract ContentSummaryComputationContext computeContentSummary(int snapshotId, ContentSummaryComputationContext summary) throws org.apache.hadoop.security.AccessControlException Count subtree content summary with aContentCounts.- 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
-
addSpaceConsumed
Check and add namespace/storagespace/storagetype consumed to itself and the ancestors. -
getQuotaCounts
Get the quota set for this inode- Returns:
- the quota counts. The count is -1 if it is not set.
-
isQuotaSet
public final boolean isQuotaSet() -
computeQuotaUsage
Count subtreeQuota.NAMESPACEandQuota.STORAGESPACEusages. Entry point for FSDirectory where blockStoragePolicyId is given its initial value. -
computeQuotaUsage
public abstract QuotaCounts computeQuotaUsage(BlockStoragePolicySuite bsps, byte blockStoragePolicyId, boolean useCache, int lastSnapshotId) Count 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.- 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.
-
computeQuotaUsage
-
getLocalName
- Returns:
- null if the local name is null; otherwise, return the local name.
-
getKey
public final byte[] getKey()- Specified by:
getKeyin interfaceDiff.Element<byte[]>- Returns:
- the key of this object.
-
setLocalName
public abstract void setLocalName(byte[] name) Set local file name -
getFullPathName
-
isDeleted
public boolean isDeleted() -
getPathComponents
public byte[][] getPathComponents() -
toString
-
getObjectString
-
getParentString
- Returns:
- a string description of the parent.
-
getFullPathAndObjectString
-
toDetailString
-
getParent
- Returns:
- the parent directory
-
getParentReference
- Returns:
- the parent as a reference if this is a referred inode; otherwise, return null.
-
isLastReference
public boolean isLastReference()- Returns:
- true if this is a reference and the reference count is 1; otherwise, return false.
-
setParent
Set parent directory -
setParentReference
Set container. -
clear
public void clear()Clear references to other objects. -
getModificationTime
public final long getModificationTime()The same as getModificationTime(Snapshot.CURRENT_STATE_ID).- Specified by:
getModificationTimein interfaceINodeAttributes- Returns:
- the modification time.
-
updateModificationTime
Update modification time if it is larger than the current value. -
setModificationTime
public abstract void setModificationTime(long modificationTime) Set the last modification time of inode. -
setModificationTime
Set the last modification time of inode. -
getAccessTime
public final long getAccessTime()The same as getAccessTime(Snapshot.CURRENT_STATE_ID).- Specified by:
getAccessTimein interfaceINodeAttributes- Returns:
- the access time.
-
setAccessTime
public abstract void setAccessTime(long accessTime) Set last access time of inode. -
setAccessTime
public final INode setAccessTime(long accessTime, int latestSnapshotId, boolean skipCaptureAccessTimeOnlyChangeInSnapshot) Set last access time of inode. -
getStoragePolicyID
public abstract byte getStoragePolicyID()- 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.
-
getLocalStoragePolicyID
public abstract byte getLocalStoragePolicyID()- Returns:
- the storage policy directly specified on the INode. Return
HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIEDif no policy has been specified.
-
getStoragePolicyIDForQuota
public byte getStoragePolicyIDForQuota(byte parentStoragePolicyId) Get the storage policy ID while computing quota usage- Parameters:
parentStoragePolicyId- the storage policy ID of the parent directory- Returns:
- the storage policy ID of this INode. Note that for an
INodeSymlinkwe returnHdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIEDinstead of throwing Exception
-
getPathComponents
Breakspathinto components.- Returns:
- array of byte arrays each of which represents a single path component.
-
getPathNames
Splits an absolutepathinto an array of path components.- Returns:
- array of path components.
- Throws:
AssertionError- if the given path is invalid.
-
compareTo
public final int compareTo(byte[] bytes) - Specified by:
compareToin interfaceComparable<byte[]>
-
equals
-
hashCode
public final int hashCode() -
dumpParentINodes
-
dumpTreeRecursively
Dump the subtree starting from this inode.- Returns:
- a text representation of the tree.
-
dumpTreeRecursively
-
dumpTreeRecursively
@VisibleForTesting public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshotId) Dump tree recursively.- Parameters:
prefix- The prefix string that each line should print.
-
dumpINode
-
accept
Accept a visitor to visit thisINode.
-