Class INodeFile
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.INode
org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields
org.apache.hadoop.hdfs.server.namenode.INodeFile
- All Implemented Interfaces:
Comparable<byte[]>,BlockCollection,INodeAttributes,INodeFileAttributes,Diff.Element<byte[]>,org.apache.hadoop.util.LightWeightGSet.LinkedElement
@Private
public class INodeFile
extends INodeWithAdditionalFields
implements INodeFileAttributes, BlockCollection
I-node for closed file.
-
Nested Class Summary
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.INodeFileAttributes
INodeFileAttributes.SnapshotCopy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final shortErasure Coded striped blocks have replication factor of 1.Fields inherited from class org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields
features -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(NamespaceVisitor visitor, int snapshot) Accept a visitor to visit thisINode.addSnapshotFeature(FileDiffList diffs) final INodeFileasFile()Cast this inode to anINodeFile.voidcleanSubtree(INode.ReclaimContext reclaimContext, int snapshot, int priorSnapshotId) Clean the subtree under this inode and collect the blocks from the descents for further block deletion/update.voidClear all blocks of the file.voidclearFile(INode.ReclaimContext reclaimContext) longcollectBlocksBeyondMax(long max, INode.BlocksMapUpdateInfo collectedBlocks, Set<BlockInfo> toRetain) Remove full blocks at the end file up to newLengthvoidcollectBlocksBeyondSnapshot(BlockInfo[] snapshotBlocks, INode.BlocksMapUpdateInfo collectedBlocks) This function is only called when block list is stored in snapshot diffs.computeContentSummary(int snapshotId, ContentSummaryComputationContext summary) Count subtree content summary with aContentCounts.final longThe same as computeFileSize(null).final longcomputeFileSize(boolean includesLastUcBlock, boolean usePreferredBlockSize4LastUcBlock) Compute file size of the current file.final longcomputeFileSize(int snapshotId) Compute file size of the current file if the given snapshot is null; otherwise, get the file size from the given snapshot.final longCompute file size of the current file size but not including the last block if it is under construction.final QuotaCountscomputeQuotaUsage(BlockStoragePolicySuite bsps, byte blockStoragePolicyId, boolean useCache, int lastSnapshotId) Count subtreeQuota.NAMESPACEandQuota.STORAGESPACEusages.final QuotaCountscomputeQuotaUsageWithStriped(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy bsp, QuotaCounts counts) Compute quota of striped file.voidconvertLastBlockToUC(BlockInfo lastBlock, DatanodeStorageInfo[] locations) Convert the last block of the collection to an under-construction block and set the locations.voiddestroyAndCollectBlocks(INode.ReclaimContext reclaimContext) Destroy self and clear everything!voiddumpINodeFile(PrintWriter out, StringBuilder prefix, int snapshotId) voiddumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshotId) Dump tree recursively.Get the blocks (striped or contiguous).getBlocks(int snapshot) org.apache.hadoop.hdfs.protocol.BlockTypegetDiffs()bytefinal shortThe same as getFileReplication(null).final shortgetFileReplication(int snapshot) If the inode contains aFileUnderConstructionFeature, return it; otherwise, return null.final FileWithSnapshotFeatureIf feature list contains aFileWithSnapshotFeature, return it; otherwise, return null.longGet the last block of the collection.bytegetName()Get the name of the collection.shortGet block replication for the collection.longGet preferred block size for the collectiongetSnapshotINode(int snapshotId) bytefinal booleanisFile()Check whether it's a file.booleanbooleanIs this file under construction?final booleanIs this file has the snapshot feature?loadSnapshotFeature(FileDiffList diffs) Used by FSImage.booleanintvoidrecordModification(int latestSnapshotId) voidrecordModification(int latestSnapshotId, boolean withBlocks) voidSet the block (contiguous or striped) at the given index.final INodeFilesetFileReplication(short replication, int latestSnapshotId) Set the replication factor of this file.final voidsetStoragePolicyID(byte storagePolicyId, int latestSnapshotId) final QuotaCountsstoragespaceConsumed(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy bsp) Compute size consumed by all blocks of the current file, including blocks in its snapshots.final QuotaCountsstoragespaceConsumedContiguous(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy bsp) final QuotaCountsstatic INodeFileThe same as valueOf(inode, path, false).static INodeFileCast INode to INodeFile.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
addSpaceConsumed, asDirectory, asReference, asSymlink, clear, 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, getQuotaCounts, getStoragePolicyIDForQuota, getUserName, getXAttrFeature, hashCode, isAncestorDirectory, isDeleted, isDirectory, 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.blockmanagement.BlockCollection
computeContentSummary, getIdMethods inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeAttributes
getAccessTime, getAclFeature, getFsPermission, getFsPermissionShort, getGroupName, getLocalNameBytes, getModificationTime, getPermissionLong, getUserName, getXAttrFeature, isDirectory
-
Field Details
-
DEFAULT_REPL_FOR_STRIPED_BLOCKS
public static final short DEFAULT_REPL_FOR_STRIPED_BLOCKSErasure Coded striped blocks have replication factor of 1.- See Also:
-
-
Constructor Details
-
INodeFile
public INodeFile(long id, byte[] name, org.apache.hadoop.fs.permission.PermissionStatus permissions, long mtime, long atime, BlockInfo[] blklist, short replication, long preferredBlockSize) -
INodeFile
-
-
Method Details
-
valueOf
The same as valueOf(inode, path, false).- Throws:
FileNotFoundException
-
valueOf
public static INodeFile valueOf(INode inode, String path, boolean acceptNull) throws FileNotFoundException Cast INode to INodeFile.- Throws:
FileNotFoundException
-
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. -
metadataEquals
- Specified by:
metadataEqualsin interfaceINodeFileAttributes
-
getFileUnderConstructionFeature
If the inode contains aFileUnderConstructionFeature, return it; otherwise, return null. -
isUnderConstruction
public boolean isUnderConstruction()Is this file under construction?- Specified by:
isUnderConstructionin interfaceBlockCollection- Returns:
- whether the block collection is under construction.
-
setBlock
Description copied from interface:BlockCollectionSet the block (contiguous or striped) at the given index.- Specified by:
setBlockin interfaceBlockCollection
-
convertLastBlockToUC
public void convertLastBlockToUC(BlockInfo lastBlock, DatanodeStorageInfo[] locations) throws IOException Description copied from interface:BlockCollectionConvert the last block of the collection to an under-construction block and set the locations.- Specified by:
convertLastBlockToUCin interfaceBlockCollection- Throws:
IOException
-
addSnapshotFeature
-
loadSnapshotFeature
Used by FSImage. -
getFileWithSnapshotFeature
If feature list contains aFileWithSnapshotFeature, return it; otherwise, return null. -
isWithSnapshot
public final boolean isWithSnapshot()Is this file has the snapshot feature? -
toDetailString
- Overrides:
toDetailStringin classINode
-
getSnapshotINode
- Overrides:
getSnapshotINodein classINode- Returns:
- if the given snapshot id is
Snapshot.CURRENT_STATE_ID, return this; otherwise return the corresponding snapshot inode.
-
recordModification
public void recordModification(int latestSnapshotId) -
recordModification
public void recordModification(int latestSnapshotId, boolean withBlocks) -
getDiffs
-
getFileReplication
public final short getFileReplication(int snapshot) - Returns:
- the replication factor of the file.
-
getFileReplication
public final short getFileReplication()The same as getFileReplication(null). For erasure coded files, this returns the EC policy ID.- Specified by:
getFileReplicationin interfaceINodeFileAttributes- Returns:
- the file replication.
-
getPreferredBlockReplication
public short getPreferredBlockReplication()Description copied from interface:BlockCollectionGet block replication for the collection.- Specified by:
getPreferredBlockReplicationin interfaceBlockCollection- Returns:
- block replication value. Return 0 if the file is erasure coded.
-
setFileReplication
public final INodeFile setFileReplication(short replication, int latestSnapshotId) throws org.apache.hadoop.hdfs.protocol.QuotaExceededException Set the replication factor of this file.- Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException
-
getPreferredBlockSize
public long getPreferredBlockSize()Description copied from interface:BlockCollectionGet preferred block size for the collection- Specified by:
getPreferredBlockSizein interfaceBlockCollection- Specified by:
getPreferredBlockSizein interfaceINodeFileAttributes- Returns:
- preferred block size (in bytes) of the file.
-
getLocalStoragePolicyID
public byte getLocalStoragePolicyID()- Specified by:
getLocalStoragePolicyIDin interfaceINodeFileAttributes- 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 interfaceBlockCollection- 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.
-
setStoragePolicyID
public final void setStoragePolicyID(byte storagePolicyId, int latestSnapshotId) throws org.apache.hadoop.hdfs.protocol.QuotaExceededException - Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException
-
getErasureCodingPolicyID
@VisibleForTesting public byte getErasureCodingPolicyID()- Specified by:
getErasureCodingPolicyIDin interfaceINodeFileAttributes- Returns:
- The ID of the erasure coding policy on the file.
-
isStriped
@VisibleForTesting public boolean isStriped()- Specified by:
isStripedin interfaceBlockCollection- Specified by:
isStripedin interfaceINodeFileAttributes- Returns:
- true if the file is in the striping layout.
-
getBlockType
@VisibleForTesting public org.apache.hadoop.hdfs.protocol.BlockType getBlockType()- Specified by:
getBlockTypein interfaceINodeFileAttributes- Returns:
- The type of the INodeFile based on block id.
-
getHeaderLong
public long getHeaderLong()- Specified by:
getHeaderLongin interfaceINodeFileAttributes- Returns:
- the header as a long.
-
getBlocks
Description copied from interface:BlockCollectionGet the blocks (striped or contiguous).- Specified by:
getBlocksin interfaceBlockCollection- Returns:
- the blocks of the file.
-
getBlocks
- Returns:
- blocks of the file corresponding to the snapshot.
-
clearBlocks
public void clearBlocks()Clear all blocks of the file. -
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.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
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.
-
clearFile
-
getName
Description copied from interface:BlockCollectionGet the name of the collection.- Specified by:
getNamein interfaceBlockCollection
-
computeQuotaUsage
public final 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.
-
computeQuotaUsageWithStriped
public final QuotaCounts computeQuotaUsageWithStriped(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy bsp, QuotaCounts counts) Compute quota of striped file. Note that currently EC files do not support append/hflush/hsync, thus the file length recorded in snapshots should be the same with the current file length. -
computeContentSummary
public final ContentSummaryComputationContext computeContentSummary(int snapshotId, ContentSummaryComputationContext summary) 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.
-
computeFileSize
public final long computeFileSize()The same as computeFileSize(null). -
computeFileSize
public final long computeFileSize(int snapshotId) Compute file size of the current file if the given snapshot is null; otherwise, get the file size from the given snapshot. -
computeFileSizeNotIncludingLastUcBlock
public final long computeFileSizeNotIncludingLastUcBlock()Compute file size of the current file size but not including the last block if it is under construction. -
computeFileSize
public final long computeFileSize(boolean includesLastUcBlock, boolean usePreferredBlockSize4LastUcBlock) Compute file size of the current file. ComputeFileSize only needs the FSLock even through it involves block. BlockSize only be changed by hsync, addBlock, commitBlockSynchronization, complete, updatePipeline and forceCompleteBlock, all these operations already hold the FSWriteLock. CompleteBlock also hold the FSWriteLock since it needs to update Quota- Parameters:
includesLastUcBlock- If the last block is under construction, should it be included?usePreferredBlockSize4LastUcBlock- If the last block is under construction, should we use actual block size or preferred block size? Note that usePreferredBlockSize4LastUcBlock is ignored if includesLastUcBlock == false.- Returns:
- file size
-
storagespaceConsumed
public final QuotaCounts storagespaceConsumed(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy bsp) Compute size consumed by all blocks of the current file, including blocks in its snapshots. Use preferred block size for the last block if it is under construction. -
storagespaceConsumedStriped
-
storagespaceConsumedContiguous
public final QuotaCounts storagespaceConsumedContiguous(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy bsp) -
getLastBlock
Description copied from interface:BlockCollectionGet the last block of the collection.- Specified by:
getLastBlockin interfaceBlockCollection
-
numBlocks
public int numBlocks()- Specified by:
numBlocksin interfaceBlockCollection- Returns:
- the number of blocks or block groups
-
dumpTreeRecursively
@VisibleForTesting public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshotId) Description copied from class:INodeDump tree recursively.- Overrides:
dumpTreeRecursivelyin classINodeprefix- The prefix string that each line should print.
-
dumpINodeFile
-
accept
Description copied from class:INodeAccept a visitor to visit thisINode. -
collectBlocksBeyondMax
public long collectBlocksBeyondMax(long max, INode.BlocksMapUpdateInfo collectedBlocks, Set<BlockInfo> toRetain) Remove full blocks at the end file up to newLength- Returns:
- sum of sizes of the remained blocks
-
collectBlocksBeyondSnapshot
public void collectBlocksBeyondSnapshot(BlockInfo[] snapshotBlocks, INode.BlocksMapUpdateInfo collectedBlocks) This function is only called when block list is stored in snapshot diffs. Note that this can only happen when truncation happens with snapshots. Since we do not support truncation with striped blocks, we only need to handle contiguous blocks here.
-