瀏覽代碼

HDFS-16496. Snapshot diff on snapshotable directory fails with not snapshottable error (#4051)

Stephen O'Donnell 3 年之前
父節點
當前提交
49e4e4d0a5

+ 3 - 3
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java

@@ -391,8 +391,8 @@ public class SnapshotManager implements SnapshotStatsMXBean {
       final INodesInPath iip) throws IOException {
     final INodeDirectory dir = getSnapshottableAncestorDir(iip);
     if (dir == null) {
-      throw new SnapshotException("Directory is neither snapshottable nor" +
-          " under a snap root!");
+      throw new SnapshotException("The path " + iip.getPath()
+          + " is neither snapshottable nor under a snapshot root!");
     }
     return dir;
   }
@@ -402,7 +402,7 @@ public class SnapshotManager implements SnapshotStatsMXBean {
     final String path = iip.getPath();
     final INode inode = iip.getLastINode();
     final INodeDirectory dir;
-    if (inode instanceof INodeDirectory) {
+    if (inode != null && inode.isDirectory()) {
       dir = INodeDirectory.valueOf(inode, path);
     } else {
       dir = INodeDirectory.valueOf(iip.getINode(-2), iip.getParentPath());

+ 2 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java

@@ -345,7 +345,8 @@ public class TestSnapshotDiffReport {
           + nonSnapDir.getName() + "'should fail!");
     } catch (SnapshotException e) {
       GenericTestUtils.assertExceptionContains(
-          "Directory is neither snapshottable nor under a snap root!", e);
+          "The path " + nonSnapDir +
+              " is neither snapshottable nor under a snapshot root!", e);
     }
 
     final String invalidName = "invalid";