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.
  • 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 the PermissionStatus
    • getUserName

      public final String getUserName()
      The same as getUserName(Snapshot.CURRENT_STATE_ID).
      Specified by:
      getUserName in interface INodeAttributes
      Returns:
      the user name.
    • getGroupName

      public final String getGroupName()
      The same as getGroupName(Snapshot.CURRENT_STATE_ID).
      Specified by:
      getGroupName in interface INodeAttributes
      Returns:
      the group name.
    • getFsPermission

      public final org.apache.hadoop.fs.permission.FsPermission getFsPermission()
      The same as getFsPermission(Snapshot.CURRENT_STATE_ID).
      Specified by:
      getFsPermission in interface INodeAttributes
      Returns:
      the permission.
    • getAclFeature

      public final AclFeature getAclFeature()
      Specified by:
      getAclFeature in interface INodeAttributes
      Returns:
      the ACL feature.
    • getXAttrFeature

      public final XAttrFeature getXAttrFeature()
      Specified by:
      getXAttrFeature in interface INodeAttributes
      Returns:
      the XAttrs feature.
    • getSnapshotINode

      public INodeAttributes getSnapshotINode(int snapshotId)
      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

      public final boolean isAncestorDirectory(INodeDirectory dir)
      Returns:
      true if the given inode is an ancestor directory of this inode.
    • shouldRecordInSrcSnapshot

      public final boolean shouldRecordInSrcSnapshot(int latestInDst)
      When recordModification(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

      public INodeReference asReference()
      Cast this inode to an INodeReference.
    • 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

      public INodeFile asFile()
      Cast this inode to an INodeFile.
    • isDirectory

      public boolean isDirectory()
      Check whether it's a directory
      Specified by:
      isDirectory in interface INodeAttributes
    • asDirectory

      public INodeDirectory asDirectory()
      Cast this inode to an INodeDirectory.
    • isSymlink

      public boolean isSymlink()
      Check whether it's a symlink
    • asSymlink

      public INodeSymlink asSymlink()
      Cast this inode to an INodeSymlink.
    • 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 If prior is 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 an INodeDirectory.
       1.2.1 If prior is 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 an INodeDirectory with 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 clean INodeFile: do nothing.
       2.2 To clean INodeDirectory: recursively clean its children.
       2.3 To clean INodeFile with snapshot: delete the corresponding snapshot in
       its diff list.
       2.4 To clean INodeDirectory with 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_ID means 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

      public abstract void destroyAndCollectBlocks(INode.ReclaimContext reclaimContext)
      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
      Compute ContentSummary. 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
      Compute ContentSummary.
      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 a ContentCounts.
      Parameters:
      snapshotId - Specify the time range for the calculation. If this parameter equals to Snapshot.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

      public void addSpaceConsumed(QuotaCounts counts)
      Check and add namespace/storagespace/storagetype consumed to itself and the ancestors.
    • getQuotaCounts

      public QuotaCounts 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

      public final QuotaCounts computeQuotaUsage(BlockStoragePolicySuite bsps)
      Count subtree Quota.NAMESPACE and Quota.STORAGESPACE usages. 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 subtree Quota.NAMESPACE and Quota.STORAGESPACE usages. With the existence of INodeReference, the same inode and its subtree may be referred by multiple INodeReference.WithName nodes and a INodeReference.DstReference node. To avoid circles while quota usage computation, we have the following rules:
       1. For a INodeReference.DstReference node, 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 a INodeReference.WithName node, 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 the INodeReference.WithName node.
       We do not count in the size of the diff list.
       
      Parameters:
      bsps - Block storage policy suite to calculate intended storage type usage
      blockStoragePolicyId - block storage policy id of the current INode
      useCache - Whether to use cached quota usage. Note that INodeReference.WithName node never uses cache for its subtree.
      lastSnapshotId - Snapshot.CURRENT_STATE_ID indicates the computation is in the current tree. Otherwise the id indicates the computation range for a INodeReference.WithName node.
      Returns:
      The subtree quota counts.
    • computeQuotaUsage

      public final QuotaCounts computeQuotaUsage(BlockStoragePolicySuite bsps, boolean useCache)
    • getLocalName

      public final String getLocalName()
      Returns:
      null if the local name is null; otherwise, return the local name.
    • getKey

      public final byte[] getKey()
      Specified by:
      getKey in interface Diff.Element<byte[]>
      Returns:
      the key of this object.
    • setLocalName

      public abstract void setLocalName(byte[] name)
      Set local file name
    • getFullPathName

      public String getFullPathName()
    • isDeleted

      public boolean isDeleted()
    • getPathComponents

      public byte[][] getPathComponents()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getObjectString

      @VisibleForTesting public final String getObjectString()
    • getParentString

      @VisibleForTesting public final String getParentString()
      Returns:
      a string description of the parent.
    • getFullPathAndObjectString

      @VisibleForTesting public String getFullPathAndObjectString()
    • toDetailString

      @VisibleForTesting public String toDetailString()
    • getParent

      public final INodeDirectory getParent()
      Returns:
      the parent directory
    • getParentReference

      public INodeReference 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

      public final void setParent(INodeDirectory parent)
      Set parent directory
    • setParentReference

      public final void setParentReference(INodeReference parent)
      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:
      getModificationTime in interface INodeAttributes
      Returns:
      the modification time.
    • updateModificationTime

      public abstract INode updateModificationTime(long mtime, int latestSnapshotId)
      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

      public final INode setModificationTime(long modificationTime, int latestSnapshotId)
      Set the last modification time of inode.
    • getAccessTime

      public final long getAccessTime()
      The same as getAccessTime(Snapshot.CURRENT_STATE_ID).
      Specified by:
      getAccessTime in interface INodeAttributes
      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_UNSPECIFIED if 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 INodeSymlink we return HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED instead of throwing Exception
    • getPathComponents

      @VisibleForTesting public static byte[][] getPathComponents(String path)
      Breaks path into components.
      Returns:
      array of byte arrays each of which represents a single path component.
    • getPathNames

      public static String[] getPathNames(String path)
      Splits an absolute path into 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:
      compareTo in interface Comparable<byte[]>
    • equals

      public final boolean equals(Object that)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • dumpParentINodes

      @VisibleForTesting public final StringBuilder dumpParentINodes()
    • dumpTreeRecursively

      @VisibleForTesting public final StringBuffer dumpTreeRecursively()
      Dump the subtree starting from this inode.
      Returns:
      a text representation of the tree.
    • dumpTreeRecursively

      @VisibleForTesting public final void dumpTreeRecursively(PrintStream out)
    • 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

      public void dumpINode(PrintWriter out, StringBuilder prefix, int snapshotId)
    • accept

      public void accept(NamespaceVisitor visitor, int snapshot)
      Accept a visitor to visit this INode.