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 ji...@apache.org on 2014/01/09 01:53:08 UTC
svn commit: r1556688 [3/5] - in
/hadoop/common/branches/HDFS-5698/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/ hadoop-hdfs/...
Modified: hadoop/common/branches/HDFS-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java Thu Jan 9 00:53:04 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;
@@ -282,26 +285,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;
}
@@ -317,23 +321,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();
@@ -351,9 +354,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;
}
@@ -431,22 +435,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();
@@ -490,17 +494,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();
@@ -511,7 +516,7 @@ public class INodeFile extends INodeWith
}
@Override
- public final ContentSummaryComputationContext computeContentSummary(
+ public final ContentSummaryComputationContext computeContentSummary(
final ContentSummaryComputationContext summary) {
computeContentSummary4Snapshot(summary.getCounts());
computeContentSummary4Current(summary.getCounts());
@@ -550,23 +555,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);
}
@@ -617,9 +620,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();
}
@@ -648,9 +652,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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeMap.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeMap.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeMap.java Thu Jan 9 00:53:04 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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeReference.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeReference.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeReference.java Thu Jan 9 00:53:04 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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java Thu Jan 9 00:53:04 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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java Thu Jan 9 00:53:04 2014
@@ -154,9 +154,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) {
@@ -164,9 +164,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);
@@ -180,9 +180,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);
@@ -196,9 +196,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());
@@ -220,9 +220,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;
@@ -231,13 +231,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) {
@@ -250,11 +250,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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java Thu Jan 9 00:53:04 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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java Thu Jan 9 00:53:04 2014
@@ -480,6 +480,14 @@ public class NameNode implements NameNod
* @param conf the configuration
*/
protected void initialize(Configuration conf) throws IOException {
+ if (conf.get(HADOOP_USER_GROUP_METRICS_PERCENTILES_INTERVALS) == null) {
+ String intervals = conf.get(DFS_METRICS_PERCENTILES_INTERVALS_KEY);
+ if (intervals != null) {
+ conf.set(HADOOP_USER_GROUP_METRICS_PERCENTILES_INTERVALS,
+ intervals);
+ }
+ }
+
UserGroupInformation.setConfiguration(conf);
loginAsNameNodeUser(conf);
Modified: hadoop/common/branches/HDFS-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiff.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiff.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiff.java Thu Jan 9 00:53:04 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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java Thu Jan 9 00:53:04 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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectoryWithSnapshotFeature.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectoryWithSnapshotFeature.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectoryWithSnapshotFeature.java Thu Jan 9 00:53:04 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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiff.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiff.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiff.java Thu Jan 9 00:53:04 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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiffList.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiffList.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileDiffList.java Thu Jan 9 00:53:04 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-5698/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-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java Thu Jan 9 00:53:04 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);
}
}
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java Thu Jan 9 00:53:04 2014
@@ -206,6 +206,15 @@ public class INodeDirectorySnapshottable
return i < 0? null: snapshotsByNames.get(i);
}
+ Snapshot getSnapshotById(int sid) {
+ for (Snapshot s : snapshotsByNames) {
+ if (s.getId() == sid) {
+ return s;
+ }
+ }
+ return null;
+ }
+
/** @return {@link #snapshotsByNames} as a {@link ReadOnlyList} */
public ReadOnlyList<Snapshot> getSnapshotList() {
return ReadOnlyList.Util.asReadOnlyList(snapshotsByNames);
@@ -297,13 +306,14 @@ public class INodeDirectorySnapshottable
+ "snapshot with the same name \"" + Snapshot.getSnapshotName(s) + "\".");
}
- final DirectoryDiff d = getDiffs().addDiff(s, this);
- d.snapshotINode = s.getRoot();
+ final DirectoryDiff d = getDiffs().addDiff(id, this);
+ d.setSnapshotRoot(s.getRoot());
snapshotsByNames.add(-i - 1, s);
//set modification time
- updateModificationTime(Time.now(), null);
- s.getRoot().setModificationTime(getModificationTime(), null);
+ updateModificationTime(Time.now(), Snapshot.CURRENT_STATE_ID);
+ s.getRoot().setModificationTime(getModificationTime(),
+ Snapshot.CURRENT_STATE_ID);
return s;
}
@@ -326,10 +336,10 @@ public class INodeDirectorySnapshottable
+ ": the snapshot does not exist.");
} else {
final Snapshot snapshot = snapshotsByNames.get(i);
- Snapshot prior = Snapshot.findLatestSnapshot(this, snapshot);
+ int prior = Snapshot.findLatestSnapshot(this, snapshot.getId());
try {
- Quota.Counts counts = cleanSubtree(snapshot, prior, collectedBlocks,
- removedINodes, true);
+ Quota.Counts counts = cleanSubtree(snapshot.getId(), prior,
+ collectedBlocks, removedINodes, true);
INodeDirectory parent = getParent();
if (parent != null) {
// there will not be any WithName node corresponding to the deleted
@@ -425,8 +435,9 @@ public class INodeDirectorySnapshottable
diffReport.addDirDiff(dir, relativePath, diff);
}
}
- ReadOnlyList<INode> children = dir.getChildrenList(diffReport
- .isFromEarlier() ? diffReport.to : diffReport.from);
+ ReadOnlyList<INode> children = dir.getChildrenList(
+ diffReport.isFromEarlier() ? Snapshot.getSnapshotId(diffReport.to) :
+ Snapshot.getSnapshotId(diffReport.from));
for (INode child : children) {
final byte[] name = child.getLocalNameBytes();
if (diff.searchIndex(ListType.CREATED, name) < 0
@@ -454,16 +465,15 @@ public class INodeDirectorySnapshottable
* Replace itself with {@link INodeDirectoryWithSnapshot} or
* {@link INodeDirectory} depending on the latest snapshot.
*/
- INodeDirectory replaceSelf(final Snapshot latest, final INodeMap inodeMap)
+ INodeDirectory replaceSelf(final int latestSnapshotId, final INodeMap inodeMap)
throws QuotaExceededException {
- if (latest == null) {
- Preconditions.checkState(
- getDirectoryWithSnapshotFeature().getLastSnapshot() == null,
- "latest == null but getLastSnapshot() != null, this=%s", this);
+ if (latestSnapshotId == Snapshot.CURRENT_STATE_ID) {
+ Preconditions.checkState(getDirectoryWithSnapshotFeature()
+ .getLastSnapshotId() == Snapshot.CURRENT_STATE_ID, "this=%s", this);
}
INodeDirectory dir = replaceSelf4INodeDirectory(inodeMap);
- if (latest != null) {
- dir.recordModification(latest);
+ if (latestSnapshotId != Snapshot.CURRENT_STATE_ID) {
+ dir.recordModification(latestSnapshotId);
}
return dir;
}
@@ -475,10 +485,10 @@ public class INodeDirectorySnapshottable
@Override
public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
- Snapshot snapshot) {
+ int snapshot) {
super.dumpTreeRecursively(out, prefix, snapshot);
- if (snapshot == null) {
+ if (snapshot == Snapshot.CURRENT_STATE_ID) {
out.println();
out.print(prefix);
@@ -494,7 +504,8 @@ public class INodeDirectorySnapshottable
n++;
}
}
- Preconditions.checkState(n == snapshotsByNames.size());
+ Preconditions.checkState(n == snapshotsByNames.size(), "#n=" + n
+ + ", snapshotsByNames.size()=" + snapshotsByNames.size());
out.print(", #snapshot=");
out.println(n);
@@ -522,8 +533,9 @@ public class INodeDirectorySnapshottable
@Override
public SnapshotAndINode next() {
- final Snapshot s = next.snapshot;
- final SnapshotAndINode pair = new SnapshotAndINode(s);
+ final SnapshotAndINode pair = new SnapshotAndINode(next
+ .getSnapshotId(), getSnapshotById(next.getSnapshotId())
+ .getRoot());
next = findNext();
return pair;
}
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java Thu Jan 9 00:53:04 2014
@@ -37,7 +37,11 @@ import org.apache.hadoop.hdfs.util.ReadO
/** Snapshot of a sub-tree in the namesystem. */
@InterfaceAudience.Private
public class Snapshot implements Comparable<byte[]> {
- public static final int INVALID_ID = -1;
+ /**
+ * This id is used to indicate the current state (vs. snapshots)
+ */
+ public static final int CURRENT_STATE_ID = Integer.MAX_VALUE - 1;
+ public static final int NO_SNAPSHOT_ID = -1;
/**
* The pattern for generating the default snapshot name.
@@ -61,14 +65,18 @@ public class Snapshot implements Compara
.toString();
}
- /**
- * Get the name of the given snapshot.
+ /**
+ * Get the name of the given snapshot.
* @param s The given snapshot.
* @return The name of the snapshot, or an empty string if {@code s} is null
*/
static String getSnapshotName(Snapshot s) {
return s != null ? s.getRoot().getLocalName() : "";
}
+
+ public static int getSnapshotId(Snapshot s) {
+ return s == null ? CURRENT_STATE_ID : s.getId();
+ }
/**
* Compare snapshot with IDs, where null indicates the current status thus
@@ -78,9 +86,8 @@ public class Snapshot implements Compara
= new Comparator<Snapshot>() {
@Override
public int compare(Snapshot left, Snapshot right) {
- return ID_INTEGER_COMPARATOR.compare(
- left == null? null: left.getId(),
- right == null? null: right.getId());
+ return ID_INTEGER_COMPARATOR.compare(Snapshot.getSnapshotId(left),
+ Snapshot.getSnapshotId(right));
}
};
@@ -92,12 +99,9 @@ public class Snapshot implements Compara
= new Comparator<Integer>() {
@Override
public int compare(Integer left, Integer right) {
- // null means the current state, thus should be the largest
- if (left == null) {
- return right == null? 0: 1;
- } else {
- return right == null? -1: left - right;
- }
+ // Snapshot.CURRENT_STATE_ID means the current state, thus should be the
+ // largest
+ return left - right;
}
};
@@ -108,12 +112,12 @@ public class Snapshot implements Compara
* is not null).
*
* @param inode the given inode that the returned snapshot needs to cover
- * @param anchor the returned snapshot should be taken before this snapshot.
- * @return the latest snapshot covers the given inode and was taken before the
- * the given snapshot (if it is not null).
+ * @param anchor the returned snapshot should be taken before this given id.
+ * @return id of the latest snapshot that covers the given inode and was taken
+ * before the the given snapshot (if it is not null).
*/
- public static Snapshot findLatestSnapshot(INode inode, Snapshot anchor) {
- Snapshot latest = null;
+ public static int findLatestSnapshot(INode inode, final int anchor) {
+ int latest = NO_SNAPSHOT_ID;
for(; inode != null; inode = inode.getParent()) {
if (inode.isDirectory()) {
final INodeDirectory dir = inode.asDirectory();
@@ -139,13 +143,13 @@ public class Snapshot implements Compara
}
@Override
- public ReadOnlyList<INode> getChildrenList(Snapshot snapshot) {
- return getParent().getChildrenList(snapshot);
+ public ReadOnlyList<INode> getChildrenList(int snapshotId) {
+ return getParent().getChildrenList(snapshotId);
}
@Override
- public INode getChild(byte[] name, Snapshot snapshot) {
- return getParent().getChild(name, snapshot);
+ public INode getChild(byte[] name, int snapshotId) {
+ return getParent().getChild(name, snapshotId);
}
@Override
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java Thu Jan 9 00:53:04 2014
@@ -118,7 +118,7 @@ public class SnapshotFSImageFormat {
private static FileDiff loadFileDiff(FileDiff posterior, DataInput in,
FSImageFormat.Loader loader) throws IOException {
- // 1. Read the full path of the Snapshot root to identify the Snapshot
+ // 1. Read the id of the Snapshot root to identify the Snapshot
final Snapshot snapshot = loader.getSnapshot(in);
// 2. Load file size
@@ -128,7 +128,7 @@ public class SnapshotFSImageFormat {
final INodeFileAttributes snapshotINode = in.readBoolean()?
loader.loadINodeFileAttributes(in): null;
- return new FileDiff(snapshot, snapshotINode, posterior, fileSize);
+ return new FileDiff(snapshot.getId(), snapshotINode, posterior, fileSize);
}
/**
@@ -149,7 +149,8 @@ public class SnapshotFSImageFormat {
} // else go to the next SnapshotDiff
}
// use the current child
- INode currentChild = parent.getChild(createdNodeName, null);
+ INode currentChild = parent.getChild(createdNodeName,
+ Snapshot.CURRENT_STATE_ID);
if (currentChild == null) {
throw new IOException("Cannot find an INode associated with the INode "
+ DFSUtil.bytes2String(createdNodeName)
@@ -295,9 +296,9 @@ public class SnapshotFSImageFormat {
// 6. Compose the SnapshotDiff
List<DirectoryDiff> diffs = parent.getDiffs().asList();
- DirectoryDiff sdiff = new DirectoryDiff(snapshot, snapshotINode,
- diffs.isEmpty() ? null : diffs.get(0),
- childrenSize, createdList, deletedList);
+ DirectoryDiff sdiff = new DirectoryDiff(snapshot.getId(), snapshotINode,
+ diffs.isEmpty() ? null : diffs.get(0), childrenSize, createdList,
+ deletedList, snapshotINode == snapshot.getRoot());
return sdiff;
}
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java Thu Jan 9 00:53:04 2014
@@ -114,7 +114,7 @@ public class SnapshotManager implements
s = (INodeDirectorySnapshottable)d;
s.setSnapshotQuota(INodeDirectorySnapshottable.SNAPSHOT_LIMIT);
} else {
- s = d.replaceSelf4INodeDirectorySnapshottable(iip.getLatestSnapshot(),
+ s = d.replaceSelf4INodeDirectorySnapshottable(iip.getLatestSnapshotId(),
fsdir.getINodeMap());
}
addSnapshottable(s);
@@ -160,7 +160,7 @@ public class SnapshotManager implements
if (s == fsdir.getRoot()) {
s.setSnapshotQuota(0);
} else {
- s.replaceSelf(iip.getLatestSnapshot(), fsdir.getINodeMap());
+ s.replaceSelf(iip.getLatestSnapshotId(), fsdir.getINodeMap());
}
removeSnapshottable(s);
}
@@ -324,7 +324,8 @@ public class SnapshotManager implements
SnapshottableDirectoryStatus status = new SnapshottableDirectoryStatus(
dir.getModificationTime(), dir.getAccessTime(),
dir.getFsPermission(), dir.getUserName(), dir.getGroupName(),
- dir.getLocalNameBytes(), dir.getId(), dir.getChildrenNum(null),
+ dir.getLocalNameBytes(), dir.getId(),
+ dir.getChildrenNum(Snapshot.CURRENT_STATE_ID),
dir.getNumSnapshots(),
dir.getSnapshotQuota(), dir.getParent() == null ?
DFSUtil.EMPTY_BYTES :