org.apache.hadoop.hdfs.server.namenode.snapshot
Class INodeDirectoryWithSnapshot

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
              extended by org.apache.hadoop.hdfs.server.namenode.INodeDirectoryWithQuota
                  extended by org.apache.hadoop.hdfs.server.namenode.snapshot.INodeDirectoryWithSnapshot
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

public class INodeDirectoryWithSnapshot
extends INodeDirectoryWithQuota

The directory with snapshots. It maintains a list of snapshot diffs for storing snapshot data. When there are modifications to the directory, the old data is stored in the latest snapshot, if there is any.


Nested Class Summary
static class INodeDirectoryWithSnapshot.DirectoryDiff
          The difference of an INodeDirectory between two snapshots.
static class INodeDirectoryWithSnapshot.DirectoryDiffList
          A list of directory diffs.
 
Nested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.namenode.INodeDirectory
INodeDirectory.SnapshotAndINode
 
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
 
Fields inherited from class org.apache.hadoop.hdfs.server.namenode.INodeDirectory
DEFAULT_FILES_PER_DIRECTORY
 
Fields inherited from class org.apache.hadoop.hdfs.server.namenode.INode
LOG
 
Constructor Summary
INodeDirectoryWithSnapshot(INodeDirectory that)
           
 
Method Summary
 boolean addChild(org.apache.hadoop.hdfs.server.namenode.INode inode, boolean setModTime, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest, INodeMap inodeMap)
          Add a child inode to the directory.
 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.
 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.
static void destroyDstSubtree(org.apache.hadoop.hdfs.server.namenode.INode inode, 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)
          Destroy a subtree under a DstReference node.
 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)
           
 INodeDirectoryWithSnapshot.DirectoryDiffList getDiffs()
           
 org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot getLastSnapshot()
           
 void getSnapshotDirectory(List<INodeDirectory> snapshotDir)
          Get all the directories that are stored in some snapshot but not in the current children list.
 org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes getSnapshotINode(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
           
 INodeDirectoryWithSnapshot recordModification(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest, INodeMap inodeMap)
          This inode is being modified.
 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.
 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.
 INodeDirectoryWithSnapshot saveSelf2Snapshot(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest, INodeDirectory snapshotCopy)
          Save the snapshot copy to the latest snapshot.
 String toDetailString()
           
 void undoRename4DstParent(org.apache.hadoop.hdfs.server.namenode.INode deletedChild, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latestSnapshot)
          Undo the rename operation for the dst tree, i.e., if the rename operation (with OVERWRITE option) removes a file/dir from the dst tree, add it back and delete possible record in the deleted list.
 void undoRename4ScrParent(INodeReference oldChild, org.apache.hadoop.hdfs.server.namenode.INode newChild, org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latestSnapshot)
          This method is usually called by the undo section of rename.
 
Methods inherited from class org.apache.hadoop.hdfs.server.namenode.INodeDirectoryWithQuota
addSpaceConsumed, addSpaceConsumed2Cache, getDiskspace, getDsQuota, getNamespace, getNsQuota, setQuota
 
Methods inherited from class org.apache.hadoop.hdfs.server.namenode.INodeDirectory
addChild, asDirectory, cleanSubtreeRecursively, clear, clearChildren, dumpTreeRecursively, dumpTreeRecursively, getChildrenNum, isDirectory, isSnapshottable, metadataEquals, removeChild, replaceSelf4INodeDirectory, replaceSelf4INodeDirectorySnapshottable, replaceSelf4INodeDirectoryWithSnapshot, valueOf
 
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
asFile, asReference, asSymlink, compareTo, computeContentSummary, computeQuotaUsage, computeQuotaUsage, dumpTreeRecursively, dumpTreeRecursively, equals, getAccessTime, getFsPermission, getFullPathName, getGroupName, getKey, getLocalName, getModificationTime, getObjectString, getParent, getParentReference, getParentString, getUserName, hashCode, isAncestorDirectory, isFile, isInLatestSnapshot, isQuotaSet, isReference, isSymlink, setAccessTime, setModificationTime, setParent, setParentReference, shouldRecordInSrcSnapshot, 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.INodeAttributes
getAccessTime, getFsPermission, getFsPermissionShort, getGroupName, getLocalNameBytes, getModificationTime, getPermissionLong, getUserName
 

Constructor Detail

INodeDirectoryWithSnapshot

public INodeDirectoryWithSnapshot(INodeDirectory that)
Method Detail

getLastSnapshot

public org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot getLastSnapshot()
Returns:
the last snapshot.

getDiffs

public INodeDirectoryWithSnapshot.DirectoryDiffList getDiffs()
Returns:
the snapshot diff list.

getSnapshotINode

public org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes getSnapshotINode(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
Overrides:
getSnapshotINode in class org.apache.hadoop.hdfs.server.namenode.INode
Returns:
if the given snapshot is null, return this; otherwise return the corresponding snapshot inode.

recordModification

public INodeDirectoryWithSnapshot 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.

Overrides:
recordModification in class INodeDirectory
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

saveSelf2Snapshot

public INodeDirectoryWithSnapshot saveSelf2Snapshot(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latest,
                                                    INodeDirectory snapshotCopy)
                                             throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Save the snapshot copy to the latest snapshot.

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
Description copied from class: INodeDirectory
Save the child to the latest snapshot.

Overrides:
saveChild2Snapshot in class INodeDirectory
Returns:
the child inode, which may be replaced.
Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException

addChild

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

Overrides:
addChild in class INodeDirectory
Parameters:
inode - 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

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
Description copied from class: INodeDirectory
Remove the specified child from this directory.

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

replaceChild

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

Overrides:
replaceChild in class INodeDirectory

undoRename4ScrParent

public void undoRename4ScrParent(INodeReference oldChild,
                                 org.apache.hadoop.hdfs.server.namenode.INode newChild,
                                 org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latestSnapshot)
                          throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
This method is usually called by the undo section of rename. Before calling this function, in the rename operation, we replace the original src node (of the rename operation) with a reference node (WithName instance) in both the children list and a created list, delete the reference node from the children list, and add it to the corresponding deleted list. To undo the above operations, we have the following steps in particular:
 1) remove the WithName node from the deleted list (if it exists) 
 2) replace the WithName node in the created list with srcChild 
 3) add srcChild back as a child of srcParent. Note that we already add 
 the node into the created list of a snapshot diff in step 2, we do not need
 to add srcChild to the created list of the latest snapshot.
 
We do not need to update quota usage because the old child is in the deleted list before.

Parameters:
oldChild - The reference node to be removed/replaced
newChild - The node to be added back
latestSnapshot - The latest snapshot. Note this may not be the last snapshot in the diffs, since the src tree of the current rename operation may be the dst tree of a previous rename.
Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException - should not throw this exception

undoRename4DstParent

public void undoRename4DstParent(org.apache.hadoop.hdfs.server.namenode.INode deletedChild,
                                 org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot latestSnapshot)
                          throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Undo the rename operation for the dst tree, i.e., if the rename operation (with OVERWRITE option) removes a file/dir from the dst tree, add it back and delete possible record in the deleted list.

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

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)
Overrides:
getChildrenList in class INodeDirectory
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.

getChild

public org.apache.hadoop.hdfs.server.namenode.INode getChild(byte[] name,
                                                             org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot snapshot)
Overrides:
getChild in class INodeDirectory
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.

toDetailString

public String toDetailString()
Overrides:
toDetailString in class org.apache.hadoop.hdfs.server.namenode.INode

getSnapshotDirectory

public void getSnapshotDirectory(List<INodeDirectory> snapshotDir)
Get all the directories that are stored in some snapshot but not in the current children list. These directories are equivalent to the directories stored in the deletes lists.


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.
 

Overrides:
cleanSubtree in class INodeDirectory
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

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.

Overrides:
destroyAndCollectBlocks in class INodeDirectory
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

computeQuotaUsage

public final 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.  
 

Overrides:
computeQuotaUsage in class INodeDirectoryWithQuota
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)
Description copied from class: INodeDirectory
Add quota usage for this inode excluding children.

Overrides:
computeQuotaUsage4CurrentDirectory in class INodeDirectory

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.

Overrides:
computeContentSummary in class INodeDirectoryWithQuota
Parameters:
counts - The subtree counts for returning.
Returns:
The same objects as the counts parameter.

destroyDstSubtree

public static void destroyDstSubtree(org.apache.hadoop.hdfs.server.namenode.INode inode,
                                     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)
                              throws org.apache.hadoop.hdfs.protocol.QuotaExceededException
Destroy a subtree under a DstReference node.

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


Copyright © 2013 Apache Software Foundation. All Rights Reserved.