From 39d25fbac331ede57196f7a2d2d5e26e2fbc1c9f Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Mon, 10 Dec 2012 23:54:26 +0000 Subject: [PATCH] HDFS-4293. Fix TestSnapshot failure. Contributed by Jing Zhao. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2802@1419882 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-2802.txt | 2 ++ .../hadoop/hdfs/server/namenode/FSDirectory.java | 2 +- .../hadoop/hdfs/server/namenode/INodeDirectory.java | 12 +++++++----- .../server/namenode/INodeDirectoryWithQuota.java | 2 +- .../server/namenode/snapshot/SnapshotManager.java | 4 ++-- .../snapshot/TestINodeDirectoryWithSnapshot.java | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index 9e743ab1727..55c3375a73c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt @@ -81,3 +81,5 @@ Branch-2802 Snapshot (Unreleased) HDFS-4175. Additional snapshot tests for more complicated directory structure and modifications. (Jing Zhao via suresh) + + HDFS-4293. Fix TestSnapshot failure. (Jing Zhao via suresh) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java index 6403955d4e5..1dda45cc70b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java @@ -2008,7 +2008,7 @@ public class FSDirectory implements Closeable { ((INodeDirectoryWithQuota)dirNode).setQuota(nsQuota, dsQuota); if (!dirNode.isQuotaSet()) { // will not come here for root because root's nsQuota is always set - INodeDirectory newNode = new INodeDirectory(dirNode); + INodeDirectory newNode = new INodeDirectory(dirNode, true); INodeDirectory parent = (INodeDirectory)inodes[inodes.length-2]; dirNode = newNode; parent.replaceChild(newNode); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java index 94d35c3ae33..ad4869c869b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java @@ -73,14 +73,16 @@ public class INodeDirectory extends INode { super(name, permissions, null, mtime, 0L); } - /** copy constructor - * - * @param other + /** + * Copy constructor + * @param other The INodeDirectory to be copied + * @param adopt Indicate whether or not need to set the parent field of child + * INodes to the new node */ - public INodeDirectory(INodeDirectory other) { + public INodeDirectory(INodeDirectory other, boolean adopt) { super(other); this.children = other.children; - if (this.children != null) { + if (adopt && this.children != null) { for (INode child : children) { child.parent = this; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectoryWithQuota.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectoryWithQuota.java index 504f2e5aa58..a41b078c43b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectoryWithQuota.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectoryWithQuota.java @@ -44,7 +44,7 @@ public class INodeDirectoryWithQuota extends INodeDirectory { */ protected INodeDirectoryWithQuota(long nsQuota, long dsQuota, INodeDirectory other) { - super(other); + super(other, true); INode.DirCounts counts = new INode.DirCounts(); other.spaceConsumedInTree(counts); this.nsCount = counts.getNsCount(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java index ef41b966e77..878df282c8d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java @@ -97,7 +97,7 @@ public class SnapshotManager implements SnapshotStats { + "Please redo the operation after removing all the snapshots."); } - final INodeDirectory d = new INodeDirectory(s); + final INodeDirectory d = new INodeDirectory(s, true); fsdir.replaceINodeDirectory(path, s, d); snapshottables.remove(s); @@ -198,7 +198,7 @@ public class SnapshotManager implements SnapshotStats { */ private INodeDirectory processINodeDirectory(final INodeDirectory srcChild ) throws IOException { - final INodeDirectory dstChild = new INodeDirectory(srcChild); + final INodeDirectory dstChild = new INodeDirectory(srcChild, false); dstChild.setChildren(null); processRecursively(srcChild, dstChild); return dstChild; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestINodeDirectoryWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestINodeDirectoryWithSnapshot.java index 1e8ac0f3986..0835a3bda61 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestINodeDirectoryWithSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestINodeDirectoryWithSnapshot.java @@ -220,7 +220,7 @@ public class TestINodeDirectoryWithSnapshot { final int i = Diff.search(current, inode); Assert.assertTrue(i >= 0); final INodeDirectory oldinode = (INodeDirectory)current.get(i); - final INodeDirectory newinode = new INodeDirectory(oldinode); + final INodeDirectory newinode = new INodeDirectory(oldinode, true); newinode.setModificationTime(oldinode.getModificationTime() + 1); current.set(i, newinode);