|
@@ -17,6 +17,7 @@
|
|
*/
|
|
*/
|
|
package org.apache.hadoop.fs.viewfs;
|
|
package org.apache.hadoop.fs.viewfs;
|
|
|
|
|
|
|
|
+import static org.apache.hadoop.fs.CreateFlag.CREATE;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.assertTrue;
|
|
@@ -24,12 +25,15 @@ import static org.junit.Assert.assertTrue;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URISyntaxException;
|
|
|
|
+import java.util.EnumSet;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.AbstractFileSystem;
|
|
import org.apache.hadoop.fs.AbstractFileSystem;
|
|
|
|
+import org.apache.hadoop.fs.FileAlreadyExistsException;
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FsConstants;
|
|
import org.apache.hadoop.fs.FsConstants;
|
|
|
|
+import org.apache.hadoop.fs.Options;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
@@ -294,4 +298,154 @@ public class TestViewFsLinkFallback {
|
|
assertTrue(fsTarget.exists(test));
|
|
assertTrue(fsTarget.exists(test));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Tests that the create file should be successful when the parent directory
|
|
|
|
+ * is same as the existent fallback directory. The new file should be created
|
|
|
|
+ * in fallback.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testCreateFileOnInternalMountDirWithSameDirTreeExistInFallback()
|
|
|
|
+ throws Exception {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ ConfigUtil.addLink(conf, "/user1/hive/warehouse/partition-0",
|
|
|
|
+ new Path(targetTestRoot.toString()).toUri());
|
|
|
|
+ Path fallbackTarget = new Path(targetTestRoot, "fallbackDir");
|
|
|
|
+ Path dir1 = new Path(fallbackTarget, "user1/hive/warehouse/partition-0");
|
|
|
|
+ fsTarget.mkdirs(dir1);
|
|
|
|
+ ConfigUtil.addLinkFallback(conf, fallbackTarget.toUri());
|
|
|
|
+
|
|
|
|
+ AbstractFileSystem vfs =
|
|
|
|
+ AbstractFileSystem.get(viewFsDefaultClusterUri, conf);
|
|
|
|
+ Path vfsTestFile = new Path("/user1/hive/warehouse/test.file");
|
|
|
|
+ Path testFileInFallback = Path.mergePaths(fallbackTarget, vfsTestFile);
|
|
|
|
+ assertFalse(fsTarget.exists(testFileInFallback));
|
|
|
|
+ assertTrue(fsTarget.exists(testFileInFallback.getParent()));
|
|
|
|
+ vfs.create(vfsTestFile, EnumSet.of(CREATE),
|
|
|
|
+ Options.CreateOpts.perms(FsPermission.getDefault())).close();
|
|
|
|
+ assertTrue(fsTarget.exists(testFileInFallback));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Tests the making of a new directory which is not matching to any of
|
|
|
|
+ * internal directory.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testCreateNewFileWithOutMatchingToMountDirOrFallbackDirPath()
|
|
|
|
+ throws Exception {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ ConfigUtil.addLink(conf, "/user1/hive/warehouse/partition-0",
|
|
|
|
+ new Path(targetTestRoot.toString()).toUri());
|
|
|
|
+ Path fallbackTarget = new Path(targetTestRoot, "fallbackDir");
|
|
|
|
+ fsTarget.mkdirs(fallbackTarget);
|
|
|
|
+ ConfigUtil.addLinkFallback(conf, fallbackTarget.toUri());
|
|
|
|
+ AbstractFileSystem vfs =
|
|
|
|
+ AbstractFileSystem.get(viewFsDefaultClusterUri, conf);
|
|
|
|
+ Path vfsTestFile = new Path("/user2/test.file");
|
|
|
|
+ Path testFileInFallback = Path.mergePaths(fallbackTarget, vfsTestFile);
|
|
|
|
+ assertFalse(fsTarget.exists(testFileInFallback));
|
|
|
|
+ // user2 does not exist in fallback
|
|
|
|
+ assertFalse(fsTarget.exists(testFileInFallback.getParent()));
|
|
|
|
+ vfs.create(vfsTestFile, EnumSet.of(CREATE),
|
|
|
|
+ Options.CreateOpts.perms(FsPermission.getDefault()),
|
|
|
|
+ Options.CreateOpts.createParent()).close();
|
|
|
|
+ // /user2/test.file should be created in fallback
|
|
|
|
+ assertTrue(fsTarget.exists(testFileInFallback));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Tests the making of a new file on root which is not matching to any of
|
|
|
|
+ * fallback files on root.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testCreateFileOnRootWithFallbackEnabled()
|
|
|
|
+ throws Exception {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ Path fallbackTarget = new Path(targetTestRoot, "fallbackDir");
|
|
|
|
+ fsTarget.mkdirs(fallbackTarget);
|
|
|
|
+
|
|
|
|
+ ConfigUtil.addLink(conf, "/user1/hive/",
|
|
|
|
+ new Path(targetTestRoot.toString()).toUri());
|
|
|
|
+ ConfigUtil.addLinkFallback(conf, fallbackTarget.toUri());
|
|
|
|
+
|
|
|
|
+ AbstractFileSystem vfs =
|
|
|
|
+ AbstractFileSystem.get(viewFsDefaultClusterUri, conf);
|
|
|
|
+ Path vfsTestFile = new Path("/test.file");
|
|
|
|
+ Path testFileInFallback = Path.mergePaths(fallbackTarget, vfsTestFile);
|
|
|
|
+ assertFalse(fsTarget.exists(testFileInFallback));
|
|
|
|
+ vfs.create(vfsTestFile, EnumSet.of(CREATE),
|
|
|
|
+ Options.CreateOpts.perms(FsPermission.getDefault())).close();
|
|
|
|
+ // /test.file should be created in fallback
|
|
|
|
+ assertTrue(fsTarget.exists(testFileInFallback));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Tests the create of a file on root where the path is matching to an
|
|
|
|
+ * existing file on fallback's file on root.
|
|
|
|
+ */
|
|
|
|
+ @Test (expected = FileAlreadyExistsException.class)
|
|
|
|
+ public void testCreateFileOnRootWithFallbackWithFileAlreadyExist()
|
|
|
|
+ throws Exception {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ Path fallbackTarget = new Path(targetTestRoot, "fallbackDir");
|
|
|
|
+ Path testFile = new Path(fallbackTarget, "test.file");
|
|
|
|
+ // pre-creating test file in fallback.
|
|
|
|
+ fsTarget.create(testFile).close();
|
|
|
|
+
|
|
|
|
+ ConfigUtil.addLink(conf, "/user1/hive/",
|
|
|
|
+ new Path(targetTestRoot.toString()).toUri());
|
|
|
|
+ ConfigUtil.addLinkFallback(conf, fallbackTarget.toUri());
|
|
|
|
+
|
|
|
|
+ AbstractFileSystem vfs =
|
|
|
|
+ AbstractFileSystem.get(viewFsDefaultClusterUri, conf);
|
|
|
|
+ Path vfsTestFile = new Path("/test.file");
|
|
|
|
+ assertTrue(fsTarget.exists(testFile));
|
|
|
|
+ vfs.create(vfsTestFile, EnumSet.of(CREATE),
|
|
|
|
+ Options.CreateOpts.perms(FsPermission.getDefault())).close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Tests the creating of a file where the path is same as mount link path.
|
|
|
|
+ */
|
|
|
|
+ @Test(expected= FileAlreadyExistsException.class)
|
|
|
|
+ public void testCreateFileWhereThePathIsSameAsItsMountLinkPath()
|
|
|
|
+ throws Exception {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ Path fallbackTarget = new Path(targetTestRoot, "fallbackDir");
|
|
|
|
+ fsTarget.mkdirs(fallbackTarget);
|
|
|
|
+
|
|
|
|
+ ConfigUtil.addLink(conf, "/user1/hive/",
|
|
|
|
+ new Path(targetTestRoot.toString()).toUri());
|
|
|
|
+ ConfigUtil.addLinkFallback(conf, fallbackTarget.toUri());
|
|
|
|
+
|
|
|
|
+ AbstractFileSystem vfs =
|
|
|
|
+ AbstractFileSystem.get(viewFsDefaultClusterUri, conf);
|
|
|
|
+ Path vfsTestDir = new Path("/user1/hive");
|
|
|
|
+ assertFalse(fsTarget.exists(Path.mergePaths(fallbackTarget, vfsTestDir)));
|
|
|
|
+ vfs.create(vfsTestDir, EnumSet.of(CREATE),
|
|
|
|
+ Options.CreateOpts.perms(FsPermission.getDefault())).close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Tests the create of a file where the path is same as one of of the internal
|
|
|
|
+ * dir path should fail.
|
|
|
|
+ */
|
|
|
|
+ @Test(expected = FileAlreadyExistsException.class)
|
|
|
|
+ public void testCreateFileSameAsInternalDirPath()
|
|
|
|
+ throws Exception {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ Path fallbackTarget = new Path(targetTestRoot, "fallbackDir");
|
|
|
|
+ fsTarget.mkdirs(fallbackTarget);
|
|
|
|
+ ConfigUtil.addLink(conf, "/user1/hive/",
|
|
|
|
+ new Path(targetTestRoot.toString()).toUri());
|
|
|
|
+ ConfigUtil.addLinkFallback(conf, fallbackTarget.toUri());
|
|
|
|
+
|
|
|
|
+ AbstractFileSystem vfs =
|
|
|
|
+ AbstractFileSystem.get(viewFsDefaultClusterUri, conf);
|
|
|
|
+ Path vfsTestDir = new Path("/user1");
|
|
|
|
+ assertFalse(fsTarget.exists(Path.mergePaths(fallbackTarget, vfsTestDir)));
|
|
|
|
+ vfs.create(vfsTestDir, EnumSet.of(CREATE),
|
|
|
|
+ Options.CreateOpts.perms(FsPermission.getDefault())).close();
|
|
|
|
+ }
|
|
}
|
|
}
|