-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-18110. ViewFileSystem: Add Support for Localized Trash Root #3956
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
Changes from 8 commits
a349813
cfc6915
5afd598
8d771ef
5b6f293
6a5c4bd
c3745aa
bc23271
250b6c8
44da786
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,8 @@ | |
| import static org.apache.hadoop.fs.FileSystemTestHelper.*; | ||
| import static org.apache.hadoop.fs.viewfs.Constants.CONFIG_VIEWFS_ENABLE_INNER_CACHE; | ||
| import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555; | ||
| import static org.apache.hadoop.fs.viewfs.Constants.CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH; | ||
| import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Assert; | ||
|
|
@@ -1102,6 +1104,131 @@ public void testTrashRoot() throws IOException { | |
| Assert.assertTrue("", fsView.getTrashRoots(true).size() > 0); | ||
| } | ||
|
|
||
| /** | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test where the child file system returns a root inside of the mount point, such as what will happen when there is an encryption zone root. To do so, you'll need to define a mock/stub fs.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @omalley, I believe Case 5 is what you are looking for. 😃
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it isn't. I was more concerned with what would happen with an encryption zone or snapshot root. You'd need to make a mock child file system that implements a custom getTrashRoot(path). |
||
| * Test the localized trash root for getTrashRoot. | ||
| */ | ||
| @Test | ||
| public void testTrashRootLocalizedTrash() throws IOException { | ||
| UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); | ||
| Configuration conf2 = new Configuration(conf); | ||
| conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, true); | ||
| ConfigUtil.addLinkFallback(conf2, targetTestRoot.toUri()); | ||
| FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2); | ||
|
|
||
| // Case 1: path p not in the default FS. | ||
| // Return a trash root within the mount point. | ||
| Path dataTestPath = new Path("/data/dir/file"); | ||
| Path dataTrashRoot = new Path(targetTestRoot, | ||
| "data/" + TRASH_PREFIX + "/" + ugi.getShortUserName()); | ||
| Assert.assertEquals(dataTrashRoot, fsView2.getTrashRoot(dataTestPath)); | ||
|
|
||
| // Case 2: path p not found in mount table, fall back to the default FS | ||
| // Return a trash root in user home dir | ||
| Path nonExistentPath = new Path("/nonExistentDir/nonExistentFile"); | ||
| Path userTrashRoot = new Path(fsTarget.getHomeDirectory(), TRASH_PREFIX); | ||
| Assert.assertEquals(userTrashRoot, fsView2.getTrashRoot(nonExistentPath)); | ||
|
|
||
| // Case 3: turn off the CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH flag. | ||
| // Return a trash root in user home dir. | ||
| conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, false); | ||
| fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2); | ||
| Assert.assertEquals(userTrashRoot, fsView2.getTrashRoot(dataTestPath)); | ||
|
|
||
| // Case 4: viewFS without fallback. Expect exception for a nonExistent path | ||
| conf2 = new Configuration(conf); | ||
| fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2); | ||
| try { | ||
| fsView2.getTrashRoot(nonExistentPath); | ||
| } catch (NotInMountpointException ignored) { | ||
| } | ||
|
|
||
| // Case 5: path p is in the same mount point as targetFS.getTrashRoot(). | ||
| // Return targetFS.getTrashRoot() | ||
| // Use a new Configuration object, so that we can start with an empty | ||
| // mount table. This would avoid a conflict between the /user link in | ||
| // setupMountPoints() and homeDir we will need to setup for this test. | ||
| // default homeDir for hdfs is /user/. | ||
| Configuration conf3 = ViewFileSystemTestSetup.createConfig(); | ||
| Path homeDir = fsTarget.getHomeDirectory(); | ||
| String homeParentDir = homeDir.getParent().toUri().getPath(); | ||
| conf3.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, true); | ||
| ConfigUtil.addLink(conf3, homeParentDir, | ||
| new Path(targetTestRoot, homeParentDir).toUri()); | ||
| Path homeTestPath = new Path(homeDir.toUri().getPath(), "testuser/file"); | ||
| FileSystem fsView3 = FileSystem.get(FsConstants.VIEWFS_URI, conf3); | ||
| Assert.assertEquals(userTrashRoot, fsView3.getTrashRoot(homeTestPath)); | ||
| } | ||
|
|
||
| /** | ||
| * Test localized trash roots in getTrashRoots() for all users. | ||
| */ | ||
| @Test | ||
| public void testTrashRootsAllUsers() throws IOException { | ||
| Configuration conf2 = new Configuration(conf); | ||
| conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, true); | ||
| FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2); | ||
|
|
||
| // Case 1: verify correct trash roots from fsView and fsView2 | ||
| int beforeTrashRootNum = fsView.getTrashRoots(true).size(); | ||
| int beforeTrashRootNum2 = fsView2.getTrashRoots(true).size(); | ||
| Assert.assertEquals(beforeTrashRootNum, beforeTrashRootNum2); | ||
|
|
||
| fsView.mkdirs(new Path("/data/" + TRASH_PREFIX + "/user1")); | ||
| fsView.mkdirs(new Path("/data/" + TRASH_PREFIX + "/user2")); | ||
| fsView.mkdirs(new Path("/user/" + TRASH_PREFIX + "/user3")); | ||
| fsView.mkdirs(new Path("/user/" + TRASH_PREFIX + "/user4")); | ||
| fsView.mkdirs(new Path("/user2/" + TRASH_PREFIX + "/user5")); | ||
| int afterTrashRootsNum = fsView.getTrashRoots(true).size(); | ||
| int afterTrashRootsNum2 = fsView2.getTrashRoots(true).size(); | ||
| Assert.assertEquals(beforeTrashRootNum, afterTrashRootsNum); | ||
| Assert.assertEquals(beforeTrashRootNum2 + 5, afterTrashRootsNum2); | ||
|
|
||
| // Case 2: per-user mount point | ||
| fsTarget.mkdirs(new Path(targetTestRoot, "Users/userA/.Trash/userA")); | ||
| Configuration conf3 = new Configuration(conf2); | ||
| ConfigUtil.addLink(conf3, "/Users/userA", | ||
| new Path(targetTestRoot, "Users/userA").toUri()); | ||
| FileSystem fsView3 = FileSystem.get(FsConstants.VIEWFS_URI, conf3); | ||
| int trashRootsNum3 = fsView3.getTrashRoots(true).size(); | ||
| Assert.assertEquals(afterTrashRootsNum2 + 1, trashRootsNum3); | ||
|
|
||
| // Case 3: single /Users mount point for all users | ||
| fsTarget.mkdirs(new Path(targetTestRoot, "Users/.Trash/user1")); | ||
| fsTarget.mkdirs(new Path(targetTestRoot, "Users/.Trash/user2")); | ||
| Configuration conf4 = new Configuration(conf2); | ||
| ConfigUtil.addLink(conf4, "/Users", | ||
| new Path(targetTestRoot, "Users").toUri()); | ||
| FileSystem fsView4 = FileSystem.get(FsConstants.VIEWFS_URI, conf4); | ||
| int trashRootsNum4 = fsView4.getTrashRoots(true).size(); | ||
| Assert.assertEquals(afterTrashRootsNum2 + 2, trashRootsNum4); | ||
| } | ||
|
|
||
| /** | ||
| * Test localized trash roots in getTrashRoots() for current user. | ||
| */ | ||
| @Test | ||
| public void testTrashRootsCurrentUser() throws IOException { | ||
| String currentUser = | ||
| UserGroupInformation.getCurrentUser().getShortUserName(); | ||
| Configuration conf2 = new Configuration(conf); | ||
| conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, true); | ||
| FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2); | ||
|
|
||
| int beforeTrashRootNum = fsView.getTrashRoots(false).size(); | ||
| int beforeTrashRootNum2 = fsView2.getTrashRoots(false).size(); | ||
| Assert.assertEquals(beforeTrashRootNum, beforeTrashRootNum2); | ||
|
|
||
| fsView.mkdirs(new Path("/data/" + TRASH_PREFIX + "/" + currentUser)); | ||
| fsView.mkdirs(new Path("/data/" + TRASH_PREFIX + "/user2")); | ||
| fsView.mkdirs(new Path("/user/" + TRASH_PREFIX + "/" + currentUser)); | ||
| fsView.mkdirs(new Path("/user/" + TRASH_PREFIX + "/user4")); | ||
| fsView.mkdirs(new Path("/user2/" + TRASH_PREFIX + "/user5")); | ||
| int afterTrashRootsNum = fsView.getTrashRoots(false).size(); | ||
| int afterTrashRootsNum2 = fsView2.getTrashRoots(false).size(); | ||
| Assert.assertEquals(beforeTrashRootNum, afterTrashRootsNum); | ||
| Assert.assertEquals(beforeTrashRootNum2 + 2, afterTrashRootsNum2); | ||
| } | ||
|
|
||
| @Test(expected = NotInMountpointException.class) | ||
| public void testViewFileSystemUtil() throws Exception { | ||
| Configuration newConf = new Configuration(conf); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.