HDFS-12981. renameSnapshot a Non-Existent snapshot to itself should throw error. Contributed by Kitti Nanasi.
This commit is contained in:
parent
3a43ac2851
commit
696a4be0da
|
@ -119,14 +119,14 @@ public class DirectorySnapshottableFeature extends DirectoryWithSnapshotFeature
|
||||||
*/
|
*/
|
||||||
public void renameSnapshot(String path, String oldName, String newName)
|
public void renameSnapshot(String path, String oldName, String newName)
|
||||||
throws SnapshotException {
|
throws SnapshotException {
|
||||||
if (newName.equals(oldName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int indexOfOld = searchSnapshot(DFSUtil.string2Bytes(oldName));
|
final int indexOfOld = searchSnapshot(DFSUtil.string2Bytes(oldName));
|
||||||
if (indexOfOld < 0) {
|
if (indexOfOld < 0) {
|
||||||
throw new SnapshotException("The snapshot " + oldName
|
throw new SnapshotException("The snapshot " + oldName
|
||||||
+ " does not exist for directory " + path);
|
+ " does not exist for directory " + path);
|
||||||
} else {
|
} else {
|
||||||
|
if (newName.equals(oldName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final byte[] newNameBytes = DFSUtil.string2Bytes(newName);
|
final byte[] newNameBytes = DFSUtil.string2Bytes(newName);
|
||||||
int indexOfNew = searchSnapshot(newNameBytes);
|
int indexOfNew = searchSnapshot(newNameBytes);
|
||||||
if (indexOfNew >= 0) {
|
if (indexOfNew >= 0) {
|
||||||
|
|
|
@ -155,6 +155,11 @@ public class TestSnapshotCommands {
|
||||||
DFSTestUtil.FsShellRun("-renameSnapshot /sub1 sn.nonexist sn.rename", 1,
|
DFSTestUtil.FsShellRun("-renameSnapshot /sub1 sn.nonexist sn.rename", 1,
|
||||||
"renameSnapshot: The snapshot sn.nonexist does not exist for directory /sub1", conf);
|
"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
|
//try renaming to existing snapshots
|
||||||
DFSTestUtil.FsShellRun("-createSnapshot /sub1 sn.new", conf);
|
DFSTestUtil.FsShellRun("-createSnapshot /sub1 sn.new", conf);
|
||||||
DFSTestUtil.FsShellRun("-renameSnapshot /sub1 sn.new sn.rename", 1,
|
DFSTestUtil.FsShellRun("-renameSnapshot /sub1 sn.new sn.rename", 1,
|
||||||
|
|
|
@ -183,6 +183,22 @@ public class TestSnapshotRename {
|
||||||
exception.expectMessage(error);
|
exception.expectMessage(error);
|
||||||
hdfs.renameSnapshot(sub1, "wrongName", "s2");
|
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
|
* Test rename a snapshot to another existing snapshot
|
||||||
|
|
Loading…
Reference in New Issue