|
@@ -38,7 +38,7 @@ import static org.apache.hadoop.fs.FileSystemTestHelper.*;
|
|
import org.apache.hadoop.fs.permission.AclEntry;
|
|
import org.apache.hadoop.fs.permission.AclEntry;
|
|
import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555;
|
|
import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555;
|
|
import static org.apache.hadoop.fs.viewfs.Constants.CONFIG_VIEWFS_ENABLE_INNER_CACHE;
|
|
import static org.apache.hadoop.fs.viewfs.Constants.CONFIG_VIEWFS_ENABLE_INNER_CACHE;
|
|
-import static org.apache.hadoop.fs.viewfs.Constants.CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH;
|
|
|
|
|
|
+import static org.apache.hadoop.fs.viewfs.Constants.CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT;
|
|
import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
|
|
import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
|
|
import static org.apache.hadoop.test.GenericTestUtils.*;
|
|
import static org.apache.hadoop.test.GenericTestUtils.*;
|
|
import static org.junit.Assert.*;
|
|
import static org.junit.Assert.*;
|
|
@@ -1022,62 +1022,62 @@ abstract public class ViewFileSystemBaseTest {
|
|
Assert.assertTrue("", fsView.getTrashRoots(true).size() > 0);
|
|
Assert.assertTrue("", fsView.getTrashRoots(true).size() > 0);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Default implementation of getTrashRoot for a fallback FS mounted at root:
|
|
|
|
+ // e.g., fallbackFS.uri.getPath = '/'
|
|
|
|
+ Path getTrashRootInFallBackFS() throws IOException {
|
|
|
|
+ return new Path(fsTarget.getHomeDirectory().toUri().getPath(),
|
|
|
|
+ TRASH_PREFIX);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Test the localized trash root for getTrashRoot.
|
|
|
|
|
|
+ * Test TRASH_FORCE_INSIDE_MOUNT_POINT feature for getTrashRoot.
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
- public void testTrashRootLocalizedTrash() throws IOException {
|
|
|
|
|
|
+ public void testTrashRootForceInsideMountPoint() throws IOException {
|
|
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|
|
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|
|
Configuration conf2 = new Configuration(conf);
|
|
Configuration conf2 = new Configuration(conf);
|
|
- conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, true);
|
|
|
|
|
|
+ conf2.setBoolean(CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT, true);
|
|
|
|
+ ConfigUtil.addLinkFallback(conf2, targetTestRoot.toUri());
|
|
FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
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.
|
|
|
|
|
|
+ // Case 1: path p in the /data mount point.
|
|
|
|
+ // Return a trash root within the /data mount point.
|
|
Path dataTestPath = new Path("/data/dir/file");
|
|
Path dataTestPath = new Path("/data/dir/file");
|
|
- Path dataTrashRoot = new Path(targetTestRoot,
|
|
|
|
- "data/" + TRASH_PREFIX + "/" + ugi.getShortUserName());
|
|
|
|
|
|
+ Path dataTrashRoot = fsView2.makeQualified(
|
|
|
|
+ new Path("/data/" + TRASH_PREFIX + "/" + ugi.getShortUserName()));
|
|
Assert.assertEquals(dataTrashRoot, fsView2.getTrashRoot(dataTestPath));
|
|
Assert.assertEquals(dataTrashRoot, fsView2.getTrashRoot(dataTestPath));
|
|
|
|
|
|
- // Case 2: turn off the CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH flag.
|
|
|
|
- // Return a trash root in user home dir.
|
|
|
|
|
|
+ // Case 2: path p not found in mount table.
|
|
|
|
+ // Return a trash root in fallback FS.
|
|
Path nonExistentPath = new Path("/nonExistentDir/nonExistentFile");
|
|
Path nonExistentPath = new Path("/nonExistentDir/nonExistentFile");
|
|
- Path userTrashRoot = new Path(fsTarget.getHomeDirectory(), TRASH_PREFIX);
|
|
|
|
- conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, false);
|
|
|
|
|
|
+ Path expectedTrash =
|
|
|
|
+ fsView2.makeQualified(getTrashRootInFallBackFS());
|
|
|
|
+ Assert.assertEquals(expectedTrash, fsView2.getTrashRoot(nonExistentPath));
|
|
|
|
+
|
|
|
|
+ // Case 3: turn off the CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT flag.
|
|
|
|
+ // Return a trash root in user home dir.
|
|
|
|
+ conf2.setBoolean(CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT, false);
|
|
fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
- Assert.assertEquals(userTrashRoot, fsView2.getTrashRoot(dataTestPath));
|
|
|
|
|
|
+ Path targetFSUserHomeTrashRoot = fsTarget.makeQualified(
|
|
|
|
+ new Path(fsTarget.getHomeDirectory(), TRASH_PREFIX));
|
|
|
|
+ Assert.assertEquals(targetFSUserHomeTrashRoot,
|
|
|
|
+ fsView2.getTrashRoot(dataTestPath));
|
|
|
|
|
|
- // Case 3: viewFS without fallback. Expect exception for a nonExistent path
|
|
|
|
|
|
+ // Case 4: viewFS without fallback. Expect exception for a nonExistent path
|
|
conf2 = new Configuration(conf);
|
|
conf2 = new Configuration(conf);
|
|
fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
try {
|
|
try {
|
|
fsView2.getTrashRoot(nonExistentPath);
|
|
fsView2.getTrashRoot(nonExistentPath);
|
|
} catch (NotInMountpointException ignored) {
|
|
} catch (NotInMountpointException ignored) {
|
|
}
|
|
}
|
|
-
|
|
|
|
- // Case 4: 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));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* A mocked FileSystem which returns a deep trash dir.
|
|
* A mocked FileSystem which returns a deep trash dir.
|
|
*/
|
|
*/
|
|
- static class MockTrashRootFS extends MockFileSystem {
|
|
|
|
|
|
+ static class DeepTrashRootMockFS extends MockFileSystem {
|
|
public static final Path TRASH =
|
|
public static final Path TRASH =
|
|
- new Path("/mnt/very/deep/deep/trash/dir/.Trash");
|
|
|
|
|
|
+ new Path("/vol/very/deep/deep/trash/dir/.Trash");
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Path getTrashRoot(Path path) {
|
|
public Path getTrashRoot(Path path) {
|
|
@@ -1086,28 +1086,31 @@ abstract public class ViewFileSystemBaseTest {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Test a trash root that is inside a mount point for getTrashRoot.
|
|
|
|
|
|
+ * Test getTrashRoot that is very deep inside a mount point.
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testTrashRootDeepTrashDir() throws IOException {
|
|
public void testTrashRootDeepTrashDir() throws IOException {
|
|
|
|
|
|
Configuration conf2 = ViewFileSystemTestSetup.createConfig();
|
|
Configuration conf2 = ViewFileSystemTestSetup.createConfig();
|
|
- conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, true);
|
|
|
|
- conf2.setClass("fs.mocktrashfs.impl", MockTrashRootFS.class,
|
|
|
|
|
|
+ conf2.setBoolean(CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT, true);
|
|
|
|
+ conf2.setClass("fs.mocktrashfs.impl", DeepTrashRootMockFS.class,
|
|
FileSystem.class);
|
|
FileSystem.class);
|
|
- ConfigUtil.addLink(conf2, "/mnt", URI.create("mocktrashfs://mnt/path"));
|
|
|
|
- Path testPath = new Path(MockTrashRootFS.TRASH, "projs/proj");
|
|
|
|
|
|
+ ConfigUtil.addLink(conf2, "/mnt/datavol1",
|
|
|
|
+ URI.create("mocktrashfs://localhost/vol"));
|
|
|
|
+ Path testPath = new Path("/mnt/datavol1/projs/proj");
|
|
FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
- Assert.assertEquals(MockTrashRootFS.TRASH, fsView2.getTrashRoot(testPath));
|
|
|
|
|
|
+ Path expectedTrash = fsView2.makeQualified(
|
|
|
|
+ new Path("/mnt/datavol1/very/deep/deep/trash/dir/.Trash"));
|
|
|
|
+ Assert.assertEquals(expectedTrash, fsView2.getTrashRoot(testPath));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Test localized trash roots in getTrashRoots() for all users.
|
|
|
|
|
|
+ * Test getTrashRoots() for all users.
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testTrashRootsAllUsers() throws IOException {
|
|
public void testTrashRootsAllUsers() throws IOException {
|
|
Configuration conf2 = new Configuration(conf);
|
|
Configuration conf2 = new Configuration(conf);
|
|
- conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, true);
|
|
|
|
|
|
+ conf2.setBoolean(CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT, true);
|
|
FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
|
|
|
|
// Case 1: verify correct trash roots from fsView and fsView2
|
|
// Case 1: verify correct trash roots from fsView and fsView2
|
|
@@ -1143,17 +1146,27 @@ abstract public class ViewFileSystemBaseTest {
|
|
FileSystem fsView4 = FileSystem.get(FsConstants.VIEWFS_URI, conf4);
|
|
FileSystem fsView4 = FileSystem.get(FsConstants.VIEWFS_URI, conf4);
|
|
int trashRootsNum4 = fsView4.getTrashRoots(true).size();
|
|
int trashRootsNum4 = fsView4.getTrashRoots(true).size();
|
|
Assert.assertEquals(afterTrashRootsNum2 + 2, trashRootsNum4);
|
|
Assert.assertEquals(afterTrashRootsNum2 + 2, trashRootsNum4);
|
|
|
|
+
|
|
|
|
+ // Case 4: test trash roots in fallback FS
|
|
|
|
+ fsTarget.mkdirs(new Path(targetTestRoot, ".Trash/user10"));
|
|
|
|
+ fsTarget.mkdirs(new Path(targetTestRoot, ".Trash/user11"));
|
|
|
|
+ fsTarget.mkdirs(new Path(targetTestRoot, ".Trash/user12"));
|
|
|
|
+ Configuration conf5 = new Configuration(conf2);
|
|
|
|
+ ConfigUtil.addLinkFallback(conf5, targetTestRoot.toUri());
|
|
|
|
+ FileSystem fsView5 = FileSystem.get(FsConstants.VIEWFS_URI, conf5);
|
|
|
|
+ int trashRootsNum5 = fsView5.getTrashRoots(true).size();
|
|
|
|
+ Assert.assertEquals(afterTrashRootsNum2 + 3, trashRootsNum5);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Test localized trash roots in getTrashRoots() for current user.
|
|
|
|
|
|
+ * Test getTrashRoots() for current user.
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testTrashRootsCurrentUser() throws IOException {
|
|
public void testTrashRootsCurrentUser() throws IOException {
|
|
String currentUser =
|
|
String currentUser =
|
|
UserGroupInformation.getCurrentUser().getShortUserName();
|
|
UserGroupInformation.getCurrentUser().getShortUserName();
|
|
Configuration conf2 = new Configuration(conf);
|
|
Configuration conf2 = new Configuration(conf);
|
|
- conf2.setBoolean(CONFIG_VIEWFS_MOUNT_POINT_LOCAL_TRASH, true);
|
|
|
|
|
|
+ conf2.setBoolean(CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT, true);
|
|
FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
FileSystem fsView2 = FileSystem.get(FsConstants.VIEWFS_URI, conf2);
|
|
|
|
|
|
int beforeTrashRootNum = fsView.getTrashRoots(false).size();
|
|
int beforeTrashRootNum = fsView.getTrashRoots(false).size();
|
|
@@ -1169,6 +1182,14 @@ abstract public class ViewFileSystemBaseTest {
|
|
int afterTrashRootsNum2 = fsView2.getTrashRoots(false).size();
|
|
int afterTrashRootsNum2 = fsView2.getTrashRoots(false).size();
|
|
Assert.assertEquals(beforeTrashRootNum, afterTrashRootsNum);
|
|
Assert.assertEquals(beforeTrashRootNum, afterTrashRootsNum);
|
|
Assert.assertEquals(beforeTrashRootNum2 + 2, afterTrashRootsNum2);
|
|
Assert.assertEquals(beforeTrashRootNum2 + 2, afterTrashRootsNum2);
|
|
|
|
+
|
|
|
|
+ // Test trash roots in fallback FS
|
|
|
|
+ Configuration conf3 = new Configuration(conf2);
|
|
|
|
+ fsTarget.mkdirs(new Path(targetTestRoot, TRASH_PREFIX + "/" + currentUser));
|
|
|
|
+ ConfigUtil.addLinkFallback(conf3, targetTestRoot.toUri());
|
|
|
|
+ FileSystem fsView3 = FileSystem.get(FsConstants.VIEWFS_URI, conf3);
|
|
|
|
+ int trashRootsNum3 = fsView3.getTrashRoots(false).size();
|
|
|
|
+ Assert.assertEquals(afterTrashRootsNum2 + 1, trashRootsNum3);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|