You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by cn...@apache.org on 2014/01/09 00:10:04 UTC
svn commit: r1556665 [2/3] - in
/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project:
hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/ hadoop-hdfs/
hadoop-hdfs/src/main/java/
hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockm...
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java Wed Jan 8 23:10:02 2014
@@ -204,9 +204,9 @@ public class INodeDirectory extends INod
}
@Override
- public INodeDirectoryAttributes getSnapshotINode(Snapshot snapshot) {
+ public INodeDirectoryAttributes getSnapshotINode(int snapshotId) {
DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature();
- return sf == null ? this : sf.getDiffs().getSnapshotINode(snapshot, this);
+ return sf == null ? this : sf.getDiffs().getSnapshotINode(snapshotId, this);
}
@Override
@@ -217,12 +217,13 @@ public class INodeDirectory extends INod
/** Replace itself with an {@link INodeDirectorySnapshottable}. */
public INodeDirectorySnapshottable replaceSelf4INodeDirectorySnapshottable(
- Snapshot latest, final INodeMap inodeMap) throws QuotaExceededException {
+ int latestSnapshotId, final INodeMap inodeMap)
+ throws QuotaExceededException {
Preconditions.checkState(!(this instanceof INodeDirectorySnapshottable),
"this is already an INodeDirectorySnapshottable, this=%s", this);
final INodeDirectorySnapshottable s = new INodeDirectorySnapshottable(this);
replaceSelf(s, inodeMap).getDirectoryWithSnapshotFeature().getDiffs()
- .saveSelf2Snapshot(latest, s, this);
+ .saveSelf2Snapshot(latestSnapshotId, s, this);
return s;
}
@@ -289,8 +290,8 @@ public class INodeDirectory extends INod
}
INodeReference.WithName replaceChild4ReferenceWithName(INode oldChild,
- Snapshot latest) {
- Preconditions.checkArgument(latest != null);
+ int latestSnapshotId) {
+ Preconditions.checkArgument(latestSnapshotId != Snapshot.CURRENT_STATE_ID);
if (oldChild instanceof INodeReference.WithName) {
return (INodeReference.WithName)oldChild;
}
@@ -304,22 +305,23 @@ public class INodeDirectory extends INod
withCount = new INodeReference.WithCount(null, oldChild);
}
final INodeReference.WithName ref = new INodeReference.WithName(this,
- withCount, oldChild.getLocalNameBytes(), latest.getId());
+ withCount, oldChild.getLocalNameBytes(), latestSnapshotId);
replaceChild(oldChild, ref, null);
return ref;
}
@Override
- public INodeDirectory recordModification(Snapshot latest)
+ public INodeDirectory recordModification(int latestSnapshotId)
throws QuotaExceededException {
- if (isInLatestSnapshot(latest) && !shouldRecordInSrcSnapshot(latest)) {
+ if (isInLatestSnapshot(latestSnapshotId)
+ && !shouldRecordInSrcSnapshot(latestSnapshotId)) {
// add snapshot feature if necessary
DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature();
if (sf == null) {
sf = addSnapshotFeature(null);
}
// record self in the diff list if necessary
- sf.getDiffs().saveSelf2Snapshot(latest, this, null);
+ sf.getDiffs().saveSelf2Snapshot(latestSnapshotId, this, null);
}
return this;
}
@@ -329,9 +331,9 @@ public class INodeDirectory extends INod
*
* @return the child inode, which may be replaced.
*/
- public INode saveChild2Snapshot(final INode child, final Snapshot latest,
+ public INode saveChild2Snapshot(final INode child, final int latestSnapshotId,
final INode snapshotCopy) throws QuotaExceededException {
- if (latest == null) {
+ if (latestSnapshotId == Snapshot.CURRENT_STATE_ID) {
return child;
}
@@ -340,42 +342,45 @@ public class INodeDirectory extends INod
if (sf == null) {
sf = this.addSnapshotFeature(null);
}
- return sf.saveChild2Snapshot(this, child, latest, snapshotCopy);
+ return sf.saveChild2Snapshot(this, child, latestSnapshotId, snapshotCopy);
}
/**
* @param name the name of the child
- * @param snapshot
- * if it is not null, get the result from the given snapshot;
- * otherwise, get the result from the current directory.
+ * @param snapshotId
+ * if it is not {@link Snapshot#CURRENT_STATE_ID}, get the result
+ * from the corresponding snapshot; otherwise, get the result from
+ * the current directory.
* @return the child inode.
*/
- public INode getChild(byte[] name, Snapshot snapshot) {
+ public INode getChild(byte[] name, int snapshotId) {
DirectoryWithSnapshotFeature sf;
- if (snapshot == null || (sf = getDirectoryWithSnapshotFeature()) == null) {
+ if (snapshotId == Snapshot.CURRENT_STATE_ID ||
+ (sf = getDirectoryWithSnapshotFeature()) == null) {
ReadOnlyList<INode> c = getCurrentChildrenList();
final int i = ReadOnlyList.Util.binarySearch(c, name);
return i < 0 ? null : c.get(i);
}
- return sf.getChild(this, name, snapshot);
+ return sf.getChild(this, name, snapshotId);
}
/**
- * @param snapshot
- * if it is not null, get the result from the given snapshot;
- * otherwise, get the result from the current directory.
+ * @param snapshotId
+ * if it is not {@link Snapshot#CURRENT_STATE_ID}, get the result
+ * from the corresponding snapshot; otherwise, get the result from
+ * the current directory.
* @return 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.
*/
- public ReadOnlyList<INode> getChildrenList(final Snapshot snapshot) {
+ public ReadOnlyList<INode> getChildrenList(final int snapshotId) {
DirectoryWithSnapshotFeature sf;
- if (snapshot == null
+ if (snapshotId == Snapshot.CURRENT_STATE_ID
|| (sf = this.getDirectoryWithSnapshotFeature()) == null) {
return getCurrentChildrenList();
}
- return sf.getChildrenList(this, snapshot);
+ return sf.getChildrenList(this, snapshotId);
}
private ReadOnlyList<INode> getCurrentChildrenList() {
@@ -450,15 +455,15 @@ public class INodeDirectory extends INod
/**
* Remove the specified child from this directory.
*/
- public boolean removeChild(INode child, Snapshot latest)
+ public boolean removeChild(INode child, int latestSnapshotId)
throws QuotaExceededException {
- if (isInLatestSnapshot(latest)) {
+ if (isInLatestSnapshot(latestSnapshotId)) {
// create snapshot feature if necessary
DirectoryWithSnapshotFeature sf = this.getDirectoryWithSnapshotFeature();
if (sf == null) {
sf = this.addSnapshotFeature(null);
}
- return sf.removeChild(this, child, latest);
+ return sf.removeChild(this, child, latestSnapshotId);
}
return removeChild(child);
}
@@ -493,24 +498,24 @@ public class INodeDirectory extends INod
* otherwise, return true;
*/
public boolean addChild(INode node, final boolean setModTime,
- final Snapshot latest) throws QuotaExceededException {
+ final int latestSnapshotId) throws QuotaExceededException {
final int low = searchChildren(node.getLocalNameBytes());
if (low >= 0) {
return false;
}
- if (isInLatestSnapshot(latest)) {
+ if (isInLatestSnapshot(latestSnapshotId)) {
// create snapshot feature if necessary
DirectoryWithSnapshotFeature sf = this.getDirectoryWithSnapshotFeature();
if (sf == null) {
sf = this.addSnapshotFeature(null);
}
- return sf.addChild(this, node, setModTime, latest);
+ return sf.addChild(this, node, setModTime, latestSnapshotId);
}
addChild(node, low);
if (setModTime) {
// update modification time of the parent directory
- updateModificationTime(node.getModificationTime(), latest);
+ updateModificationTime(node.getModificationTime(), latestSnapshotId);
}
return true;
}
@@ -548,10 +553,9 @@ public class INodeDirectory extends INod
// we are computing the quota usage for a specific snapshot here, i.e., the
// computation only includes files/directories that exist at the time of the
// given snapshot
- if (sf != null && lastSnapshotId != Snapshot.INVALID_ID
+ if (sf != null && lastSnapshotId != Snapshot.CURRENT_STATE_ID
&& !(useCache && isQuotaSet())) {
- Snapshot lastSnapshot = sf.getDiffs().getSnapshotById(lastSnapshotId);
- ReadOnlyList<INode> childrenList = getChildrenList(lastSnapshot);
+ ReadOnlyList<INode> childrenList = getChildrenList(lastSnapshotId);
for (INode child : childrenList) {
child.computeQuotaUsage(counts, useCache, lastSnapshotId);
}
@@ -607,7 +611,7 @@ public class INodeDirectory extends INod
ContentSummaryComputationContext computeDirectoryContentSummary(
ContentSummaryComputationContext summary) {
- ReadOnlyList<INode> childrenList = getChildrenList(null);
+ ReadOnlyList<INode> childrenList = getChildrenList(Snapshot.CURRENT_STATE_ID);
// Explicit traversing is done to enable repositioning after relinquishing
// and reacquiring locks.
for (int i = 0; i < childrenList.size(); i++) {
@@ -629,7 +633,7 @@ public class INodeDirectory extends INod
break;
}
// Obtain the children list again since it may have been modified.
- childrenList = getChildrenList(null);
+ childrenList = getChildrenList(Snapshot.CURRENT_STATE_ID);
// Reposition in case the children list is changed. Decrement by 1
// since it will be incremented when loops.
i = nextChild(childrenList, childName) - 1;
@@ -668,21 +672,16 @@ public class INodeDirectory extends INod
* The reference node to be removed/replaced
* @param newChild
* The node to be added back
- * @param latestSnapshot
- * The latest snapshot. Note this may not be the last snapshot in the
- * diff list, since the src tree of the current rename operation
- * may be the dst tree of a previous rename.
* @throws QuotaExceededException should not throw this exception
*/
public void undoRename4ScrParent(final INodeReference oldChild,
- final INode newChild, Snapshot latestSnapshot)
- throws QuotaExceededException {
+ final INode newChild) throws QuotaExceededException {
DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature();
Preconditions.checkState(sf != null,
"Directory does not have snapshot feature");
sf.getDiffs().removeChild(ListType.DELETED, oldChild);
sf.getDiffs().replaceChild(ListType.CREATED, oldChild, newChild);
- addChild(newChild, true, null);
+ addChild(newChild, true, Snapshot.CURRENT_STATE_ID);
}
/**
@@ -691,16 +690,14 @@ public class INodeDirectory extends INod
* and delete possible record in the deleted list.
*/
public void undoRename4DstParent(final INode deletedChild,
- Snapshot latestSnapshot) throws QuotaExceededException {
+ int latestSnapshotId) throws QuotaExceededException {
DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature();
Preconditions.checkState(sf != null,
"Directory does not have snapshot feature");
boolean removeDeletedChild = sf.getDiffs().removeChild(ListType.DELETED,
deletedChild);
- // pass null for inodeMap since the parent node will not get replaced when
- // undoing rename
- final boolean added = addChild(deletedChild, true, removeDeletedChild ? null
- : latestSnapshot);
+ int sid = removeDeletedChild ? Snapshot.CURRENT_STATE_ID : latestSnapshotId;
+ final boolean added = addChild(deletedChild, true, sid);
// update quota usage if adding is successfully and the old child has not
// been stored in deleted list before
if (added && !removeDeletedChild) {
@@ -722,8 +719,8 @@ public class INodeDirectory extends INod
}
/** Call cleanSubtree(..) recursively down the subtree. */
- public Quota.Counts cleanSubtreeRecursively(final Snapshot snapshot,
- Snapshot prior, final BlocksMapUpdateInfo collectedBlocks,
+ public Quota.Counts cleanSubtreeRecursively(final int snapshot,
+ int prior, final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes, final Map<INode, INode> excludedNodes,
final boolean countDiffChange) throws QuotaExceededException {
Quota.Counts counts = Quota.Counts.newInstance();
@@ -732,9 +729,10 @@ public class INodeDirectory extends INod
// to its latest previous snapshot. (besides, we also need to consider nodes
// created after prior but before snapshot. this will be done in
// DirectoryWithSnapshotFeature)
- Snapshot s = snapshot != null && prior != null ? prior : snapshot;
+ int s = snapshot != Snapshot.CURRENT_STATE_ID
+ && prior != Snapshot.NO_SNAPSHOT_ID ? prior : snapshot;
for (INode child : getChildrenList(s)) {
- if (snapshot != null && excludedNodes != null
+ if (snapshot != Snapshot.CURRENT_STATE_ID && excludedNodes != null
&& excludedNodes.containsKey(child)) {
continue;
} else {
@@ -753,7 +751,7 @@ public class INodeDirectory extends INod
if (sf != null) {
sf.clear(this, collectedBlocks, removedINodes);
}
- for (INode child : getChildrenList(null)) {
+ for (INode child : getChildrenList(Snapshot.CURRENT_STATE_ID)) {
child.destroyAndCollectBlocks(collectedBlocks, removedINodes);
}
clear();
@@ -761,18 +759,19 @@ public class INodeDirectory extends INod
}
@Override
- public Quota.Counts cleanSubtree(final Snapshot snapshot, Snapshot prior,
+ public Quota.Counts cleanSubtree(final int snapshotId, int priorSnapshotId,
final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes, final boolean countDiffChange)
throws QuotaExceededException {
DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature();
// there is snapshot data
if (sf != null) {
- return sf.cleanDirectory(this, snapshot, prior, collectedBlocks,
- removedINodes, countDiffChange);
+ return sf.cleanDirectory(this, snapshotId, priorSnapshotId,
+ collectedBlocks, removedINodes, countDiffChange);
}
// there is no snapshot data
- if (prior == null && snapshot == null) {
+ if (priorSnapshotId == Snapshot.NO_SNAPSHOT_ID
+ && snapshotId == Snapshot.CURRENT_STATE_ID) {
// destroy the whole subtree and collect blocks that should be deleted
Quota.Counts counts = Quota.Counts.newInstance();
this.computeQuotaUsage(counts, true);
@@ -780,7 +779,7 @@ public class INodeDirectory extends INod
return counts;
} else {
// process recursively down the subtree
- Quota.Counts counts = cleanSubtreeRecursively(snapshot, prior,
+ Quota.Counts counts = cleanSubtreeRecursively(snapshotId, priorSnapshotId,
collectedBlocks, removedINodes, null, countDiffChange);
if (isQuotaSet()) {
getDirectoryWithQuotaFeature().addSpaceConsumed2Cache(
@@ -816,7 +815,7 @@ public class INodeDirectory extends INod
@VisibleForTesting
@Override
public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
- final Snapshot snapshot) {
+ final int snapshot) {
super.dumpTreeRecursively(out, prefix, snapshot);
out.print(", childrenSize=" + getChildrenList(snapshot).size());
final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature();
@@ -824,7 +823,7 @@ public class INodeDirectory extends INod
out.print(", " + q);
}
if (this instanceof Snapshot.Root) {
- out.print(", snapshotId=" + snapshot.getId());
+ out.print(", snapshotId=" + snapshot);
}
out.println();
@@ -869,7 +868,7 @@ public class INodeDirectory extends INod
for(final Iterator<SnapshotAndINode> i = subs.iterator(); i.hasNext();) {
final SnapshotAndINode pair = i.next();
prefix.append(i.hasNext()? DUMPTREE_EXCEPT_LAST_ITEM: DUMPTREE_LAST_ITEM);
- pair.inode.dumpTreeRecursively(out, prefix, pair.snapshot);
+ pair.inode.dumpTreeRecursively(out, prefix, pair.snapshotId);
prefix.setLength(prefix.length() - 2);
}
}
@@ -877,20 +876,16 @@ public class INodeDirectory extends INod
/** A pair of Snapshot and INode objects. */
protected static class SnapshotAndINode {
- public final Snapshot snapshot;
+ public final int snapshotId;
public final INode inode;
- public SnapshotAndINode(Snapshot snapshot, INode inode) {
- this.snapshot = snapshot;
+ public SnapshotAndINode(int snapshot, INode inode) {
+ this.snapshotId = snapshot;
this.inode = inode;
}
-
- public SnapshotAndINode(Snapshot snapshot) {
- this(snapshot, snapshot.getRoot());
- }
}
- public final int getChildrenNum(final Snapshot snapshot) {
- return getChildrenList(snapshot).size();
+ public final int getChildrenNum(final int snapshotId) {
+ return getChildrenList(snapshotId).size();
}
}
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java Wed Jan 8 23:10:02 2014
@@ -17,6 +17,9 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
+import static org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot.CURRENT_STATE_ID;
+import static org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot.NO_SNAPSHOT_ID;
+
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
@@ -272,26 +275,27 @@ public class INodeFile extends INodeWith
}
@Override
- public INodeFileAttributes getSnapshotINode(final Snapshot snapshot) {
+ public INodeFileAttributes getSnapshotINode(final int snapshotId) {
FileWithSnapshotFeature sf = this.getFileWithSnapshotFeature();
if (sf != null) {
- return sf.getDiffs().getSnapshotINode(snapshot, this);
+ return sf.getDiffs().getSnapshotINode(snapshotId, this);
} else {
return this;
}
}
@Override
- public INodeFile recordModification(final Snapshot latest)
+ public INodeFile recordModification(final int latestSnapshotId)
throws QuotaExceededException {
- if (isInLatestSnapshot(latest) && !shouldRecordInSrcSnapshot(latest)) {
+ if (isInLatestSnapshot(latestSnapshotId)
+ && !shouldRecordInSrcSnapshot(latestSnapshotId)) {
// the file is in snapshot, create a snapshot feature if it does not have
FileWithSnapshotFeature sf = this.getFileWithSnapshotFeature();
if (sf == null) {
sf = addSnapshotFeature(null);
}
// record self in the diff list if necessary
- sf.getDiffs().saveSelf2Snapshot(latest, this, null);
+ sf.getDiffs().saveSelf2Snapshot(latestSnapshotId, this, null);
}
return this;
}
@@ -307,23 +311,22 @@ public class INodeFile extends INodeWith
/* End of Snapshot Feature */
/** @return the replication factor of the file. */
- public final short getFileReplication(Snapshot snapshot) {
- if (snapshot != null) {
+ public final short getFileReplication(int snapshot) {
+ if (snapshot != CURRENT_STATE_ID) {
return getSnapshotINode(snapshot).getFileReplication();
}
-
return HeaderFormat.getReplication(header);
}
/** The same as getFileReplication(null). */
@Override // INodeFileAttributes
public final short getFileReplication() {
- return getFileReplication(null);
+ return getFileReplication(CURRENT_STATE_ID);
}
@Override // BlockCollection
public short getBlockReplication() {
- short max = getFileReplication(null);
+ short max = getFileReplication(CURRENT_STATE_ID);
FileWithSnapshotFeature sf = this.getFileWithSnapshotFeature();
if (sf != null) {
short maxInSnapshot = sf.getMaxBlockRepInDiffs();
@@ -341,9 +344,10 @@ public class INodeFile extends INodeWith
}
/** Set the replication factor of this file. */
- public final INodeFile setFileReplication(short replication, Snapshot latest,
- final INodeMap inodeMap) throws QuotaExceededException {
- final INodeFile nodeToUpdate = recordModification(latest);
+ public final INodeFile setFileReplication(short replication,
+ int latestSnapshotId, final INodeMap inodeMap)
+ throws QuotaExceededException {
+ final INodeFile nodeToUpdate = recordModification(latestSnapshotId);
nodeToUpdate.setFileReplication(replication);
return nodeToUpdate;
}
@@ -421,22 +425,22 @@ public class INodeFile extends INodeWith
}
@Override
- public Quota.Counts cleanSubtree(final Snapshot snapshot, Snapshot prior,
+ public Quota.Counts cleanSubtree(final int snapshot, int priorSnapshotId,
final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes, final boolean countDiffChange)
throws QuotaExceededException {
FileWithSnapshotFeature sf = getFileWithSnapshotFeature();
if (sf != null) {
- return sf.cleanFile(this, snapshot, prior, collectedBlocks,
+ return sf.cleanFile(this, snapshot, priorSnapshotId, collectedBlocks,
removedINodes, countDiffChange);
}
Quota.Counts counts = Quota.Counts.newInstance();
- if (snapshot == null && prior == null) {
+ if (snapshot == CURRENT_STATE_ID && priorSnapshotId == NO_SNAPSHOT_ID) {
// this only happens when deleting the current file and the file is not
// in any snapshot
computeQuotaUsage(counts, false);
destroyAndCollectBlocks(collectedBlocks, removedINodes);
- } else if (snapshot == null && prior != null) {
+ } else if (snapshot == CURRENT_STATE_ID && priorSnapshotId != NO_SNAPSHOT_ID) {
// when deleting the current file and the file is in snapshot, we should
// clean the 0-sized block if the file is UC
FileUnderConstructionFeature uc = getFileUnderConstructionFeature();
@@ -480,17 +484,18 @@ public class INodeFile extends INodeWith
FileWithSnapshotFeature sf = getFileWithSnapshotFeature();
if (sf != null) {
FileDiffList fileDiffList = sf.getDiffs();
- Snapshot last = fileDiffList.getLastSnapshot();
+ int last = fileDiffList.getLastSnapshotId();
List<FileDiff> diffs = fileDiffList.asList();
- if (lastSnapshotId == Snapshot.INVALID_ID || last == null) {
+ if (lastSnapshotId == Snapshot.CURRENT_STATE_ID
+ || last == Snapshot.CURRENT_STATE_ID) {
nsDelta += diffs.size();
dsDelta = diskspaceConsumed();
- } else if (last.getId() < lastSnapshotId) {
+ } else if (last < lastSnapshotId) {
dsDelta = computeFileSize(true, false) * getFileReplication();
} else {
- Snapshot s = fileDiffList.getSnapshotById(lastSnapshotId);
- dsDelta = diskspaceConsumed(s);
+ int sid = fileDiffList.getSnapshotById(lastSnapshotId);
+ dsDelta = diskspaceConsumed(sid);
}
} else {
dsDelta = diskspaceConsumed();
@@ -501,7 +506,7 @@ public class INodeFile extends INodeWith
}
@Override
- public final ContentSummaryComputationContext computeContentSummary(
+ public final ContentSummaryComputationContext computeContentSummary(
final ContentSummaryComputationContext summary) {
computeContentSummary4Snapshot(summary.getCounts());
computeContentSummary4Current(summary.getCounts());
@@ -540,23 +545,21 @@ public class INodeFile extends INodeWith
/** The same as computeFileSize(null). */
public final long computeFileSize() {
- return computeFileSize(null);
+ return computeFileSize(CURRENT_STATE_ID);
}
/**
* Compute file size of the current file if the given snapshot is null;
* otherwise, get the file size from the given snapshot.
*/
- public final long computeFileSize(Snapshot snapshot) {
+ public final long computeFileSize(int snapshotId) {
FileWithSnapshotFeature sf = this.getFileWithSnapshotFeature();
- if (snapshot != null && sf != null) {
- final FileDiff d = sf.getDiffs().getDiff(
- snapshot);
+ if (snapshotId != CURRENT_STATE_ID && sf != null) {
+ final FileDiff d = sf.getDiffs().getDiffById(snapshotId);
if (d != null) {
return d.getFileSize();
}
}
-
return computeFileSize(true, false);
}
@@ -607,9 +610,10 @@ public class INodeFile extends INodeWith
return computeFileSize(true, true) * getBlockReplication();
}
- public final long diskspaceConsumed(Snapshot lastSnapshot) {
- if (lastSnapshot != null) {
- return computeFileSize(lastSnapshot) * getFileReplication(lastSnapshot);
+ public final long diskspaceConsumed(int lastSnapshotId) {
+ if (lastSnapshotId != CURRENT_STATE_ID) {
+ return computeFileSize(lastSnapshotId)
+ * getFileReplication(lastSnapshotId);
} else {
return diskspaceConsumed();
}
@@ -638,9 +642,9 @@ public class INodeFile extends INodeWith
@VisibleForTesting
@Override
public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
- final Snapshot snapshot) {
- super.dumpTreeRecursively(out, prefix, snapshot);
- out.print(", fileSize=" + computeFileSize(snapshot));
+ final int snapshotId) {
+ super.dumpTreeRecursively(out, prefix, snapshotId);
+ out.print(", fileSize=" + computeFileSize(snapshotId));
// only compare the first block
out.print(", blocks=");
out.print(blocks == null || blocks.length == 0? null: blocks[0]);
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeMap.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeMap.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeMap.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeMap.java Wed Jan 8 23:10:02 2014
@@ -23,7 +23,6 @@ import org.apache.hadoop.fs.permission.F
import org.apache.hadoop.fs.permission.PermissionStatus;
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
import org.apache.hadoop.hdfs.server.namenode.Quota.Counts;
-import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.util.GSet;
import org.apache.hadoop.util.LightWeightGSet;
@@ -89,7 +88,8 @@ public class INodeMap {
"", "", new FsPermission((short) 0)), 0, 0) {
@Override
- INode recordModification(Snapshot latest) throws QuotaExceededException {
+ INode recordModification(int latestSnapshotId)
+ throws QuotaExceededException {
return null;
}
@@ -112,7 +112,7 @@ public class INodeMap {
}
@Override
- public Counts cleanSubtree(Snapshot snapshot, Snapshot prior,
+ public Counts cleanSubtree(int snapshotId, int priorSnapshotId,
BlocksMapUpdateInfo collectedBlocks, List<INode> removedINodes,
boolean countDiffChange) throws QuotaExceededException {
return null;
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeReference.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeReference.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeReference.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeReference.java Wed Jan 8 23:10:02 2014
@@ -91,7 +91,7 @@ public abstract class INodeReference ext
* method to identify the snapshot which is the latest snapshot before the
* reference node's creation.
*/
- static Snapshot getPriorSnapshot(INodeReference ref) {
+ static int getPriorSnapshot(INodeReference ref) {
WithCount wc = (WithCount) ref.getReferredINode();
WithName wn = null;
if (ref instanceof DstReference) {
@@ -111,7 +111,7 @@ public abstract class INodeReference ext
}
}
}
- return null;
+ return Snapshot.NO_SNAPSHOT_ID;
}
private INode referred;
@@ -185,13 +185,13 @@ public abstract class INodeReference ext
}
@Override
- public final PermissionStatus getPermissionStatus(Snapshot snapshot) {
- return referred.getPermissionStatus(snapshot);
+ public final PermissionStatus getPermissionStatus(int snapshotId) {
+ return referred.getPermissionStatus(snapshotId);
}
@Override
- public final String getUserName(Snapshot snapshot) {
- return referred.getUserName(snapshot);
+ public final String getUserName(int snapshotId) {
+ return referred.getUserName(snapshotId);
}
@Override
@@ -200,8 +200,8 @@ public abstract class INodeReference ext
}
@Override
- public final String getGroupName(Snapshot snapshot) {
- return referred.getGroupName(snapshot);
+ public final String getGroupName(int snapshotId) {
+ return referred.getGroupName(snapshotId);
}
@Override
@@ -210,8 +210,8 @@ public abstract class INodeReference ext
}
@Override
- public final FsPermission getFsPermission(Snapshot snapshot) {
- return referred.getFsPermission(snapshot);
+ public final FsPermission getFsPermission(int snapshotId) {
+ return referred.getFsPermission(snapshotId);
}
@Override
public final short getFsPermissionShort() {
@@ -229,14 +229,14 @@ public abstract class INodeReference ext
}
@Override
- public final long getModificationTime(Snapshot snapshot) {
- return referred.getModificationTime(snapshot);
+ public final long getModificationTime(int snapshotId) {
+ return referred.getModificationTime(snapshotId);
}
@Override
- public final INode updateModificationTime(long mtime, Snapshot latest)
+ public final INode updateModificationTime(long mtime, int latestSnapshotId)
throws QuotaExceededException {
- return referred.updateModificationTime(mtime, latest);
+ return referred.updateModificationTime(mtime, latestSnapshotId);
}
@Override
@@ -245,8 +245,8 @@ public abstract class INodeReference ext
}
@Override
- public final long getAccessTime(Snapshot snapshot) {
- return referred.getAccessTime(snapshot);
+ public final long getAccessTime(int snapshotId) {
+ return referred.getAccessTime(snapshotId);
}
@Override
@@ -255,15 +255,15 @@ public abstract class INodeReference ext
}
@Override
- final INode recordModification(Snapshot latest)
+ final INode recordModification(int latestSnapshotId)
throws QuotaExceededException {
- referred.recordModification(latest);
+ referred.recordModification(latestSnapshotId);
// reference is never replaced
return this;
}
@Override // used by WithCount
- public Quota.Counts cleanSubtree(Snapshot snapshot, Snapshot prior,
+ public Quota.Counts cleanSubtree(int snapshot, int prior,
BlocksMapUpdateInfo collectedBlocks, final List<INode> removedINodes,
final boolean countDiffChange) throws QuotaExceededException {
return referred.cleanSubtree(snapshot, prior, collectedBlocks,
@@ -291,8 +291,8 @@ public abstract class INodeReference ext
}
@Override
- public final INodeAttributes getSnapshotINode(Snapshot snapshot) {
- return referred.getSnapshotINode(snapshot);
+ public final INodeAttributes getSnapshotINode(int snapshotId) {
+ return referred.getSnapshotINode(snapshotId);
}
@Override
@@ -308,7 +308,7 @@ public abstract class INodeReference ext
@Override
public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
- final Snapshot snapshot) {
+ final int snapshot) {
super.dumpTreeRecursively(out, prefix, snapshot);
if (this instanceof DstReference) {
out.print(", dstSnapshotId=" + ((DstReference) this).dstSnapshotId);
@@ -327,7 +327,7 @@ public abstract class INodeReference ext
}
public int getDstSnapshotId() {
- return Snapshot.INVALID_ID;
+ return Snapshot.CURRENT_STATE_ID;
}
/** An anonymous reference with reference count. */
@@ -457,34 +457,35 @@ public abstract class INodeReference ext
// node happened before the rename of its ancestor. This should be
// impossible since for WithName node we only count its children at the
// time of the rename.
- Preconditions.checkState(this.lastSnapshotId >= lastSnapshotId);
+ Preconditions.checkState(lastSnapshotId == Snapshot.CURRENT_STATE_ID
+ || this.lastSnapshotId >= lastSnapshotId);
final INode referred = this.getReferredINode().asReference()
.getReferredINode();
// We will continue the quota usage computation using the same snapshot id
// as time line (if the given snapshot id is valid). Also, we cannot use
// cache for the referred node since its cached quota may have already
// been updated by changes in the current tree.
- int id = lastSnapshotId > Snapshot.INVALID_ID ?
+ int id = lastSnapshotId != Snapshot.CURRENT_STATE_ID ?
lastSnapshotId : this.lastSnapshotId;
return referred.computeQuotaUsage(counts, false, id);
}
@Override
- public Quota.Counts cleanSubtree(final Snapshot snapshot, Snapshot prior,
+ public Quota.Counts cleanSubtree(final int snapshot, int prior,
final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes, final boolean countDiffChange)
throws QuotaExceededException {
// since WithName node resides in deleted list acting as a snapshot copy,
// the parameter snapshot must be non-null
- Preconditions.checkArgument(snapshot != null);
- // if prior is null, we need to check snapshot belonging to the previous
- // WithName instance
- if (prior == null) {
+ Preconditions.checkArgument(snapshot != Snapshot.CURRENT_STATE_ID);
+ // if prior is NO_SNAPSHOT_ID, we need to check snapshot belonging to the
+ // previous WithName instance
+ if (prior == Snapshot.NO_SNAPSHOT_ID) {
prior = getPriorSnapshot(this);
}
- if (prior != null
- && Snapshot.ID_COMPARATOR.compare(snapshot, prior) <= 0) {
+ if (prior != Snapshot.NO_SNAPSHOT_ID
+ && Snapshot.ID_INTEGER_COMPARATOR.compare(snapshot, prior) <= 0) {
return Quota.Counts.newInstance();
}
@@ -496,7 +497,7 @@ public abstract class INodeReference ext
-counts.get(Quota.DISKSPACE), true);
}
- if (snapshot.getId() < lastSnapshotId) {
+ if (snapshot < lastSnapshotId) {
// for a WithName node, when we compute its quota usage, we only count
// in all the nodes existing at the time of the corresponding rename op.
// Thus if we are deleting a snapshot before/at the snapshot associated
@@ -509,16 +510,16 @@ public abstract class INodeReference ext
@Override
public void destroyAndCollectBlocks(BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes) {
- Snapshot snapshot = getSelfSnapshot();
+ int snapshot = getSelfSnapshot();
if (removeReference(this) <= 0) {
getReferredINode().destroyAndCollectBlocks(collectedBlocks,
removedINodes);
} else {
- Snapshot prior = getPriorSnapshot(this);
+ int prior = getPriorSnapshot(this);
INode referred = getReferredINode().asReference().getReferredINode();
- if (snapshot != null) {
- if (prior != null && snapshot.getId() <= prior.getId()) {
+ if (snapshot != Snapshot.NO_SNAPSHOT_ID) {
+ if (prior != Snapshot.NO_SNAPSHOT_ID && snapshot <= prior) {
// the snapshot to be deleted has been deleted while traversing
// the src tree of the previous rename operation. This usually
// happens when rename's src and dst are under the same
@@ -545,9 +546,9 @@ public abstract class INodeReference ext
}
}
- private Snapshot getSelfSnapshot() {
+ private int getSelfSnapshot() {
INode referred = getReferredINode().asReference().getReferredINode();
- Snapshot snapshot = null;
+ int snapshot = Snapshot.NO_SNAPSHOT_ID;
if (referred.isFile() && referred.asFile().isWithSnapshot()) {
snapshot = referred.asFile().getDiffs().getPrior(lastSnapshotId);
} else if (referred.isDirectory()) {
@@ -569,7 +570,7 @@ public abstract class INodeReference ext
* latest snapshot. Otherwise changes will be recorded to the snapshot
* belonging to the src of the rename.
*
- * {@link Snapshot#INVALID_ID} means no dstSnapshot (e.g., src of the
+ * {@link Snapshot#NO_SNAPSHOT_ID} means no dstSnapshot (e.g., src of the
* first-time rename).
*/
private final int dstSnapshotId;
@@ -587,25 +588,27 @@ public abstract class INodeReference ext
}
@Override
- public Quota.Counts cleanSubtree(Snapshot snapshot, Snapshot prior,
+ public Quota.Counts cleanSubtree(int snapshot, int prior,
BlocksMapUpdateInfo collectedBlocks, List<INode> removedINodes,
final boolean countDiffChange) throws QuotaExceededException {
- if (snapshot == null && prior == null) {
+ if (snapshot == Snapshot.CURRENT_STATE_ID
+ && prior == Snapshot.NO_SNAPSHOT_ID) {
Quota.Counts counts = Quota.Counts.newInstance();
this.computeQuotaUsage(counts, true);
destroyAndCollectBlocks(collectedBlocks, removedINodes);
return counts;
} else {
- // if prior is null, we need to check snapshot belonging to the previous
- // WithName instance
- if (prior == null) {
+ // if prior is NO_SNAPSHOT_ID, we need to check snapshot belonging to
+ // the previous WithName instance
+ if (prior == Snapshot.NO_SNAPSHOT_ID) {
prior = getPriorSnapshot(this);
}
- // if prior is not null, and prior is not before the to-be-deleted
- // snapshot, we can quit here and leave the snapshot deletion work to
- // the src tree of rename
- if (snapshot != null && prior != null
- && Snapshot.ID_COMPARATOR.compare(snapshot, prior) <= 0) {
+ // if prior is not NO_SNAPSHOT_ID, and prior is not before the
+ // to-be-deleted snapshot, we can quit here and leave the snapshot
+ // deletion work to the src tree of rename
+ if (snapshot != Snapshot.CURRENT_STATE_ID
+ && prior != Snapshot.NO_SNAPSHOT_ID
+ && Snapshot.ID_INTEGER_COMPARATOR.compare(snapshot, prior) <= 0) {
return Quota.Counts.newInstance();
}
return getReferredINode().cleanSubtree(snapshot, prior,
@@ -632,12 +635,12 @@ public abstract class INodeReference ext
} else {
// we will clean everything, including files, directories, and
// snapshots, that were created after this prior snapshot
- Snapshot prior = getPriorSnapshot(this);
+ int prior = getPriorSnapshot(this);
// prior must be non-null, otherwise we do not have any previous
// WithName nodes, and the reference number will be 0.
- Preconditions.checkState(prior != null);
+ Preconditions.checkState(prior != Snapshot.NO_SNAPSHOT_ID);
// identify the snapshot created after prior
- Snapshot snapshot = getSelfSnapshot(prior);
+ int snapshot = getSelfSnapshot(prior);
INode referred = getReferredINode().asReference().getReferredINode();
if (referred.isFile()) {
@@ -671,23 +674,23 @@ public abstract class INodeReference ext
}
}
- private Snapshot getSelfSnapshot(final Snapshot prior) {
+ private int getSelfSnapshot(final int prior) {
WithCount wc = (WithCount) getReferredINode().asReference();
INode referred = wc.getReferredINode();
- Snapshot lastSnapshot = null;
+ int lastSnapshot = Snapshot.CURRENT_STATE_ID;
if (referred.isFile() && referred.asFile().isWithSnapshot()) {
- lastSnapshot = referred.asFile().getDiffs().getLastSnapshot();
+ lastSnapshot = referred.asFile().getDiffs().getLastSnapshotId();
} else if (referred.isDirectory()) {
DirectoryWithSnapshotFeature sf = referred.asDirectory()
.getDirectoryWithSnapshotFeature();
if (sf != null) {
- lastSnapshot = sf.getLastSnapshot();
+ lastSnapshot = sf.getLastSnapshotId();
}
}
- if (lastSnapshot != null && !lastSnapshot.equals(prior)) {
+ if (lastSnapshot != Snapshot.CURRENT_STATE_ID && lastSnapshot != prior) {
return lastSnapshot;
} else {
- return null;
+ return Snapshot.CURRENT_STATE_ID;
}
}
}
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java Wed Jan 8 23:10:02 2014
@@ -45,10 +45,10 @@ public class INodeSymlink extends INodeW
}
@Override
- INode recordModification(Snapshot latest) throws QuotaExceededException {
- if (isInLatestSnapshot(latest)) {
+ INode recordModification(int latestSnapshotId) throws QuotaExceededException {
+ if (isInLatestSnapshot(latestSnapshotId)) {
INodeDirectory parent = getParent();
- parent.saveChild2Snapshot(this, latest, new INodeSymlink(this));
+ parent.saveChild2Snapshot(this, latestSnapshotId, new INodeSymlink(this));
}
return this;
}
@@ -74,10 +74,11 @@ public class INodeSymlink extends INodeW
}
@Override
- public Quota.Counts cleanSubtree(final Snapshot snapshot, Snapshot prior,
+ public Quota.Counts cleanSubtree(final int snapshotId, int priorSnapshotId,
final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes, final boolean countDiffChange) {
- if (snapshot == null && prior == null) {
+ if (snapshotId == Snapshot.CURRENT_STATE_ID
+ && priorSnapshotId == Snapshot.NO_SNAPSHOT_ID) {
destroyAndCollectBlocks(collectedBlocks, removedINodes);
}
return Quota.Counts.newInstance(1, 0);
@@ -105,7 +106,7 @@ public class INodeSymlink extends INodeW
@Override
public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
- final Snapshot snapshot) {
+ final int snapshot) {
super.dumpTreeRecursively(out, prefix, snapshot);
out.println();
}
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java Wed Jan 8 23:10:02 2014
@@ -155,9 +155,9 @@ public abstract class INodeWithAdditiona
}
@Override
- final PermissionStatus getPermissionStatus(Snapshot snapshot) {
- return new PermissionStatus(getUserName(snapshot), getGroupName(snapshot),
- getFsPermission(snapshot));
+ final PermissionStatus getPermissionStatus(int snapshotId) {
+ return new PermissionStatus(getUserName(snapshotId), getGroupName(snapshotId),
+ getFsPermission(snapshotId));
}
private final void updatePermissionStatus(PermissionStatusFormat f, long n) {
@@ -165,9 +165,9 @@ public abstract class INodeWithAdditiona
}
@Override
- final String getUserName(Snapshot snapshot) {
- if (snapshot != null) {
- return getSnapshotINode(snapshot).getUserName();
+ final String getUserName(int snapshotId) {
+ if (snapshotId != Snapshot.CURRENT_STATE_ID) {
+ return getSnapshotINode(snapshotId).getUserName();
}
int n = (int)PermissionStatusFormat.USER.retrieve(permission);
@@ -181,9 +181,9 @@ public abstract class INodeWithAdditiona
}
@Override
- final String getGroupName(Snapshot snapshot) {
- if (snapshot != null) {
- return getSnapshotINode(snapshot).getGroupName();
+ final String getGroupName(int snapshotId) {
+ if (snapshotId != Snapshot.CURRENT_STATE_ID) {
+ return getSnapshotINode(snapshotId).getGroupName();
}
int n = (int)PermissionStatusFormat.GROUP.retrieve(permission);
@@ -197,9 +197,9 @@ public abstract class INodeWithAdditiona
}
@Override
- final FsPermission getFsPermission(Snapshot snapshot) {
- if (snapshot != null) {
- return getSnapshotINode(snapshot).getFsPermission();
+ final FsPermission getFsPermission(int snapshotId) {
+ if (snapshotId != Snapshot.CURRENT_STATE_ID) {
+ return getSnapshotINode(snapshotId).getFsPermission();
}
return new FsPermission(getFsPermissionShort());
@@ -221,9 +221,9 @@ public abstract class INodeWithAdditiona
}
@Override
- final long getModificationTime(Snapshot snapshot) {
- if (snapshot != null) {
- return getSnapshotINode(snapshot).getModificationTime();
+ final long getModificationTime(int snapshotId) {
+ if (snapshotId != Snapshot.CURRENT_STATE_ID) {
+ return getSnapshotINode(snapshotId).getModificationTime();
}
return this.modificationTime;
@@ -232,13 +232,13 @@ public abstract class INodeWithAdditiona
/** Update modification time if it is larger than the current value. */
@Override
- public final INode updateModificationTime(long mtime, Snapshot latest)
+ public final INode updateModificationTime(long mtime, int latestSnapshotId)
throws QuotaExceededException {
Preconditions.checkState(isDirectory());
if (mtime <= modificationTime) {
return this;
}
- return setModificationTime(mtime, latest);
+ return setModificationTime(mtime, latestSnapshotId);
}
final void cloneModificationTime(INodeWithAdditionalFields that) {
@@ -251,11 +251,10 @@ public abstract class INodeWithAdditiona
}
@Override
- final long getAccessTime(Snapshot snapshot) {
- if (snapshot != null) {
- return getSnapshotINode(snapshot).getAccessTime();
+ final long getAccessTime(int snapshotId) {
+ if (snapshotId != Snapshot.CURRENT_STATE_ID) {
+ return getSnapshotINode(snapshotId).getAccessTime();
}
-
return accessTime;
}
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java Wed Jan 8 23:10:02 2014
@@ -135,8 +135,8 @@ public class INodesInPath {
if (!isRef && isDir && dir.isWithSnapshot()) {
//if the path is a non-snapshot path, update the latest snapshot.
if (!existing.isSnapshot()) {
- existing.updateLatestSnapshot(dir.getDirectoryWithSnapshotFeature()
- .getLastSnapshot());
+ existing.updateLatestSnapshotId(dir.getDirectoryWithSnapshotFeature()
+ .getLastSnapshotId());
}
} else if (isRef && isDir && !lastComp) {
// If the curNode is a reference node, need to check its dstSnapshot:
@@ -151,16 +151,17 @@ public class INodesInPath {
// recordModification method.
if (!existing.isSnapshot()) {
int dstSnapshotId = curNode.asReference().getDstSnapshotId();
- Snapshot latest = existing.getLatestSnapshot();
- if (latest == null || // no snapshot in dst tree of rename
- dstSnapshotId >= latest.getId()) { // the above scenario
- Snapshot lastSnapshot = null;
+ int latest = existing.getLatestSnapshotId();
+ if (latest == Snapshot.CURRENT_STATE_ID || // no snapshot in dst tree of rename
+ (dstSnapshotId != Snapshot.CURRENT_STATE_ID &&
+ dstSnapshotId >= latest)) { // the above scenario
+ int lastSnapshot = Snapshot.CURRENT_STATE_ID;
DirectoryWithSnapshotFeature sf = null;
if (curNode.isDirectory() &&
(sf = curNode.asDirectory().getDirectoryWithSnapshotFeature()) != null) {
- lastSnapshot = sf.getLastSnapshot();
+ lastSnapshot = sf.getLastSnapshotId();
}
- existing.setSnapshot(lastSnapshot);
+ existing.setSnapshotId(lastSnapshot);
}
}
}
@@ -206,14 +207,14 @@ public class INodesInPath {
curNode = null;
} else {
curNode = s.getRoot();
- existing.setSnapshot(s);
+ existing.setSnapshotId(s.getId());
}
if (index >= -1) {
existing.snapshotRootIndex = existing.numNonNull;
}
} else {
// normal case, and also for resolving file/dir under snapshot root
- curNode = dir.getChild(childName, existing.getPathSnapshot());
+ curNode = dir.getChild(childName, existing.getPathSnapshotId());
}
count++;
index++;
@@ -245,11 +246,12 @@ public class INodesInPath {
*/
private int snapshotRootIndex;
/**
- * For snapshot paths, it is the reference to the snapshot; or null if the
- * snapshot does not exist. For non-snapshot paths, it is the reference to
- * the latest snapshot found in the path; or null if no snapshot is found.
+ * For snapshot paths, it is the id of the snapshot; or
+ * {@link Snapshot#CURRENT_STATE_ID} if the snapshot does not exist. For
+ * non-snapshot paths, it is the id of the latest snapshot found in the path;
+ * or {@link Snapshot#CURRENT_STATE_ID} if no snapshot is found.
*/
- private Snapshot snapshot = null;
+ private int snapshotId = Snapshot.CURRENT_STATE_ID;
private INodesInPath(byte[][] path, int number) {
this.path = path;
@@ -262,29 +264,30 @@ public class INodesInPath {
}
/**
- * For non-snapshot paths, return the latest snapshot found in the path.
- * For snapshot paths, return null.
+ * For non-snapshot paths, return the latest snapshot id found in the path.
*/
- public Snapshot getLatestSnapshot() {
- return isSnapshot? null: snapshot;
+ public int getLatestSnapshotId() {
+ Preconditions.checkState(!isSnapshot);
+ return snapshotId;
}
/**
- * For snapshot paths, return the snapshot specified in the path.
- * For non-snapshot paths, return null.
+ * For snapshot paths, return the id of the snapshot specified in the path.
+ * For non-snapshot paths, return {@link Snapshot#CURRENT_STATE_ID}.
*/
- public Snapshot getPathSnapshot() {
- return isSnapshot? snapshot: null;
+ public int getPathSnapshotId() {
+ return isSnapshot ? snapshotId : Snapshot.CURRENT_STATE_ID;
}
- private void setSnapshot(Snapshot s) {
- snapshot = s;
+ private void setSnapshotId(int sid) {
+ snapshotId = sid;
}
- private void updateLatestSnapshot(Snapshot s) {
- if (snapshot == null
- || (s != null && Snapshot.ID_COMPARATOR.compare(snapshot, s) < 0)) {
- snapshot = s;
+ private void updateLatestSnapshotId(int sid) {
+ if (snapshotId == Snapshot.CURRENT_STATE_ID
+ || (sid != Snapshot.CURRENT_STATE_ID && Snapshot.ID_INTEGER_COMPARATOR
+ .compare(snapshotId, sid) < 0)) {
+ snapshotId = sid;
}
}
@@ -386,7 +389,7 @@ public class INodesInPath {
.append("\n capacity = ").append(capacity)
.append("\n isSnapshot = ").append(isSnapshot)
.append("\n snapshotRootIndex = ").append(snapshotRootIndex)
- .append("\n snapshot = ").append(snapshot);
+ .append("\n snapshotId = ").append(snapshotId);
return b.toString();
}
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiff.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiff.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiff.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiff.java Wed Jan 8 23:10:02 2014
@@ -22,8 +22,8 @@ import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hdfs.server.namenode.INode;
-import org.apache.hadoop.hdfs.server.namenode.INodeAttributes;
import org.apache.hadoop.hdfs.server.namenode.INode.BlocksMapUpdateInfo;
+import org.apache.hadoop.hdfs.server.namenode.INodeAttributes;
import org.apache.hadoop.hdfs.server.namenode.Quota;
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotFSImageFormat.ReferenceMap;
@@ -52,8 +52,8 @@ abstract class AbstractINodeDiff<N exten
D extends AbstractINodeDiff<N, A, D>>
implements Comparable<Integer> {
- /** The snapshot will be obtained after this diff is applied. */
- Snapshot snapshot;
+ /** The id of the corresponding snapshot. */
+ private int snapshotId;
/** The snapshot inode data. It is null when there is no change. */
A snapshotINode;
/**
@@ -64,10 +64,8 @@ abstract class AbstractINodeDiff<N exten
*/
private D posteriorDiff;
- AbstractINodeDiff(Snapshot snapshot, A snapshotINode, D posteriorDiff) {
- Preconditions.checkNotNull(snapshot, "snapshot is null");
-
- this.snapshot = snapshot;
+ AbstractINodeDiff(int snapshotId, A snapshotINode, D posteriorDiff) {
+ this.snapshotId = snapshotId;
this.snapshotINode = snapshotINode;
this.posteriorDiff = posteriorDiff;
}
@@ -75,16 +73,16 @@ abstract class AbstractINodeDiff<N exten
/** Compare diffs with snapshot ID. */
@Override
public final int compareTo(final Integer that) {
- return Snapshot.ID_INTEGER_COMPARATOR.compare(this.snapshot.getId(), that);
+ return Snapshot.ID_INTEGER_COMPARATOR.compare(this.snapshotId, that);
}
/** @return the snapshot object of this diff. */
- public final Snapshot getSnapshot() {
- return snapshot;
+ public final int getSnapshotId() {
+ return snapshotId;
}
- final void setSnapshot(Snapshot snapshot) {
- this.snapshot = snapshot;
+ final void setSnapshotId(int snapshot) {
+ this.snapshotId = snapshot;
}
/** @return the posterior diff. */
@@ -132,13 +130,12 @@ abstract class AbstractINodeDiff<N exten
@Override
public String toString() {
- return getClass().getSimpleName() + ": " + snapshot + " (post="
- + (posteriorDiff == null? null: posteriorDiff.snapshot) + ")";
+ return getClass().getSimpleName() + ": " + this.getSnapshotId() + " (post="
+ + (posteriorDiff == null? null: posteriorDiff.getSnapshotId()) + ")";
}
void writeSnapshot(DataOutput out) throws IOException {
- // Assume the snapshot is recorded before, write id only.
- out.writeInt(snapshot.getId());
+ out.writeInt(snapshotId);
}
abstract void write(DataOutput out, ReferenceMap referenceMap
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java Wed Jan 8 23:10:02 2014
@@ -53,7 +53,7 @@ abstract class AbstractINodeDiffList<N e
}
/** @return an {@link AbstractINodeDiff}. */
- abstract D createDiff(Snapshot snapshot, N currentINode);
+ abstract D createDiff(int snapshotId, N currentINode);
/** @return a snapshot copy of the current inode. */
abstract A createSnapshotCopy(N currentINode);
@@ -63,25 +63,25 @@ abstract class AbstractINodeDiffList<N e
* outside. If the diff to remove is not the first one in the diff list, we
* need to combine the diff with its previous one.
*
- * @param snapshot The snapshot to be deleted
- * @param prior The snapshot taken before the to-be-deleted snapshot
+ * @param snapshot The id of the snapshot to be deleted
+ * @param prior The id of the snapshot taken before the to-be-deleted snapshot
* @param collectedBlocks Used to collect information for blocksMap update
* @return delta in namespace.
*/
- public final Quota.Counts deleteSnapshotDiff(final Snapshot snapshot,
- Snapshot prior, final N currentINode,
+ public final Quota.Counts deleteSnapshotDiff(final int snapshot,
+ final int prior, final N currentINode,
final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes, boolean countDiffChange)
throws QuotaExceededException {
- int snapshotIndex = Collections.binarySearch(diffs, snapshot.getId());
+ int snapshotIndex = Collections.binarySearch(diffs, snapshot);
Quota.Counts counts = Quota.Counts.newInstance();
D removed = null;
if (snapshotIndex == 0) {
- if (prior != null) {
+ if (prior != Snapshot.NO_SNAPSHOT_ID) { // there is still snapshot before
// set the snapshot to latestBefore
- diffs.get(snapshotIndex).setSnapshot(prior);
- } else {
+ diffs.get(snapshotIndex).setSnapshotId(prior);
+ } else { // there is no snapshot before
removed = diffs.remove(0);
if (countDiffChange) {
counts.add(Quota.NAMESPACE, 1);
@@ -96,8 +96,8 @@ abstract class AbstractINodeDiffList<N e
}
} else if (snapshotIndex > 0) {
final AbstractINodeDiff<N, A, D> previous = diffs.get(snapshotIndex - 1);
- if (!previous.getSnapshot().equals(prior)) {
- diffs.get(snapshotIndex).setSnapshot(prior);
+ if (previous.getSnapshotId() != prior) {
+ diffs.get(snapshotIndex).setSnapshotId(prior);
} else {
// combine the to-be-removed diff with its previous diff
removed = diffs.remove(snapshotIndex);
@@ -120,10 +120,10 @@ abstract class AbstractINodeDiffList<N e
}
/** Add an {@link AbstractINodeDiff} for the given snapshot. */
- final D addDiff(Snapshot latest, N currentINode)
+ final D addDiff(int latestSnapshotId, N currentINode)
throws QuotaExceededException {
currentINode.addSpaceConsumed(1, 0, true);
- return addLast(createDiff(latest, currentINode));
+ return addLast(createDiff(latestSnapshotId, currentINode));
}
/** Append the diff at the end of the list. */
@@ -149,10 +149,10 @@ abstract class AbstractINodeDiffList<N e
return n == 0? null: diffs.get(n - 1);
}
- /** @return the last snapshot. */
- public final Snapshot getLastSnapshot() {
+ /** @return the id of the last snapshot. */
+ public final int getLastSnapshotId() {
final AbstractINodeDiff<N, A, D> last = getLast();
- return last == null? null: last.getSnapshot();
+ return last == null ? Snapshot.CURRENT_STATE_ID : last.getSnapshotId();
}
/**
@@ -161,60 +161,49 @@ abstract class AbstractINodeDiffList<N e
* snapshot id.
* @param exclusive True means the returned snapshot's id must be < the given
* id, otherwise <=.
- * @return The latest snapshot before the given snapshot.
+ * @return The id of the latest snapshot before the given snapshot.
*/
- private final Snapshot getPrior(int anchorId, boolean exclusive) {
- if (anchorId == Snapshot.INVALID_ID) {
- return getLastSnapshot();
+ private final int getPrior(int anchorId, boolean exclusive) {
+ if (anchorId == Snapshot.CURRENT_STATE_ID) {
+ return getLastSnapshotId();
}
final int i = Collections.binarySearch(diffs, anchorId);
if (exclusive) { // must be the one before
if (i == -1 || i == 0) {
- return null;
+ return Snapshot.NO_SNAPSHOT_ID;
} else {
int priorIndex = i > 0 ? i - 1 : -i - 2;
- return diffs.get(priorIndex).getSnapshot();
+ return diffs.get(priorIndex).getSnapshotId();
}
} else { // the one, or the one before if not existing
if (i >= 0) {
- return diffs.get(i).getSnapshot();
+ return diffs.get(i).getSnapshotId();
} else if (i < -1) {
- return diffs.get(-i - 2).getSnapshot();
+ return diffs.get(-i - 2).getSnapshotId();
} else { // i == -1
- return null;
+ return Snapshot.NO_SNAPSHOT_ID;
}
}
}
- public final Snapshot getPrior(int snapshotId) {
+ public final int getPrior(int snapshotId) {
return getPrior(snapshotId, false);
}
/**
* Update the prior snapshot.
*/
- final Snapshot updatePrior(Snapshot snapshot, Snapshot prior) {
- int id = snapshot == null ? Snapshot.INVALID_ID : snapshot.getId();
- Snapshot s = getPrior(id, true);
- if (s != null &&
- (prior == null || Snapshot.ID_COMPARATOR.compare(s, prior) > 0)) {
- return s;
+ final int updatePrior(int snapshot, int prior) {
+ int p = getPrior(snapshot, true);
+ if (p != Snapshot.CURRENT_STATE_ID
+ && Snapshot.ID_INTEGER_COMPARATOR.compare(p, prior) > 0) {
+ return p;
}
return prior;
}
-
- /**
- * @return the diff corresponding to the given snapshot.
- * When the diff is null, it means that the current state and
- * the corresponding snapshot state are the same.
- */
- public final D getDiff(Snapshot snapshot) {
- return getDiffById(snapshot == null ?
- Snapshot.INVALID_ID : snapshot.getId());
- }
- private final D getDiffById(final int snapshotId) {
- if (snapshotId == Snapshot.INVALID_ID) {
+ public final D getDiffById(final int snapshotId) {
+ if (snapshotId == Snapshot.CURRENT_STATE_ID) {
return null;
}
final int i = Collections.binarySearch(diffs, snapshotId);
@@ -234,9 +223,9 @@ abstract class AbstractINodeDiffList<N e
* Search for the snapshot whose id is 1) no less than the given id,
* and 2) most close to the given id.
*/
- public final Snapshot getSnapshotById(final int snapshotId) {
+ public final int getSnapshotById(final int snapshotId) {
D diff = getDiffById(snapshotId);
- return diff == null ? null : diff.getSnapshot();
+ return diff == null ? Snapshot.CURRENT_STATE_ID : diff.getSnapshotId();
}
/**
@@ -271,8 +260,8 @@ abstract class AbstractINodeDiffList<N e
* Note that the current inode is returned if there is no change
* between the given snapshot and the current state.
*/
- public A getSnapshotINode(final Snapshot snapshot, final A currentINode) {
- final D diff = getDiff(snapshot);
+ public A getSnapshotINode(final int snapshotId, final A currentINode) {
+ final D diff = getDiffById(snapshotId);
final A inode = diff == null? null: diff.getSnapshotINode();
return inode == null? currentINode: inode;
}
@@ -281,15 +270,16 @@ abstract class AbstractINodeDiffList<N e
* Check if the latest snapshot diff exists. If not, add it.
* @return the latest snapshot diff, which is never null.
*/
- final D checkAndAddLatestSnapshotDiff(Snapshot latest, N currentINode)
+ final D checkAndAddLatestSnapshotDiff(int latestSnapshotId, N currentINode)
throws QuotaExceededException {
final D last = getLast();
if (last != null
- && Snapshot.ID_COMPARATOR.compare(last.getSnapshot(), latest) >= 0) {
+ && Snapshot.ID_INTEGER_COMPARATOR.compare(last.getSnapshotId(),
+ latestSnapshotId) >= 0) {
return last;
} else {
try {
- return addDiff(latest, currentINode);
+ return addDiff(latestSnapshotId, currentINode);
} catch(NSQuotaExceededException e) {
e.setMessagePrefix("Failed to record modification for snapshot");
throw e;
@@ -298,10 +288,10 @@ abstract class AbstractINodeDiffList<N e
}
/** Save the snapshot copy to the latest snapshot. */
- public void saveSelf2Snapshot(Snapshot latest, N currentINode, A snapshotCopy)
- throws QuotaExceededException {
- if (latest != null) {
- D diff = checkAndAddLatestSnapshotDiff(latest, currentINode);
+ public void saveSelf2Snapshot(int latestSnapshotId, N currentINode,
+ A snapshotCopy) throws QuotaExceededException {
+ if (latestSnapshotId != Snapshot.CURRENT_STATE_ID) {
+ D diff = checkAndAddLatestSnapshotDiff(latestSnapshotId, currentINode);
if (diff.snapshotINode == null) {
if (snapshotCopy == null) {
snapshotCopy = createSnapshotCopy(currentINode);
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectoryWithSnapshotFeature.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectoryWithSnapshotFeature.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectoryWithSnapshotFeature.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectoryWithSnapshotFeature.java Wed Jan 8 23:10:02 2014
@@ -225,30 +225,36 @@ public class DirectoryWithSnapshotFeatur
private final int childrenSize;
/** The children list diff. */
private final ChildrenDiff diff;
+ private boolean isSnapshotRoot = false;
+
+ private DirectoryDiff(int snapshotId, INodeDirectory dir) {
+ super(snapshotId, null, null);
- private DirectoryDiff(Snapshot snapshot, INodeDirectory dir) {
- super(snapshot, null, null);
-
- this.childrenSize = dir.getChildrenList(null).size();
+ this.childrenSize = dir.getChildrenList(Snapshot.CURRENT_STATE_ID).size();
this.diff = new ChildrenDiff();
}
/** Constructor used by FSImage loading */
- DirectoryDiff(Snapshot snapshot, INodeDirectoryAttributes snapshotINode,
- DirectoryDiff posteriorDiff, int childrenSize,
- List<INode> createdList, List<INode> deletedList) {
- super(snapshot, snapshotINode, posteriorDiff);
+ DirectoryDiff(int snapshotId, INodeDirectoryAttributes snapshotINode,
+ DirectoryDiff posteriorDiff, int childrenSize, List<INode> createdList,
+ List<INode> deletedList, boolean isSnapshotRoot) {
+ super(snapshotId, snapshotINode, posteriorDiff);
this.childrenSize = childrenSize;
this.diff = new ChildrenDiff(createdList, deletedList);
+ this.isSnapshotRoot = isSnapshotRoot;
}
ChildrenDiff getChildrenDiff() {
return diff;
}
-
- /** Is the inode the root of the snapshot? */
+
+ void setSnapshotRoot(INodeDirectoryAttributes root) {
+ this.snapshotINode = root;
+ this.isSnapshotRoot = true;
+ }
+
boolean isSnapshotRoot() {
- return snapshotINode == snapshot.getRoot();
+ return isSnapshotRoot;
}
@Override
@@ -287,7 +293,7 @@ public class DirectoryWithSnapshotFeatur
combined.combinePosterior(d.diff, null);
}
children = combined.apply2Current(ReadOnlyList.Util.asList(
- currentDir.getChildrenList(null)));
+ currentDir.getChildrenList(Snapshot.CURRENT_STATE_ID)));
}
return children;
}
@@ -327,7 +333,7 @@ public class DirectoryWithSnapshotFeatur
return null;
} else if (d.getPosterior() == null) {
// no more posterior diff, get from current inode.
- return currentDir.getChild(name, null);
+ return currentDir.getChild(name, Snapshot.CURRENT_STATE_ID);
}
}
}
@@ -342,11 +348,9 @@ public class DirectoryWithSnapshotFeatur
writeSnapshot(out);
out.writeInt(childrenSize);
- // write snapshotINode
- if (isSnapshotRoot()) {
- out.writeBoolean(true);
- } else {
- out.writeBoolean(false);
+ // Write snapshotINode
+ out.writeBoolean(isSnapshotRoot);
+ if (!isSnapshotRoot) {
if (snapshotINode != null) {
out.writeBoolean(true);
FSImageSerialization.writeINodeDirectoryAttributes(snapshotINode, out);
@@ -373,7 +377,7 @@ public class DirectoryWithSnapshotFeatur
extends AbstractINodeDiffList<INodeDirectory, INodeDirectoryAttributes, DirectoryDiff> {
@Override
- DirectoryDiff createDiff(Snapshot snapshot, INodeDirectory currentDir) {
+ DirectoryDiff createDiff(int snapshot, INodeDirectory currentDir) {
return new DirectoryDiff(snapshot, currentDir);
}
@@ -424,12 +428,13 @@ public class DirectoryWithSnapshotFeatur
/**
* Destroy a subtree under a DstReference node.
*/
- public static void destroyDstSubtree(INode inode, final Snapshot snapshot,
- final Snapshot prior, final BlocksMapUpdateInfo collectedBlocks,
+ public static void destroyDstSubtree(INode inode, final int snapshot,
+ final int prior, final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes) throws QuotaExceededException {
- Preconditions.checkArgument(prior != null);
+ Preconditions.checkArgument(prior != Snapshot.NO_SNAPSHOT_ID);
if (inode.isReference()) {
- if (inode instanceof INodeReference.WithName && snapshot != null) {
+ if (inode instanceof INodeReference.WithName
+ && snapshot != Snapshot.CURRENT_STATE_ID) {
// this inode has been renamed before the deletion of the DstReference
// subtree
inode.cleanSubtree(snapshot, prior, collectedBlocks, removedINodes,
@@ -447,18 +452,18 @@ public class DirectoryWithSnapshotFeatur
DirectoryWithSnapshotFeature sf = dir.getDirectoryWithSnapshotFeature();
if (sf != null) {
DirectoryDiffList diffList = sf.getDiffs();
- DirectoryDiff priorDiff = diffList.getDiff(prior);
- if (priorDiff != null && priorDiff.getSnapshot().equals(prior)) {
+ DirectoryDiff priorDiff = diffList.getDiffById(prior);
+ if (priorDiff != null && priorDiff.getSnapshotId() == prior) {
List<INode> dList = priorDiff.diff.getList(ListType.DELETED);
excludedNodes = cloneDiffList(dList);
}
- if (snapshot != null) {
+ if (snapshot != Snapshot.CURRENT_STATE_ID) {
diffList.deleteSnapshotDiff(snapshot, prior, dir, collectedBlocks,
removedINodes, true);
}
- priorDiff = diffList.getDiff(prior);
- if (priorDiff != null && priorDiff.getSnapshot().equals(prior)) {
+ priorDiff = diffList.getDiffById(prior);
+ if (priorDiff != null && priorDiff.getSnapshotId() == prior) {
priorDiff.diff.destroyCreatedList(dir, collectedBlocks,
removedINodes);
}
@@ -478,14 +483,14 @@ public class DirectoryWithSnapshotFeatur
* deleted list of prior.
* @param inode The inode to clean.
* @param post The post snapshot.
- * @param prior The prior snapshot.
+ * @param prior The id of the prior snapshot.
* @param collectedBlocks Used to collect blocks for later deletion.
* @return Quota usage update.
*/
private static Quota.Counts cleanDeletedINode(INode inode,
- final Snapshot post, final Snapshot prior,
+ final int post, final int prior,
final BlocksMapUpdateInfo collectedBlocks,
- final List<INode> removedINodes, final boolean countDiffChange)
+ final List<INode> removedINodes, final boolean countDiffChange)
throws QuotaExceededException {
Quota.Counts counts = Quota.Counts.newInstance();
Deque<INode> queue = new ArrayDeque<INode>();
@@ -494,7 +499,7 @@ public class DirectoryWithSnapshotFeatur
INode topNode = queue.pollFirst();
if (topNode instanceof INodeReference.WithName) {
INodeReference.WithName wn = (INodeReference.WithName) topNode;
- if (wn.getLastSnapshotId() >= post.getId()) {
+ if (wn.getLastSnapshotId() >= post) {
wn.cleanSubtree(post, prior, collectedBlocks, removedINodes,
countDiffChange);
}
@@ -511,8 +516,8 @@ public class DirectoryWithSnapshotFeatur
if (sf != null) {
// delete files/dirs created after prior. Note that these
// files/dirs, along with inode, were deleted right after post.
- DirectoryDiff priorDiff = sf.getDiffs().getDiff(prior);
- if (priorDiff != null && priorDiff.getSnapshot().equals(prior)) {
+ DirectoryDiff priorDiff = sf.getDiffs().getDiffById(prior);
+ if (priorDiff != null && priorDiff.getSnapshotId() == prior) {
priorChildrenDiff = priorDiff.getChildrenDiff();
counts.add(priorChildrenDiff.destroyCreatedList(dir,
collectedBlocks, removedINodes));
@@ -540,8 +545,8 @@ public class DirectoryWithSnapshotFeatur
}
/** @return the last snapshot. */
- public Snapshot getLastSnapshot() {
- return diffs.getLastSnapshot();
+ public int getLastSnapshotId() {
+ return diffs.getLastSnapshotId();
}
/** @return the snapshot diff list. */
@@ -565,11 +570,13 @@ public class DirectoryWithSnapshotFeatur
* to make sure that parent is in the given snapshot "latest".
*/
public boolean addChild(INodeDirectory parent, INode inode,
- boolean setModTime, Snapshot latest) throws QuotaExceededException {
- ChildrenDiff diff = diffs.checkAndAddLatestSnapshotDiff(latest, parent).diff;
+ boolean setModTime, int latestSnapshotId) throws QuotaExceededException {
+ ChildrenDiff diff = diffs.checkAndAddLatestSnapshotDiff(latestSnapshotId,
+ parent).diff;
int undoInfo = diff.create(inode);
- final boolean added = parent.addChild(inode, setModTime, null);
+ final boolean added = parent.addChild(inode, setModTime,
+ Snapshot.CURRENT_STATE_ID);
if (!added) {
diff.undoCreate(inode, undoInfo);
}
@@ -581,7 +588,7 @@ public class DirectoryWithSnapshotFeatur
* needs to make sure that parent is in the given snapshot "latest".
*/
public boolean removeChild(INodeDirectory parent, INode child,
- Snapshot latest) throws QuotaExceededException {
+ int latestSnapshotId) throws QuotaExceededException {
// For a directory that is not a renamed node, if isInLatestSnapshot returns
// false, the directory is not in the latest snapshot, thus we do not need
// to record the removed child in any snapshot.
@@ -593,7 +600,8 @@ public class DirectoryWithSnapshotFeatur
// directory node cannot be in any snapshot (not in current tree, nor in
// previous src tree). Thus we do not need to record the removed child in
// any snapshot.
- ChildrenDiff diff = diffs.checkAndAddLatestSnapshotDiff(latest, parent).diff;
+ ChildrenDiff diff = diffs.checkAndAddLatestSnapshotDiff(latestSnapshotId,
+ parent).diff;
UndoInfo<INode> undoInfo = diff.delete(child);
final boolean removed = parent.removeChild(child);
@@ -611,29 +619,29 @@ public class DirectoryWithSnapshotFeatur
* for the snapshot and return it.
*/
public ReadOnlyList<INode> getChildrenList(INodeDirectory currentINode,
- final Snapshot snapshot) {
- final DirectoryDiff diff = diffs.getDiff(snapshot);
+ final int snapshotId) {
+ final DirectoryDiff diff = diffs.getDiffById(snapshotId);
return diff != null ? diff.getChildrenList(currentINode) : currentINode
- .getChildrenList(null);
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
}
public INode getChild(INodeDirectory currentINode, byte[] name,
- Snapshot snapshot) {
- final DirectoryDiff diff = diffs.getDiff(snapshot);
+ int snapshotId) {
+ final DirectoryDiff diff = diffs.getDiffById(snapshotId);
return diff != null ? diff.getChild(name, true, currentINode)
- : currentINode.getChild(name, null);
+ : currentINode.getChild(name, Snapshot.CURRENT_STATE_ID);
}
/** Used to record the modification of a symlink node */
public INode saveChild2Snapshot(INodeDirectory currentINode,
- final INode child, final Snapshot latest, final INode snapshotCopy)
+ final INode child, final int latestSnapshotId, final INode snapshotCopy)
throws QuotaExceededException {
Preconditions.checkArgument(!child.isDirectory(),
"child is a directory, child=%s", child);
- Preconditions.checkArgument(latest != null);
+ Preconditions.checkArgument(latestSnapshotId != Snapshot.CURRENT_STATE_ID);
- final DirectoryDiff diff = diffs.checkAndAddLatestSnapshotDiff(latest,
- currentINode);
+ final DirectoryDiff diff = diffs.checkAndAddLatestSnapshotDiff(
+ latestSnapshotId, currentINode);
if (diff.getChild(child.getLocalNameBytes(), false, currentINode) != null) {
// it was already saved in the latest snapshot earlier.
return child;
@@ -656,7 +664,7 @@ public class DirectoryWithSnapshotFeatur
public Quota.Counts computeQuotaUsage4CurrentDirectory(Quota.Counts counts) {
for(DirectoryDiff d : diffs) {
for(INode deleted : d.getChildrenDiff().getList(ListType.DELETED)) {
- deleted.computeQuotaUsage(counts, false, Snapshot.INVALID_ID);
+ deleted.computeQuotaUsage(counts, false, Snapshot.CURRENT_STATE_ID);
}
}
counts.add(Quota.NAMESPACE, diffs.asList().size());
@@ -744,14 +752,14 @@ public class DirectoryWithSnapshotFeatur
}
public Quota.Counts cleanDirectory(final INodeDirectory currentINode,
- final Snapshot snapshot, Snapshot prior,
+ final int snapshot, int prior,
final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes, final boolean countDiffChange)
throws QuotaExceededException {
Quota.Counts counts = Quota.Counts.newInstance();
Map<INode, INode> priorCreated = null;
Map<INode, INode> priorDeleted = null;
- if (snapshot == null) { // delete the current directory
+ if (snapshot == Snapshot.CURRENT_STATE_ID) { // delete the current directory
currentINode.recordModification(prior);
// delete everything in created list
DirectoryDiff lastDiff = diffs.getLast();
@@ -764,9 +772,9 @@ public class DirectoryWithSnapshotFeatur
prior = getDiffs().updatePrior(snapshot, prior);
// if there is a snapshot diff associated with prior, we need to record
// its original created and deleted list before deleting post
- if (prior != null) {
- DirectoryDiff priorDiff = this.getDiffs().getDiff(prior);
- if (priorDiff != null && priorDiff.getSnapshot().equals(prior)) {
+ if (prior != Snapshot.NO_SNAPSHOT_ID) {
+ DirectoryDiff priorDiff = this.getDiffs().getDiffById(prior);
+ if (priorDiff != null && priorDiff.getSnapshotId() == prior) {
List<INode> cList = priorDiff.diff.getList(ListType.CREATED);
List<INode> dList = priorDiff.diff.getList(ListType.DELETED);
priorCreated = cloneDiffList(cList);
@@ -774,13 +782,13 @@ public class DirectoryWithSnapshotFeatur
}
}
- counts.add(getDiffs().deleteSnapshotDiff(snapshot, prior, currentINode,
- collectedBlocks, removedINodes, countDiffChange));
+ counts.add(getDiffs().deleteSnapshotDiff(snapshot, prior,
+ currentINode, collectedBlocks, removedINodes, countDiffChange));
// check priorDiff again since it may be created during the diff deletion
- if (prior != null) {
- DirectoryDiff priorDiff = this.getDiffs().getDiff(prior);
- if (priorDiff != null && priorDiff.getSnapshot().equals(prior)) {
+ if (prior != Snapshot.NO_SNAPSHOT_ID) {
+ DirectoryDiff priorDiff = this.getDiffs().getDiffById(prior);
+ if (priorDiff != null && priorDiff.getSnapshotId() == prior) {
// For files/directories created between "prior" and "snapshot",
// we need to clear snapshot copies for "snapshot". Note that we must
// use null as prior in the cleanSubtree call. Files/directories that
@@ -791,8 +799,8 @@ public class DirectoryWithSnapshotFeatur
for (INode cNode : priorDiff.getChildrenDiff().getList(
ListType.CREATED)) {
if (priorCreated.containsKey(cNode)) {
- counts.add(cNode.cleanSubtree(snapshot, null, collectedBlocks,
- removedINodes, countDiffChange));
+ counts.add(cNode.cleanSubtree(snapshot, Snapshot.NO_SNAPSHOT_ID,
+ collectedBlocks, removedINodes, countDiffChange));
}
}
}
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiff.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiff.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiff.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiff.java Wed Jan 8 23:10:02 2014
@@ -38,15 +38,15 @@ public class FileDiff extends
/** The file size at snapshot creation time. */
private final long fileSize;
- FileDiff(Snapshot snapshot, INodeFile file) {
- super(snapshot, null, null);
+ FileDiff(int snapshotId, INodeFile file) {
+ super(snapshotId, null, null);
fileSize = file.computeFileSize();
}
/** Constructor used by FSImage loading */
- FileDiff(Snapshot snapshot, INodeFileAttributes snapshotINode,
+ FileDiff(int snapshotId, INodeFileAttributes snapshotINode,
FileDiff posteriorDiff, long fileSize) {
- super(snapshot, snapshotINode, posteriorDiff);
+ super(snapshotId, snapshotINode, posteriorDiff);
this.fileSize = fileSize;
}
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiffList.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiffList.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiffList.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiffList.java Wed Jan 8 23:10:02 2014
@@ -25,8 +25,8 @@ public class FileDiffList extends
AbstractINodeDiffList<INodeFile, INodeFileAttributes, FileDiff> {
@Override
- FileDiff createDiff(Snapshot snapshot, INodeFile file) {
- return new FileDiff(snapshot, file);
+ FileDiff createDiff(int snapshotId, INodeFile file) {
+ return new FileDiff(snapshotId, file);
}
@Override
Modified: hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java?rev=1556665&r1=1556664&r2=1556665&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java (original)
+++ hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java Wed Jan 8 23:10:02 2014
@@ -78,22 +78,22 @@ public class FileWithSnapshotFeature imp
return (isCurrentFileDeleted()? "(DELETED), ": ", ") + diffs;
}
- public Quota.Counts cleanFile(final INodeFile file, final Snapshot snapshot,
- Snapshot prior, final BlocksMapUpdateInfo collectedBlocks,
+ public Quota.Counts cleanFile(final INodeFile file, final int snapshotId,
+ int priorSnapshotId, final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes, final boolean countDiffChange)
throws QuotaExceededException {
- if (snapshot == null) {
+ if (snapshotId == Snapshot.CURRENT_STATE_ID) {
// delete the current file while the file has snapshot feature
if (!isCurrentFileDeleted()) {
- file.recordModification(prior);
+ file.recordModification(priorSnapshotId);
deleteCurrentFile();
}
collectBlocksAndClear(file, collectedBlocks, removedINodes);
return Quota.Counts.newInstance();
} else { // delete the snapshot
- prior = getDiffs().updatePrior(snapshot, prior);
- return diffs.deleteSnapshotDiff(snapshot, prior, file, collectedBlocks,
- removedINodes, countDiffChange);
+ priorSnapshotId = getDiffs().updatePrior(snapshotId, priorSnapshotId);
+ return diffs.deleteSnapshotDiff(snapshotId, priorSnapshotId, file,
+ collectedBlocks, removedINodes, countDiffChange);
}
}