Просмотр исходного кода

HDFS-4650. When passing two non-existing snapshot names to snapshotDiff, it returns success if the names are the same. Contributed by Jing Zhao

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2802@1476408 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 12 лет назад
Родитель
Сommit
a5ae562d70

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt

@@ -312,3 +312,6 @@ Branch-2802 Snapshot (Unreleased)
   HDFS-4650. Fix a bug in FSDirectory and add more unit tests for rename with
   HDFS-4650. Fix a bug in FSDirectory and add more unit tests for rename with
   existence of snapshottable directories and snapshots.  (Jing Zhao via
   existence of snapshottable directories and snapshots.  (Jing Zhao via
   szetszwo)
   szetszwo)
+
+  HDFS-4650. When passing two non-existing snapshot names to snapshotDiff, it
+  returns success if the names are the same.  (Jing Zhao via szetszwo)

+ 5 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectorySnapshottable.java

@@ -371,7 +371,11 @@ public class INodeDirectorySnapshottable extends INodeDirectoryWithSnapshot {
   SnapshotDiffInfo computeDiff(final String from, final String to)
   SnapshotDiffInfo computeDiff(final String from, final String to)
       throws SnapshotException {
       throws SnapshotException {
     Snapshot fromSnapshot = getSnapshotByName(from);
     Snapshot fromSnapshot = getSnapshotByName(from);
-    Snapshot toSnapshot = getSnapshotByName(to); 
+    Snapshot toSnapshot = getSnapshotByName(to);
+    // if the start point is equal to the end point, return null
+    if (from.equals(to)) {
+      return null;
+    }
     SnapshotDiffInfo diffs = new SnapshotDiffInfo(this, fromSnapshot,
     SnapshotDiffInfo diffs = new SnapshotDiffInfo(this, fromSnapshot,
         toSnapshot);
         toSnapshot);
     computeDiffRecursively(this, new ArrayList<byte[]>(), diffs);
     computeDiffRecursively(this, new ArrayList<byte[]>(), diffs);

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

@@ -289,10 +289,6 @@ public class SnapshotManager implements SnapshotStats {
       // both fromSnapshot and toSnapshot indicate the current tree
       // both fromSnapshot and toSnapshot indicate the current tree
       return null;
       return null;
     }
     }
-    // if the start point is equal to the end point, return null
-    if (from.equals(to)) {
-      return null;
-    }
 
 
     // Find the source root directory path where the snapshots were taken.
     // Find the source root directory path where the snapshots were taken.
     // All the check for path has been included in the valueOf method.
     // All the check for path has been included in the valueOf method.

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

@@ -186,6 +186,16 @@ public class TestSnapshotDiffReport {
           "Directory is not a snapshottable directory: " + subsub1, e);
           "Directory is not a snapshottable directory: " + subsub1, e);
     }
     }
     
     
+    final String invalidName = "invalid";
+    try {
+      hdfs.getSnapshotDiffReport(sub1, invalidName, invalidName);
+      fail("Expect exception when providing invalid snapshot name for diff report");
+    } catch (IOException e) {
+      GenericTestUtils.assertExceptionContains(
+          "Cannot find the snapshot of directory " + sub1 + " with name "
+              + invalidName, e);
+    }
+    
     // diff between the same snapshot
     // diff between the same snapshot
     SnapshotDiffReport report = hdfs.getSnapshotDiffReport(sub1, "s0", "s0");
     SnapshotDiffReport report = hdfs.getSnapshotDiffReport(sub1, "s0", "s0");
     System.out.println(report);
     System.out.println(report);