diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index 8e148968f8e..ee6e5bde45d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt +++ b/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 existence of snapshottable directories and snapshots. (Jing Zhao via 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) 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 fd2c2abb5ef..452b2380016 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 @@ -371,7 +371,11 @@ public class INodeDirectorySnapshottable extends INodeDirectoryWithSnapshot { SnapshotDiffInfo computeDiff(final String from, final String to) throws SnapshotException { 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, toSnapshot); computeDiffRecursively(this, new ArrayList(), diffs); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java index 325be95ce19..7bee746fc79 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java +++ b/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 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. // All the check for path has been included in the valueOf method. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java index 66417b02e31..029af2cfa92 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java +++ b/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); } + 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 SnapshotDiffReport report = hdfs.getSnapshotDiffReport(sub1, "s0", "s0"); System.out.println(report);