hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x...@apache.org
Subject hadoop git commit: HDFS-12981. renameSnapshot a Non-Existent snapshot to itself should throw error. Contributed by Kitti Nanasi.
Date Mon, 07 May 2018 22:39:27 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-3.1 752092a86 -> 6f3bbf364


HDFS-12981. renameSnapshot a Non-Existent snapshot to itself should throw error. Contributed
by Kitti Nanasi.

(cherry picked from commit 696a4be0daac00dd3bb64801d9fbe659aef9e089)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6f3bbf36
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6f3bbf36
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6f3bbf36

Branch: refs/heads/branch-3.1
Commit: 6f3bbf364c42e046e02d545515e45cdb64df6b4a
Parents: 752092a
Author: Xiao Chen <xiao@apache.org>
Authored: Mon May 7 15:34:22 2018 -0700
Committer: Xiao Chen <xiao@apache.org>
Committed: Mon May 7 15:39:24 2018 -0700

----------------------------------------------------------------------
 .../snapshot/DirectorySnapshottableFeature.java     |  6 +++---
 .../apache/hadoop/hdfs/TestSnapshotCommands.java    |  5 +++++
 .../namenode/snapshot/TestSnapshotRename.java       | 16 ++++++++++++++++
 3 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/6f3bbf36/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java
index 6adb770..d3083cf 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java
@@ -119,14 +119,14 @@ public class DirectorySnapshottableFeature extends DirectoryWithSnapshotFeature
    */
   public void renameSnapshot(String path, String oldName, String newName)
       throws SnapshotException {
-    if (newName.equals(oldName)) {
-      return;
-    }
     final int indexOfOld = searchSnapshot(DFSUtil.string2Bytes(oldName));
     if (indexOfOld < 0) {
       throw new SnapshotException("The snapshot " + oldName
           + " does not exist for directory " + path);
     } else {
+      if (newName.equals(oldName)) {
+        return;
+      }
       final byte[] newNameBytes = DFSUtil.string2Bytes(newName);
       int indexOfNew = searchSnapshot(newNameBytes);
       if (indexOfNew >= 0) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/6f3bbf36/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSnapshotCommands.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSnapshotCommands.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSnapshotCommands.java
index 0b2b23c..2b5a69d 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSnapshotCommands.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSnapshotCommands.java
@@ -155,6 +155,11 @@ public class TestSnapshotCommands {
     DFSTestUtil.FsShellRun("-renameSnapshot /sub1 sn.nonexist sn.rename", 1,
         "renameSnapshot: The snapshot sn.nonexist does not exist for directory /sub1", conf);
 
+    //try renaming a non-existing snapshot to itself
+    DFSTestUtil.FsShellRun("-renameSnapshot /sub1 sn.nonexist sn.nonexist", 1,
+        "renameSnapshot: The snapshot sn.nonexist " +
+            "does not exist for directory /sub1", conf);
+
     //try renaming to existing snapshots
     DFSTestUtil.FsShellRun("-createSnapshot /sub1 sn.new", conf);
     DFSTestUtil.FsShellRun("-renameSnapshot /sub1 sn.new sn.rename", 1,

http://git-wip-us.apache.org/repos/asf/hadoop/blob/6f3bbf36/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
index 01157e8..1d46e4e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
@@ -183,6 +183,22 @@ public class TestSnapshotRename {
     exception.expectMessage(error);
     hdfs.renameSnapshot(sub1, "wrongName", "s2");
   }
+
+  /**
+   * Test rename a non-existing snapshot to itself.
+   */
+  @Test (timeout=60000)
+  public void testRenameNonExistingSnapshotToItself() throws Exception {
+    DFSTestUtil.createFile(hdfs, file1, BLOCKSIZE, REPLICATION, seed);
+    // Create snapshot for sub1
+    SnapshotTestHelper.createSnapshot(hdfs, sub1, "s1");
+
+    exception.expect(SnapshotException.class);
+    String error = "The snapshot wrongName does not exist for directory "
+        + sub1.toString();
+    exception.expectMessage(error);
+    hdfs.renameSnapshot(sub1, "wrongName", "wrongName");
+  }
   
   /**
    * Test rename a snapshot to another existing snapshot 


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message