diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index 9be2d5268cc..bcf59fdce6f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt @@ -190,3 +190,5 @@ Branch-2802 Snapshot (Unreleased) (Jing Zhao via szetszwo) HDFS-4579. Annotate snapshot tests. (Arpit Agarwal via suresh) + + HDFS-4574. Move Diff to the util package. (szetszwo) 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 7c21117af7c..1b2da6f4ba6 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 @@ -1558,7 +1558,7 @@ public class FSDirectory implements Closeable { private static INode[] getRelativePathINodes(INode inode, INode ancestor) { // calculate the depth of this inode from the ancestor int depth = 0; - for (INode i = inode; i != null && !i.equals(ancestor); i = i.parent) { + for (INode i = inode; i != null && !i.equals(ancestor); i = i.getParent()) { depth++; } INode[] inodes = new INode[depth]; @@ -1571,7 +1571,7 @@ public class FSDirectory implements Closeable { return null; } inodes[depth-i-1] = inode; - inode = inode.parent; + inode = inode.getParent(); } return inodes; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java index 4d2953a11ed..f951ce85b55 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java @@ -34,8 +34,10 @@ import org.apache.hadoop.hdfs.DFSUtil; import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.NSQuotaExceededException; import org.apache.hadoop.hdfs.server.namenode.INode.Content.CountsMap.Key; +import org.apache.hadoop.hdfs.server.namenode.snapshot.FileWithSnapshot; +import org.apache.hadoop.hdfs.server.namenode.snapshot.INodeDirectoryWithSnapshot; import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot; -import org.apache.hadoop.hdfs.server.namenode.snapshot.diff.Diff; +import org.apache.hadoop.hdfs.util.Diff; import org.apache.hadoop.util.StringUtils; import com.google.common.annotations.VisibleForTesting; @@ -109,7 +111,7 @@ public abstract class INode implements Diff.Element { * should not modify it. */ private long permission = 0L; - INodeDirectory parent = null; + private INodeDirectory parent = null; private long modificationTime = 0L; private long accessTime = 0L; @@ -509,16 +511,6 @@ public abstract class INode implements Diff.Element { return name == null? null: DFSUtil.bytes2String(name); } - - String getLocalParentDir() { - INode inode = isRoot() ? this : getParent(); - String parentDir = ""; - if (inode != null) { - parentDir = inode.getFullPathName(); - } - return (parentDir != null) ? parentDir : ""; - } - /** * @return null if the local name is null; * otherwise, return the local name byte array. @@ -532,13 +524,6 @@ public abstract class INode implements Diff.Element { return getLocalNameBytes(); } - /** - * Set local file name - */ - public void setLocalName(String name) { - setLocalName(DFSUtil.string2Bytes(name)); - } - /** * Set local file name */ 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 0f65a5edf9b..3035991c39e 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 @@ -82,7 +82,7 @@ public class INodeDirectory extends INode { this.children = other.children; if (adopt && this.children != null) { for (INode child : children) { - child.parent = this; + child.setParent(this); } } } @@ -529,7 +529,7 @@ public class INodeDirectory extends INode { if (children == null) { children = new ArrayList(DEFAULT_FILES_PER_DIRECTORY); } - node.parent = this; + node.setParent(this); children.add(-insertionPoint - 1, node); if (node.getGroupName() == null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java index d4b639d2c80..8fe9886e6b6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java @@ -157,7 +157,7 @@ public class INodeFile extends INode implements BlockCollection { public INodeFile recordModification(final Snapshot latest) throws NSQuotaExceededException { return isInLatestSnapshot(latest)? - parent.replaceChild4INodeFileWithSnapshot(this) + getParent().replaceChild4INodeFileWithSnapshot(this) .recordModification(latest) : this; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFileUnderConstruction.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFileUnderConstruction.java index 800ed15ed83..ff1075d45d1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFileUnderConstruction.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFileUnderConstruction.java @@ -133,7 +133,7 @@ public class INodeFileUnderConstruction extends INodeFile implements MutableBloc public INodeFileUnderConstruction recordModification(final Snapshot latest) throws NSQuotaExceededException { return isInLatestSnapshot(latest)? - parent.replaceChild4INodeFileUcWithSnapshot(this) + getParent().replaceChild4INodeFileUcWithSnapshot(this) .recordModification(latest) : this; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java index 2532d1d2e6f..916334e34c1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java @@ -47,7 +47,7 @@ public class INodeSymlink extends INode { @Override INode recordModification(Snapshot latest) throws NSQuotaExceededException { return isInLatestSnapshot(latest)? - parent.saveChild2Snapshot(this, latest, new INodeSymlink(this)) + getParent().saveChild2Snapshot(this, latest, new INodeSymlink(this)) : this; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java index d13ace018d6..321d9262acd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeJspHelper.java @@ -775,7 +775,16 @@ class NamenodeJspHelper { } } } - + + private static String getLocalParentDir(INode inode) { + final INode parent = inode.isRoot() ? inode : inode.getParent(); + String parentDir = ""; + if (parent != null) { + parentDir = parent.getFullPathName(); + } + return (parentDir != null) ? parentDir : ""; + } + // utility class used in block_info_xml.jsp static class XMLBlockInfo { final Block block; @@ -817,7 +826,7 @@ class NamenodeJspHelper { doc.endTag(); doc.startTag("local_directory"); - doc.pcdata(inode.getLocalParentDir()); + doc.pcdata(getLocalParentDir(inode)); doc.endTag(); doc.startTag("user_name"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java index a9db43fd194..cc18844a23c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java @@ -227,7 +227,8 @@ public class INodeDirectorySnapshottable extends INodeDirectoryWithSnapshot { throw new SnapshotException("The snapshot " + oldName + " does not exist for directory " + path); } else { - int indexOfNew = searchSnapshot(DFSUtil.string2Bytes(newName)); + final byte[] newNameBytes = DFSUtil.string2Bytes(newName); + int indexOfNew = searchSnapshot(newNameBytes); if (indexOfNew > 0) { throw new SnapshotException("The snapshot " + newName + " already exists for directory " + path); @@ -235,7 +236,7 @@ public class INodeDirectorySnapshottable extends INodeDirectoryWithSnapshot { // remove the one with old name from snapshotsByNames Snapshot snapshot = snapshotsByNames.remove(indexOfOld); final INodeDirectory ssRoot = snapshot.getRoot(); - ssRoot.setLocalName(newName); + ssRoot.setLocalName(newNameBytes); indexOfNew = -indexOfNew - 1; if (indexOfNew <= indexOfOld) { snapshotsByNames.add(indexOfNew, snapshot); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java index 58d8cc8ca6f..57476acb7e7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java @@ -30,13 +30,13 @@ import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry; import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffType; import org.apache.hadoop.hdfs.server.namenode.FSImageSerialization; import org.apache.hadoop.hdfs.server.namenode.INode; -import org.apache.hadoop.hdfs.server.namenode.Quota; import org.apache.hadoop.hdfs.server.namenode.INode.Content.CountsMap.Key; import org.apache.hadoop.hdfs.server.namenode.INodeDirectory; import org.apache.hadoop.hdfs.server.namenode.INodeDirectoryWithQuota; -import org.apache.hadoop.hdfs.server.namenode.snapshot.diff.Diff; -import org.apache.hadoop.hdfs.server.namenode.snapshot.diff.Diff.Container; -import org.apache.hadoop.hdfs.server.namenode.snapshot.diff.Diff.UndoInfo; +import org.apache.hadoop.hdfs.server.namenode.Quota; +import org.apache.hadoop.hdfs.util.Diff; +import org.apache.hadoop.hdfs.util.Diff.Container; +import org.apache.hadoop.hdfs.util.Diff.UndoInfo; import org.apache.hadoop.hdfs.util.ReadOnlyList; import com.google.common.base.Preconditions; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/diff/Diff.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/Diff.java similarity index 99% rename from hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/diff/Diff.java rename to hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/Diff.java index af85cc0840b..b912d218596 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/diff/Diff.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/Diff.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hdfs.server.namenode.snapshot.diff; +package org.apache.hadoop.hdfs.util; import java.util.ArrayList; import java.util.Collections; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java index 89792c88ba1..e8b7efc58dc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java @@ -139,7 +139,7 @@ public class TestINodeFile { replication = 3; preferredBlockSize = 128*1024*1024; INodeFile inf = createINodeFile(replication, preferredBlockSize); - inf.setLocalName("f"); + inf.setLocalName(DFSUtil.string2Bytes("f")); INodeDirectory root = new INodeDirectory(INodeId.GRANDFATHER_INODE_ID, INodeDirectory.ROOT_NAME, perm, 0L); @@ -147,19 +147,15 @@ public class TestINodeFile { DFSUtil.string2Bytes("d"), perm, 0L); assertEquals("f", inf.getFullPathName()); - assertEquals("", inf.getLocalParentDir()); dir.addChild(inf); assertEquals("d"+Path.SEPARATOR+"f", inf.getFullPathName()); - assertEquals("d", inf.getLocalParentDir()); root.addChild(dir); assertEquals(Path.SEPARATOR+"d"+Path.SEPARATOR+"f", inf.getFullPathName()); assertEquals(Path.SEPARATOR+"d", dir.getFullPathName()); assertEquals(Path.SEPARATOR, root.getFullPathName()); - assertEquals(Path.SEPARATOR, root.getLocalParentDir()); - } /** @@ -229,7 +225,7 @@ public class TestINodeFile { for (int i = 0; i < nCount; i++) { iNodes[i] = new INodeFile(i, null, perm, 0L, 0L, null, replication, preferredBlockSize); - iNodes[i].setLocalName(fileNamePrefix + Integer.toString(i)); + iNodes[i].setLocalName(DFSUtil.string2Bytes(fileNamePrefix + i)); BlockInfo newblock = new BlockInfo(replication); iNodes[i].addBlock(newblock); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/diff/TestDiff.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestDiff.java similarity index 97% rename from hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/diff/TestDiff.java rename to hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestDiff.java index c3d8b89cea8..f8cb13b4569 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/diff/TestDiff.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestDiff.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hdfs.server.namenode.snapshot.diff; +package org.apache.hadoop.hdfs.util; import java.util.ArrayList; import java.util.List; @@ -26,8 +26,9 @@ import org.apache.hadoop.fs.permission.PermissionStatus; import org.apache.hadoop.hdfs.DFSUtil; import org.apache.hadoop.hdfs.server.namenode.INode; import org.apache.hadoop.hdfs.server.namenode.INodeDirectory; -import org.apache.hadoop.hdfs.server.namenode.snapshot.diff.Diff.Container; -import org.apache.hadoop.hdfs.server.namenode.snapshot.diff.Diff.UndoInfo; +import org.apache.hadoop.hdfs.util.Diff; +import org.apache.hadoop.hdfs.util.Diff.Container; +import org.apache.hadoop.hdfs.util.Diff.UndoInfo; import org.junit.Assert; import org.junit.Test; @@ -45,7 +46,7 @@ public class TestDiff { } /** Test directory diff. */ - @Test + @Test(timeout=60000) public void testDiff() throws Exception { for(int startSize = 0; startSize <= 1000; startSize = nextStep(startSize)) { for(int m = 0; m <= 10000; m = nextStep(m)) {