From 98b416f5ac53d46d31c7f68013762ea5f5e257e1 Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Mon, 6 May 2013 22:48:54 +0000 Subject: [PATCH] HDFS-4801. lsSnapshottableDir throws IllegalArgumentException when root is snapshottable. Contributed by Jing Zhao git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2802@1479709 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-2802.txt | 3 +++ .../protocol/SnapshottableDirectoryStatus.java | 15 +++++++++++---- .../snapshot/TestSnapshottableDirListing.java | 13 +++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index e599bc8ca8a..2346ca3ba0a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt @@ -341,3 +341,6 @@ Branch-2802 Snapshot (Unreleased) HDFS-4800. Fix INodeDirectoryWithSnapshot#cleanDeletedINode. (Jing Zhao via szetszwo) + + HDFS-4801. lsSnapshottableDir throws IllegalArgumentException when root is + snapshottable. (Jing Zhao via szetszwo) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java index c1f9388eef3..2300fc31d93 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java @@ -98,10 +98,17 @@ public class SnapshottableDirectoryStatus { * @return Full path of the file */ public Path getFullPath() { - String parentFullPathStr = (parentFullPath == null || parentFullPath.length == 0) ? null - : DFSUtil.bytes2String(parentFullPath); - return parentFullPathStr == null ? new Path(dirStatus.getLocalName()) - : new Path(parentFullPathStr, dirStatus.getLocalName()); + String parentFullPathStr = + (parentFullPath == null || parentFullPath.length == 0) ? + null : DFSUtil.bytes2String(parentFullPath); + if (parentFullPathStr == null + && dirStatus.getLocalNameInBytes().length == 0) { + // root + return new Path("/"); + } else { + return parentFullPathStr == null ? new Path(dirStatus.getLocalName()) + : new Path(parentFullPathStr, dirStatus.getLocalName()); + } } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshottableDirListing.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshottableDirListing.java index 66728b9ca68..89888060741 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshottableDirListing.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshottableDirListing.java @@ -81,6 +81,19 @@ public class TestSnapshottableDirListing { SnapshottableDirectoryStatus[] dirs = hdfs.getSnapshottableDirListing(); assertNull(dirs); + // Make root as snapshottable + final Path root = new Path("/"); + hdfs.allowSnapshot(root); + dirs = hdfs.getSnapshottableDirListing(); + assertEquals(1, dirs.length); + assertEquals("", dirs[0].getDirStatus().getLocalName()); + assertEquals(root, dirs[0].getFullPath()); + + // Make root non-snaphsottable + hdfs.disallowSnapshot(root); + dirs = hdfs.getSnapshottableDirListing(); + assertNull(dirs); + // Make dir1 as snapshottable hdfs.allowSnapshot(dir1); dirs = hdfs.getSnapshottableDirListing();