org.apache.hadoop.hdfs.server.namenode
Class INodeReference

java.lang.Object
  extended by org.apache.hadoop.hdfs.server.namenode.INode
      extended by org.apache.hadoop.hdfs.server.namenode.INodeReference
All Implemented Interfaces:
Comparable<byte[]>, org.apache.hadoop.hdfs.server.namenode.INodeAttributes, Diff.Element<byte[]>
Direct Known Subclasses:
INodeReference.DstReference, INodeReference.WithCount, INodeReference.WithName

public abstract class INodeReference
extends org.apache.hadoop.hdfs.server.namenode.INode

An anonymous reference to an inode. 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, say the inode of foo is inode(id=1000,name=foo) (2) create snapshot s0 for /abc (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 and /abc/.snapshot/s0/foo are two different access paths to the same inode, inode(id=1000,name=bar). With references, we have the following - /abc has a child ref(id=1001,name=foo). - /xyz has a child ref(id=1002) - Both ref(id=1001,name=foo) and ref(id=1002) point to another reference, ref(id=1003,count=2). - Finally, ref(id=1003,count=2) points to inode(id=1000,name=bar). Note 1: For a reference without name, e.g. ref(id=1002), it uses the name of the referred inode. Note 2: getParent() always returns the parent in the current state, e.g. inode(id=1000,name=bar).getParent() returns /xyz but not /abc.


Nested Class Summary
static class INodeReference.DstReference
           
static class INodeReference.WithCount
          An anonymous reference with reference count.
static class INodeReference.WithName
          A reference with a fixed name.
 
Nested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.namenode.INode
INode.BlocksMapUpdateInfo, INode.Feature
 
Nested classes/interfaces inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeAttributes
INodeAttributes.SnapshotCopy
 
Field Summary
 
Fields inherited from class org.apache.hadoop.hdfs.server.namenode.INode
LOG
 
Constructor Summary
INodeReference(org.apache.hadoop.hdfs.server.namenode.INode parent, org.apache.hadoop.hdfs.server.namenode.INode referred)
           
 
Method Summary
 INodeDirectory asDirectory()
          Cast this inode to an INodeDirectory.
 org.apache.hadoop.hdfs.server.namenode.INodeFile asFile()
          Cast this inode to an INodeFile.
 INodeReference asReference()
          Cast this inode to an INodeReference.
 org.apache.hadoop.hdfs.server.namenode.INodeSymlink asSymlink()
          Cast this inode to an INodeSymlink.
 Quota.Counts cleanSubtree(int snapshot, int prior, INode.BlocksMapUpdateInfo collectedBlocks, List<org.apache.hadoop.hdfs.server.namenode.INode> removedINodes, boolean countDiffChange)
          Clean the subtree under this inode and collect the blocks from the descents for further block deletion/update.
 void clear()
          Clear references to other objects.
 org.apache.hadoop.hdfs.server.namenode.ContentSummaryComputationContext computeContentSummary(org.apache.hadoop.hdfs.server.namenode.ContentSummaryComputationContext summary)
          Count subtree content summary with a Content.Counts.
 Quota.Counts computeQuotaUsage(Quota.Counts counts, boolean useCache, int lastSnapshotId)
          Count subtree Quota.NAMESPACE and Quota.DISKSPACE usages.
 void destroyAndCollectBlocks(INode.BlocksMapUpdateInfo collectedBlocks, List<org.apache.hadoop.hdfs.server.namenode.INode> removedINodes)
          Destroy self and clear everything! If the INode is a file, this method collects its blocks for further block deletion.
 void dumpTreeRecursively(PrintWriter out, StringBuilder prefix, int snapshot)
          Dump tree recursively.
 long getAccessTime(int snapshotId)
           
 int getDstSnapshotId()
           
 org.apache.hadoop.fs.permission.FsPermission getFsPermission(int snapshotId)
           
 short getFsPermissionShort()
           
 String getGroupName(int snapshotId)
           
 long getId()
          Get inode id
 byte[] getLocalNameBytes()
           
 byte getLocalStoragePolicyID()
           
 long getModificationTime(int snapshotId)
           
 long getPermissionLong()
           
 org.apache.hadoop.fs.permission.PermissionStatus getPermissionStatus(int snapshotId)
          Get the PermissionStatus
 Quota.Counts getQuotaCounts()
          Get the quota set for this inode
 org.apache.hadoop.hdfs.server.namenode.INode getReferredINode()
           
 org.apache.hadoop.hdfs.server.namenode.INodeAttributes getSnapshotINode(int snapshotId)
           
 byte getStoragePolicyID()
           
 String getUserName(int snapshotId)
           
 boolean isDirectory()
          Check whether it's a directory
 boolean isFile()
          Check whether it's a file.
 boolean isReference()
          Check whether it's a reference.
 boolean isSymlink()
          Check whether it's a symlink
 void setAccessTime(long accessTime)
          Set last access time of inode.
 void setLocalName(byte[] name)
          Set local file name
 void setModificationTime(long modificationTime)
          Set the last modification time of inode.
 void setReferredINode(org.apache.hadoop.hdfs.server.namenode.INode referred)
           
static int tryRemoveReference(org.apache.hadoop.hdfs.server.namenode.INode inode)
          Try to remove the given reference and then return the reference count.
 org.apache.hadoop.hdfs.server.namenode.INode updateModificationTime(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, dumpTreeRecursively, dumpTreeRecursively, equals, getAccessTime, getAclFeature, getFsPermission, getFullPathName, getGroupName, getKey, getLocalName, getModificationTime, getObjectString, getParent, getParentReference, getParentString, getPathComponents, getPathNames, getUserName, getXAttrFeature, hashCode, isAncestorDirectory, isInLatestSnapshot, isQuotaSet, setAccessTime, setModificationTime, setParent, setParentReference, shouldRecordInSrcSnapshot, toDetailString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

INodeReference

public INodeReference(org.apache.hadoop.hdfs.server.namenode.INode parent,
                      org.apache.hadoop.hdfs.server.namenode.INode referred)
Method Detail

tryRemoveReference

public static int tryRemoveReference(org.apache.hadoop.hdfs.server.namenode.INode inode)
Try to remove the given reference and then return the reference count. If the given inode is not a reference, return -1;


getReferredINode

public final org.apache.hadoop.hdfs.server.namenode.INode getReferredINode()

setReferredINode

public final void setReferredINode(org.apache.hadoop.hdfs.server.namenode.INode referred)

isReference

public final boolean isReference()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Check whether it's a reference.

Overrides:
isReference in class org.apache.hadoop.hdfs.server.namenode.INode

asReference

public final INodeReference asReference()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Cast this inode to an INodeReference.

Overrides:
asReference in class org.apache.hadoop.hdfs.server.namenode.INode

isFile

public final boolean isFile()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Check whether it's a file.

Overrides:
isFile in class org.apache.hadoop.hdfs.server.namenode.INode

asFile

public final org.apache.hadoop.hdfs.server.namenode.INodeFile asFile()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Cast this inode to an INodeFile.

Overrides:
asFile in class org.apache.hadoop.hdfs.server.namenode.INode

isDirectory

public final boolean isDirectory()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Check whether it's a directory

Overrides:
isDirectory in class org.apache.hadoop.hdfs.server.namenode.INode

asDirectory

public final INodeDirectory asDirectory()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Cast this inode to an INodeDirectory.

Overrides:
asDirectory in class org.apache.hadoop.hdfs.server.namenode.INode

isSymlink

public final boolean isSymlink()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Check whether it's a symlink

Overrides:
isSymlink in class org.apache.hadoop.hdfs.server.namenode.INode

asSymlink

public final org.apache.hadoop.hdfs.server.namenode.INodeSymlink asSymlink()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Cast this inode to an INodeSymlink.

Overrides:
asSymlink in class org.apache.hadoop.hdfs.server.namenode.INode

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: org.apache.hadoop.hdfs.server.namenode.INode
Set local file name

Specified by:
setLocalName in class org.apache.hadoop.hdfs.server.namenode.INode

getId

public final long getId()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Get inode id

Specified by:
getId in class org.apache.hadoop.hdfs.server.namenode.INode

getPermissionStatus

public final org.apache.hadoop.fs.permission.PermissionStatus getPermissionStatus(int snapshotId)
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Get the PermissionStatus

Specified by:
getPermissionStatus in class org.apache.hadoop.hdfs.server.namenode.INode

getUserName

public final String getUserName(int snapshotId)
Specified by:
getUserName in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
snapshotId - if it is not Snapshot.CURRENT_STATE_ID, get the result from the given snapshot; otherwise, get the result from the current inode.
Returns:
user name

getGroupName

public final String getGroupName(int snapshotId)
Specified by:
getGroupName in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
snapshotId - if it is not Snapshot.CURRENT_STATE_ID, get the result from the given snapshot; otherwise, get the result from the current inode.
Returns:
group name

getFsPermission

public final org.apache.hadoop.fs.permission.FsPermission getFsPermission(int snapshotId)
Specified by:
getFsPermission in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
snapshotId - if it is not Snapshot.CURRENT_STATE_ID, get the result from the given snapshot; otherwise, get the result from the current inode.
Returns:
permission.

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)
Specified by:
getModificationTime in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
snapshotId - if it is not Snapshot.CURRENT_STATE_ID, get the result from the given snapshot; otherwise, get the result from the current inode.
Returns:
modification time.

updateModificationTime

public final org.apache.hadoop.hdfs.server.namenode.INode updateModificationTime(long mtime,
                                                                                 int latestSnapshotId)
                                                                          throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Update modification time if it is larger than the current value.

Specified by:
updateModificationTime in class org.apache.hadoop.hdfs.server.namenode.INode
Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException

setModificationTime

public final void setModificationTime(long modificationTime)
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Set the last modification time of inode.

Specified by:
setModificationTime in class org.apache.hadoop.hdfs.server.namenode.INode

getAccessTime

public final long getAccessTime(int snapshotId)
Specified by:
getAccessTime in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
snapshotId - if it is not Snapshot.CURRENT_STATE_ID, get the result from the given snapshot; otherwise, get the result from the current inode.
Returns:
access time

setAccessTime

public final void setAccessTime(long accessTime)
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Set last access time of inode.

Specified by:
setAccessTime in class org.apache.hadoop.hdfs.server.namenode.INode

getStoragePolicyID

public final byte getStoragePolicyID()
Specified by:
getStoragePolicyID in class org.apache.hadoop.hdfs.server.namenode.INode
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:
getLocalStoragePolicyID in class org.apache.hadoop.hdfs.server.namenode.INode
Returns:
the storage policy directly specified on the INode. Return BlockStoragePolicySuite.ID_UNSPECIFIED if no policy has been specified.

cleanSubtree

public Quota.Counts cleanSubtree(int snapshot,
                                 int prior,
                                 INode.BlocksMapUpdateInfo collectedBlocks,
                                 List<org.apache.hadoop.hdfs.server.namenode.INode> removedINodes,
                                 boolean countDiffChange)
                          throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
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.
 

Specified by:
cleanSubtree in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
snapshot - The id of the snapshot to delete. Snapshot.CURRENT_STATE_ID means 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.
collectedBlocks - blocks collected from the descents for further block deletion/update will be added to the given map.
removedINodes - INodes collected from the descents for further cleaning up of inodeMap
Returns:
quota usage delta when deleting a snapshot
Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException

destroyAndCollectBlocks

public void destroyAndCollectBlocks(INode.BlocksMapUpdateInfo collectedBlocks,
                                    List<org.apache.hadoop.hdfs.server.namenode.INode> removedINodes)
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
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.

Specified by:
destroyAndCollectBlocks in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
collectedBlocks - blocks collected from the descents for further block deletion/update will be added to this map.
removedINodes - INodes collected from the descents for further cleaning up of inodeMap

computeContentSummary

public org.apache.hadoop.hdfs.server.namenode.ContentSummaryComputationContext computeContentSummary(org.apache.hadoop.hdfs.server.namenode.ContentSummaryComputationContext summary)
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Count subtree content summary with a Content.Counts.

Specified by:
computeContentSummary in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
summary - the context object holding counts for the subtree.
Returns:
The same objects as summary.

computeQuotaUsage

public Quota.Counts computeQuotaUsage(Quota.Counts counts,
                                      boolean useCache,
                                      int lastSnapshotId)
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Count subtree Quota.NAMESPACE and Quota.DISKSPACE 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.  
 

Specified by:
computeQuotaUsage in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
counts - The subtree counts for returning.
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 same objects as the counts parameter.

getSnapshotINode

public final org.apache.hadoop.hdfs.server.namenode.INodeAttributes getSnapshotINode(int snapshotId)
Overrides:
getSnapshotINode in class org.apache.hadoop.hdfs.server.namenode.INode
Returns:
if the given snapshot id is Snapshot.CURRENT_STATE_ID, return this; otherwise return the corresponding snapshot inode.

getQuotaCounts

public Quota.Counts getQuotaCounts()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Get the quota set for this inode

Overrides:
getQuotaCounts in class org.apache.hadoop.hdfs.server.namenode.INode
Returns:
the quota counts. The count is -1 if it is not set.

clear

public final void clear()
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Clear references to other objects.

Overrides:
clear in class org.apache.hadoop.hdfs.server.namenode.INode

dumpTreeRecursively

public void dumpTreeRecursively(PrintWriter out,
                                StringBuilder prefix,
                                int snapshot)
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
Dump tree recursively.

Overrides:
dumpTreeRecursively in class org.apache.hadoop.hdfs.server.namenode.INode
prefix - The prefix string that each line should print.

getDstSnapshotId

public int getDstSnapshotId()


Copyright © 2014 Apache Software Foundation. All Rights Reserved.