From a5ae562d700a668ed5acc2c148f8cca459a9c9f7 Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Fri, 26 Apr 2013 21:30:53 +0000 Subject: [PATCH] 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 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt | 3 +++ .../namenode/snapshot/INodeDirectorySnapshottable.java | 6 +++++- .../hdfs/server/namenode/snapshot/SnapshotManager.java | 4 ---- .../namenode/snapshot/TestSnapshotDiffReport.java | 10 ++++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) 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);