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

java.lang.Object
  extended by org.apache.hadoop.hdfs.server.namenode.INode
      extended by org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields
          extended by org.apache.hadoop.hdfs.server.namenode.INodeDirectory
All Implemented Interfaces:
Comparable<byte[]>, org.apache.hadoop.hdfs.server.namenode.INodeAttributes, org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes, Diff.Element<byte[]>, org.apache.hadoop.util.LightWeightGSet.LinkedElement
Direct Known Subclasses:
INodeDirectoryWithQuota, Snapshot.Root

public class INodeDirectory
extends org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields
implements org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes

Directory INode class.


Nested Class Summary
protected static class INodeDirectory.SnapshotAndINode
          A pair of Snapshot and INode objects.
 
Nested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.namenode.INode
INode.BlocksMapUpdateInfo
 
Nested classes/interfaces inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes
INodeDirectoryAttributes.CopyWithQuota, INodeDirectoryAttributes.SnapshotCopy
 
Field Summary
protected static int DEFAULT_FILES_PER_DIRECTORY
           
 
Fields inherited from class org.apache.hadoop.hdfs.server.namenode.INode
LOG
 
Constructor Summary
INodeDirectory(INodeDirectory other, boolean adopt)
          Copy constructor
INodeDirectory(long id, byte[] name, org.apache.hadoop.fs.permission.PermissionStatus permissions, long mtime)
          constructor
 
Method Summary
 boolean addChild(org.apache.hadoop.hdfs.server.namenode.INode node)
          The same as addChild(node, false, null, false)
 boolean addChild(org.apache.hadoop.hdfs.server.namenode.INode node, boolean setModTime, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest, INodeMap inodeMap)
          Add a child inode to the directory.
 INodeDirectory asDirectory()
          Cast this inode to an INodeDirectory.
 Quota.Counts cleanSubtree(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot 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.
 Quota.Counts cleanSubtreeRecursively(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot prior, INode.BlocksMapUpdateInfo collectedBlocks, List<org.apache.hadoop.hdfs.server.namenode.INode> removedINodes, Map<org.apache.hadoop.hdfs.server.namenode.INode,org.apache.hadoop.hdfs.server.namenode.INode> excludedNodes, boolean countDiffChange)
          Call cleanSubtree(..) recursively down the subtree.
 void clear()
          Clear references to other objects.
 void clearChildren()
          Set the children list to null.
 Content.Counts computeContentSummary(Content.Counts counts)
          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.
 Quota.Counts computeQuotaUsage4CurrentDirectory(Quota.Counts counts)
          Add quota usage for this inode excluding children.
 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.
protected static void dumpTreeRecursively(PrintWriter out, StringBuilder prefix, Iterable<INodeDirectory.SnapshotAndINode> subs)
          Dump the given subtrees.
 void dumpTreeRecursively(PrintWriter out, StringBuilder prefix, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
          Dump tree recursively.
 org.apache.hadoop.hdfs.server.namenode.INode getChild(byte[] name, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
           
 org.apache.hadoop.hdfs.util.ReadOnlyList<org.apache.hadoop.hdfs.server.namenode.INode> getChildrenList(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
           
 int getChildrenNum(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
           
 boolean isDirectory()
          Check whether it's a directory
 boolean isSnapshottable()
          Is this a snapshottable directory?
 boolean metadataEquals(org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes other)
          Compare the metadata with another INodeDirectory
 INodeDirectory recordModification(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest, INodeMap inodeMap)
          This inode is being modified.
protected  boolean removeChild(org.apache.hadoop.hdfs.server.namenode.INode child)
          Remove the specified child from this directory.
 boolean removeChild(org.apache.hadoop.hdfs.server.namenode.INode child, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest, INodeMap inodeMap)
          Remove the specified child from this directory.
 void replaceChild(org.apache.hadoop.hdfs.server.namenode.INode oldChild, org.apache.hadoop.hdfs.server.namenode.INode newChild, INodeMap inodeMap)
          Replace the given child with a new child.
 INodeDirectory replaceSelf4INodeDirectory(INodeMap inodeMap)
          Replace itself with INodeDirectory.
 org.apache.hadoop.hdfs.server.namenode.snapshot.INodeDirectorySnapshottable replaceSelf4INodeDirectorySnapshottable(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest, INodeMap inodeMap)
          Replace itself with an INodeDirectorySnapshottable.
 INodeDirectoryWithSnapshot replaceSelf4INodeDirectoryWithSnapshot(INodeMap inodeMap)
          Replace itself with an INodeDirectoryWithSnapshot.
 org.apache.hadoop.hdfs.server.namenode.INode saveChild2Snapshot(org.apache.hadoop.hdfs.server.namenode.INode child, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest, org.apache.hadoop.hdfs.server.namenode.INode snapshotCopy, INodeMap inodeMap)
          Save the child to the latest snapshot.
static INodeDirectory valueOf(org.apache.hadoop.hdfs.server.namenode.INode inode, Object path)
          Cast INode to INodeDirectory.
 
Methods inherited from class org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields
getFsPermissionShort, getId, getLocalNameBytes, getNext, getPermissionLong, setAccessTime, setLocalName, setModificationTime, setNext, updateModificationTime
 
Methods inherited from class org.apache.hadoop.hdfs.server.namenode.INode
addSpaceConsumed, asFile, asReference, asSymlink, compareTo, computeContentSummary, computeQuotaUsage, computeQuotaUsage, dumpTreeRecursively, dumpTreeRecursively, equals, getAccessTime, getDsQuota, getFsPermission, getFullPathName, getGroupName, getKey, getLocalName, getModificationTime, getNsQuota, getObjectString, getParent, getParentReference, getParentString, getSnapshotINode, getUserName, hashCode, isAncestorDirectory, isFile, isInLatestSnapshot, isQuotaSet, isReference, isSymlink, setAccessTime, setModificationTime, setParent, setParentReference, shouldRecordInSrcSnapshot, toDetailString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes
getDsQuota, getNsQuota
 
Methods inherited from interface org.apache.hadoop.hdfs.server.namenode.INodeAttributes
getAccessTime, getFsPermission, getFsPermissionShort, getGroupName, getLocalNameBytes, getModificationTime, getPermissionLong, getUserName
 

Field Detail

DEFAULT_FILES_PER_DIRECTORY

protected static final int DEFAULT_FILES_PER_DIRECTORY
See Also:
Constant Field Values
Constructor Detail

INodeDirectory

public INodeDirectory(long id,
                      byte[] name,
                      org.apache.hadoop.fs.permission.PermissionStatus permissions,
                      long mtime)
constructor


INodeDirectory

public INodeDirectory(INodeDirectory other,
                      boolean adopt)
Copy constructor

Parameters:
other - The INodeDirectory to be copied
adopt - Indicate whether or not need to set the parent field of child INodes to the new node
Method Detail

valueOf

public static INodeDirectory valueOf(org.apache.hadoop.hdfs.server.namenode.INode inode,
                                     Object path)
                              throws FileNotFoundException,
                                     org.apache.hadoop.fs.PathIsNotDirectoryException
Cast INode to INodeDirectory.

Throws:
FileNotFoundException
org.apache.hadoop.fs.PathIsNotDirectoryException

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
Returns:
true unconditionally.

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
Returns:
this object.

isSnapshottable

public boolean isSnapshottable()
Is this a snapshottable directory?


removeChild

public boolean removeChild(org.apache.hadoop.hdfs.server.namenode.INode child,
                           org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest,
                           INodeMap inodeMap)
                    throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Remove the specified child from this directory.

Parameters:
child - the child inode to be removed
latest - See recordModification(Snapshot, INodeMap).
Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException

removeChild

protected final boolean removeChild(org.apache.hadoop.hdfs.server.namenode.INode child)
Remove the specified child from this directory. The basic remove method which actually calls children.remove(..).

Parameters:
child - the child inode to be removed
Returns:
true if the child is removed; false if the child is not found.

replaceSelf4INodeDirectorySnapshottable

public org.apache.hadoop.hdfs.server.namenode.snapshot.INodeDirectorySnapshottable replaceSelf4INodeDirectorySnapshottable(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest,
                                                                                                                           INodeMap inodeMap)
                                                                                                                    throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Replace itself with an INodeDirectorySnapshottable.

Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException

replaceSelf4INodeDirectoryWithSnapshot

public INodeDirectoryWithSnapshot replaceSelf4INodeDirectoryWithSnapshot(INodeMap inodeMap)
Replace itself with an INodeDirectoryWithSnapshot.


replaceSelf4INodeDirectory

public INodeDirectory replaceSelf4INodeDirectory(INodeMap inodeMap)
Replace itself with INodeDirectory.


replaceChild

public void replaceChild(org.apache.hadoop.hdfs.server.namenode.INode oldChild,
                         org.apache.hadoop.hdfs.server.namenode.INode newChild,
                         INodeMap inodeMap)
Replace the given child with a new child.


recordModification

public INodeDirectory recordModification(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest,
                                         INodeMap inodeMap)
                                  throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Description copied from class: org.apache.hadoop.hdfs.server.namenode.INode
This inode is being modified. The previous version of the inode needs to be recorded in the latest snapshot.

Specified by:
recordModification in class org.apache.hadoop.hdfs.server.namenode.INode
Parameters:
latest - the latest snapshot that has been taken. Note that it is null if no snapshots have been taken.
inodeMap - while recording modification, the inode or its parent may get replaced, and the inodeMap needs to be updated.
Returns:
The current inode, which usually is the same object of this inode. However, in some cases, this inode may be replaced with a new inode for maintaining snapshots. The current inode is then the new inode.
Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException

saveChild2Snapshot

public org.apache.hadoop.hdfs.server.namenode.INode saveChild2Snapshot(org.apache.hadoop.hdfs.server.namenode.INode child,
                                                                       org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest,
                                                                       org.apache.hadoop.hdfs.server.namenode.INode snapshotCopy,
                                                                       INodeMap inodeMap)
                                                                throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Save the child to the latest snapshot.

Returns:
the child inode, which may be replaced.
Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException

getChild

public org.apache.hadoop.hdfs.server.namenode.INode getChild(byte[] name,
                                                             org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
Parameters:
name - the name of the child
snapshot - if it is not null, get the result from the given snapshot; otherwise, get the result from the current directory.
Returns:
the child inode.

addChild

public boolean addChild(org.apache.hadoop.hdfs.server.namenode.INode node,
                        boolean setModTime,
                        org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest,
                        INodeMap inodeMap)
                 throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Add a child inode to the directory.

Parameters:
node - INode to insert
setModTime - set modification time for the parent node not needed when replaying the addition and the parent already has the proper mod time
inodeMap - update the inodeMap if the directory node gets replaced
Returns:
false if the child with this name already exists; otherwise, return true;
Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException

addChild

public boolean addChild(org.apache.hadoop.hdfs.server.namenode.INode node)
The same as addChild(node, false, null, false)


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.INVALID_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.

computeQuotaUsage4CurrentDirectory

public Quota.Counts computeQuotaUsage4CurrentDirectory(Quota.Counts counts)
Add quota usage for this inode excluding children.


computeContentSummary

public Content.Counts computeContentSummary(Content.Counts counts)
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:
counts - The subtree counts for returning.
Returns:
The same objects as the counts parameter.

getChildrenList

public org.apache.hadoop.hdfs.util.ReadOnlyList<org.apache.hadoop.hdfs.server.namenode.INode> getChildrenList(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
Parameters:
snapshot - if it is not null, get the result from the given snapshot; otherwise, get the result from the current directory.
Returns:
the current children list if the specified snapshot is null; otherwise, return the children list corresponding to the snapshot. Note that the returned list is never null.

clearChildren

public void clearChildren()
Set the children list to null.


clear

public 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

cleanSubtreeRecursively

public Quota.Counts cleanSubtreeRecursively(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot,
                                            org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot prior,
                                            INode.BlocksMapUpdateInfo collectedBlocks,
                                            List<org.apache.hadoop.hdfs.server.namenode.INode> removedINodes,
                                            Map<org.apache.hadoop.hdfs.server.namenode.INode,org.apache.hadoop.hdfs.server.namenode.INode> excludedNodes,
                                            boolean countDiffChange)
                                     throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Call cleanSubtree(..) recursively down the subtree.

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

cleanSubtree

public Quota.Counts cleanSubtree(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot,
                                 org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot 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 FileWithSnapshot.
 Call recordModification(..) to capture the current states.
 Mark the INode as deleted.
 
 1.4 The current inode is a INodeDirectoryWithSnapshot.
 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 FileWithSnapshot: delete the corresponding snapshot in
 its diff list.
 2.4 To clean INodeDirectoryWithSnapshot: 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 snapshot to delete. Null means to delete the current file/directory.
prior - 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

metadataEquals

public boolean metadataEquals(org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes other)
Compare the metadata with another INodeDirectory

Specified by:
metadataEquals in interface org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes

dumpTreeRecursively

public void dumpTreeRecursively(PrintWriter out,
                                StringBuilder prefix,
                                org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot 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.

dumpTreeRecursively

protected static void dumpTreeRecursively(PrintWriter out,
                                          StringBuilder prefix,
                                          Iterable<INodeDirectory.SnapshotAndINode> subs)
Dump the given subtrees.

Parameters:
prefix - The prefix string that each line should print.
subs - The subtrees.

getChildrenNum

public final int getChildrenNum(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)


Copyright © 2013 Apache Software Foundation. All Rights Reserved.