Browse Source

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
Tsz-wo Sze 12 years ago
parent
commit
98b416f5ac

+ 3 - 0
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)

+ 11 - 4
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());
+    }
   }
   
   /**

+ 13 - 0
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();