Class INodeReference
- All Implemented Interfaces:
Comparable<byte[]>,INodeAttributes,Diff.Element<byte[]>
- Direct Known Subclasses:
INodeReference.DstReference,INodeReference.WithCount,INodeReference.WithName
This class and its subclasses are used to support multiple access paths. A file/directory may have multiple access paths when it is stored in some snapshots, and it is renamed/moved to other locations.
For example, (1) Suppose we have /abc/foo and the inode is inode(id=1000,name=foo). Suppose foo is created after snapshot s0, i.e. foo is not in s0 and inode(id=1000,name=foo) is in the create-list of /abc for the s0 diff entry. (2) Create snapshot s1, s2 for /abc, i.e. foo is in s1 and s2. Suppose sDst is the last snapshot /xyz. (3) mv /abc/foo /xyz/bar, i.e. inode(id=1000,name=...) is renamed from "foo" to "bar" and its parent becomes /xyz.
Then, /xyz/bar, /abc/.snapshot/s1/foo and /abc/.snapshot/s2/foo are different access paths to the same inode, inode(id=1000,name=bar). Inside the inode tree, /abc/.snapshot/s1/foo and /abc/.snapshot/s2/foo indeed have the same resolved path, but /xyz/bar has a different resolved path.
With references, we have the following - The source /abc/foo inode(id=1000,name=foo) is replaced with a WithName(name=foo,lastSnapshot=s2) and then it is moved to the delete-list of /abc for the s2 diff entry. The replacement also replaces inode(id=1000,name=foo) in the create-list of /abc for the s0 diff entry with the WithName. The same as before, /abc/foo is in s1 and s2, but not in s0. - The destination /xyz adds a child DstReference(dstSnapshot=sDst). DstReference is added to the create-list of /xyz for the sDst diff entry. /xyz/bar is not in sDst. - Both WithName and DstReference point to another reference WithCount(count=2). - Finally, WithCount(count=2) points to inode(id=1000,name=bar) Note that the inode name is changed to "bar".
Note 1: References other than WithName use the name of the referred inode,
i.e. WithCount and DstReference do not have their own name.
Note 2: getParent() always returns the parent in the current state, e.g.
inode(id=1000,name=bar).getParent() returns /xyz but not /abc.
Note 3: getId() returns the id the referred inode,
e.g. all WithName, DstReference and WithCount above return id=1000.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classAn anonymous reference with reference count.static classA reference with a fixed name.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.SnapshotCopy -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(NamespaceVisitor visitor, int snapshot) Accept a visitor to visit thisINode.final INodeDirectoryCast this inode to anINodeDirectory.final INodeFileasFile()Cast this inode to anINodeFile.final INodeReferenceCast this inode to anINodeReference.final INodeSymlinkCast this inode to anINodeSymlink.voidcleanSubtree(INode.ReclaimContext reclaimContext, int snapshot, int prior) Clean the subtree under this inode and collect the blocks from the descents for further block deletion/update.final voidclear()Clear references to other objects.computeContentSummary(int snapshotId, ContentSummaryComputationContext summary) Count subtree content summary with aContentCounts.computeQuotaUsage(BlockStoragePolicySuite bsps, byte blockStoragePolicyId, boolean useCache, int lastSnapshotId) Count subtreeQuota.NAMESPACEandQuota.STORAGESPACEusages.voiddestroyAndCollectBlocks(INode.ReclaimContext reclaimContext) Destroy self and clear everything!voiddumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshot) Dump tree recursively.final longgetAccessTime(int snapshotId) intfinal org.apache.hadoop.fs.permission.FsPermissiongetFsPermission(int snapshotId) final shortfinal StringgetGroupName(int snapshotId) final longgetId()Get inode idbyte[]final bytefinal longgetModificationTime(int snapshotId) longfinal org.apache.hadoop.fs.permission.PermissionStatusgetPermissionStatus(int snapshotId) Get thePermissionStatusGet the quota set for this inodefinal INodefinal INodeAttributesgetSnapshotINode(int snapshotId) final bytefinal StringgetUserName(int snapshotId) final booleanCheck whether it's a directoryfinal booleanisFile()Check whether it's a file.final booleanCheck whether it's a reference.final booleanCheck whether it's a symlinkfinal voidsetAccessTime(long accessTime) Set last access time of inode.voidsetLocalName(byte[] name) Set local file namefinal voidsetModificationTime(long modificationTime) Set the last modification time of inode.static inttryRemoveReference(INode inode) Try to remove the given reference and then return the reference count.final INodeupdateModificationTime(long mtime, int latestSnapshotId) Update modification time if it is larger than the current value.Methods inherited from class org.apache.hadoop.hdfs.server.namenode.INode
addSpaceConsumed, 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, isInCurrentState, isInLatestSnapshot, isLastReference, isQuotaSet, isSetStoragePolicy, setAccessTime, setModificationTime, setParent, setParentReference, shouldRecordInSrcSnapshot, toString
-
Constructor Details
-
INodeReference
-
-
Method Details
-
toDetailString
- Overrides:
toDetailStringin classINode
-
tryRemoveReference
Try to remove the given reference and then return the reference count. If the given inode is not a reference, return -1; -
getReferredINode
-
isReference
public final boolean isReference()Description copied from class:INodeCheck whether it's a reference.- Overrides:
isReferencein classINode
-
asReference
Description copied from class:INodeCast this inode to anINodeReference.- Overrides:
asReferencein classINode
-
isFile
public final boolean isFile()Description copied from class:INodeCheck whether it's a file. -
asFile
Description copied from class:INodeCast this inode to anINodeFile. -
isDirectory
public final boolean isDirectory()Description copied from class:INodeCheck whether it's a directory- Specified by:
isDirectoryin interfaceINodeAttributes- Overrides:
isDirectoryin classINode
-
asDirectory
Description copied from class:INodeCast this inode to anINodeDirectory.- Overrides:
asDirectoryin classINode
-
isSymlink
public final boolean isSymlink()Description copied from class:INodeCheck whether it's a symlink -
asSymlink
Description copied from class:INodeCast this inode to anINodeSymlink. -
getLocalNameBytes
public byte[] getLocalNameBytes()- Returns:
- null if the local name is null; otherwise, return the local name byte array.
-
setLocalName
public void setLocalName(byte[] name) Description copied from class:INodeSet local file name- Specified by:
setLocalNamein classINode
-
getId
public final long getId()Description copied from class:INodeGet inode id -
getPermissionStatus
public final org.apache.hadoop.fs.permission.PermissionStatus getPermissionStatus(int snapshotId) Description copied from class:INodeGet thePermissionStatus- Specified by:
getPermissionStatusin classINode
-
getUserName
-
getGroupName
-
getFsPermission
public final org.apache.hadoop.fs.permission.FsPermission getFsPermission(int snapshotId) -
getFsPermissionShort
public final short getFsPermissionShort()- Returns:
- the permission as a short.
-
getPermissionLong
public long getPermissionLong()- Returns:
- the permission information as a long.
-
getModificationTime
public final long getModificationTime(int snapshotId) -
updateModificationTime
Description copied from class:INodeUpdate modification time if it is larger than the current value.- Specified by:
updateModificationTimein classINode
-
setModificationTime
public final void setModificationTime(long modificationTime) Description copied from class:INodeSet the last modification time of inode.- Specified by:
setModificationTimein classINode
-
getAccessTime
public final long getAccessTime(int snapshotId) -
setAccessTime
public final void setAccessTime(long accessTime) Description copied from class:INodeSet last access time of inode.- Specified by:
setAccessTimein classINode
-
getStoragePolicyID
public final 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.
-
getLocalStoragePolicyID
public final 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.
-
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.snapshot- The id of the snapshot to delete.Snapshot.CURRENT_STATE_IDmeans to delete the current file/directory.prior- The id of the latest snapshot before the to-be-deleted snapshot. When deleting a current inode, this parameter captures the latest snapshot.
-
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.
-
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
-
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.
-
getSnapshotINode
- Overrides:
getSnapshotINodein classINode- Returns:
- if the given snapshot id is
Snapshot.CURRENT_STATE_ID, return this; otherwise return the corresponding snapshot inode.
-
getQuotaCounts
Description copied from class:INodeGet the quota set for this inode- Overrides:
getQuotaCountsin classINode- Returns:
- the quota counts. The count is -1 if it is not set.
-
clear
public final void clear()Description copied from class:INodeClear references to other objects. -
dumpTreeRecursively
Description copied from class:INodeDump tree recursively.- Overrides:
dumpTreeRecursivelyin classINodeprefix- The prefix string that each line should print.
-
accept
Description copied from class:INodeAccept a visitor to visit thisINode. -
getDstSnapshotId
public int getDstSnapshotId()
-