-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HDFS-15483. Ordered snapshot deletion: Disallow rename between two snapshottable directories. #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e9d96a
HDFS-15483. Ordered snapshot deletion: Disallow rename between two sn…
bshashikant 6d5c151
Addressed review comments.
bshashikant 70f6603
Rebased to latest trunk and added snapshotTrashRoot config check.
bshashikant 279e772
Addressed review comments.
bshashikant edee22e
Removede empty line added in SnapshotManager.Java.
bshashikant 8444f5d
Addressed whitespace issues.
bshashikant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...rg/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithOrderedSnapshotDeletion.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hdfs.server.namenode.snapshot; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.hdfs.DistributedFileSystem; | ||
import org.apache.hadoop.hdfs.MiniDFSCluster; | ||
import org.apache.hadoop.hdfs.DFSTestUtil; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
|
||
import java.io.IOException; | ||
|
||
import static org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotManager.DFS_NAMENODE_SNAPSHOT_DELETION_ORDERED; | ||
import static org.apache.hadoop.hdfs.server.namenode.FSNamesystem.DFS_NAMENODE_SNAPSHOT_TRASHROOT_ENABLED; | ||
/** | ||
* Test Rename with ordered snapshot deletion. | ||
*/ | ||
public class TestRenameWithOrderedSnapshotDeletion { | ||
private final Path snapshottableDir | ||
= new Path("/" + getClass().getSimpleName()); | ||
private DistributedFileSystem hdfs; | ||
private MiniDFSCluster cluster; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
final Configuration conf = new Configuration(); | ||
conf.setBoolean(DFS_NAMENODE_SNAPSHOT_DELETION_ORDERED, true); | ||
conf.setBoolean(DFS_NAMENODE_SNAPSHOT_TRASHROOT_ENABLED, true); | ||
|
||
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); | ||
cluster.waitActive(); | ||
hdfs = cluster.getFileSystem(); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
if (cluster != null) { | ||
cluster.shutdown(); | ||
cluster = null; | ||
} | ||
} | ||
|
||
@Test(timeout = 60000) | ||
public void testRename() throws Exception { | ||
final Path dir1 = new Path("/dir1"); | ||
final Path dir2 = new Path("/dir2"); | ||
final Path sub0 = new Path(snapshottableDir, "sub0"); | ||
final Path sub1 = new Path(snapshottableDir, "sub1"); | ||
hdfs.mkdirs(sub0); | ||
hdfs.mkdirs(dir2); | ||
final Path file1 = new Path(dir1, "file1"); | ||
final Path file2 = new Path(sub0, "file2"); | ||
hdfs.mkdirs(snapshottableDir); | ||
hdfs.mkdirs(dir1); | ||
hdfs.mkdirs(dir2); | ||
hdfs.mkdirs(sub0); | ||
DFSTestUtil.createFile(hdfs, file1, 0, (short) 1, 0); | ||
DFSTestUtil.createFile(hdfs, file2, 0, (short) 1, 0); | ||
hdfs.allowSnapshot(snapshottableDir); | ||
// rename from non snapshottable dir to snapshottable dir should fail | ||
validateRename(file1, sub0); | ||
hdfs.createSnapshot(snapshottableDir, "s0"); | ||
validateRename(file1, sub0); | ||
// rename across non snapshottable dirs should work | ||
hdfs.rename(file1, dir2); | ||
// rename beyond snapshottable root should fail | ||
validateRename(file2, dir1); | ||
// rename within snapshottable root should work | ||
hdfs.rename(file2, snapshottableDir); | ||
|
||
// rename dirs outside snapshottable root should work | ||
hdfs.rename(dir2, dir1); | ||
// rename dir into snapshottable root should fail | ||
validateRename(dir1, snapshottableDir); | ||
// rename dir outside snapshottable root should fail | ||
validateRename(sub0, dir2); | ||
// rename dir within snapshottable root should work | ||
hdfs.rename(sub0, sub1); | ||
} | ||
|
||
private void validateRename(Path src, Path dest) { | ||
try { | ||
hdfs.rename(src, dest); | ||
Assert.fail("Expected exception not thrown."); | ||
} catch (IOException ioe) { | ||
Assert.assertTrue(ioe.getMessage().contains("are not under the" + | ||
" same snapshot root.")); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.