ayushtkn commented on a change in pull request #2107:
URL: https://github.com/apache/hadoop/pull/2107#discussion_r449744920
##########
File path:
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java
##########
@@ -765,4 +766,151 @@ public void
testMkdirsShouldReturnFalseWhenFallbackFSNotAvailable()
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());
+
+ try (FileSystem vfs = FileSystem.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).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());
+ try (FileSystem vfs = FileSystem.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).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());
+
+ try (FileSystem vfs = FileSystem.get(viewFsDefaultClusterUri, conf)) {
+ Path vfsTestFile = new Path("/test.file");
+ Path testFileInFallback = Path.mergePaths(fallbackTarget, vfsTestFile);
+ assertFalse(fsTarget.exists(testFileInFallback));
+ vfs.create(vfsTestFile).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());
+
+ try (FileSystem vfs = FileSystem.get(viewFsDefaultClusterUri, conf)) {
+ Path vfsTestFile = new Path("/test.file");
+ assertTrue(fsTarget.exists(testFile));
+ vfs.create(vfsTestFile, false).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());
+
+ try (FileSystem vfs = FileSystem.get(viewFsDefaultClusterUri, conf)) {
+ Path vfsTestDir = new Path("/user1/hive");
+ assertFalse(fsTarget.exists(Path.mergePaths(fallbackTarget,
vfsTestDir)));
+ vfs.create(vfsTestDir).close();
+ }
+ }
+
+ /**
+ * Tests the create of a file where the path is same as one of of the
internal
+ * dir path should fail.
+ */
+ @Test
+ 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());
+
+ try (FileSystem vfs = FileSystem.get(viewFsDefaultClusterUri, conf)) {
+ Path vfsTestDir = new Path("/user1");
+ assertFalse(fsTarget.exists(Path.mergePaths(fallbackTarget,
vfsTestDir)));
+ try {
+ vfs.create(vfsTestDir);
+ Assert.fail("Should fail to create file as this is an internal dir.");
+ } catch (NotInMountpointException e){
+ // This tree is part of internal tree. The above expetion will be
thrown
Review comment:
typo "expetion"
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java
##########
@@ -919,6 +921,42 @@ public FSDataOutputStream createInternal(final Path f,
FileAlreadyExistsException, FileNotFoundException,
ParentNotDirectoryException, UnsupportedFileSystemException,
UnresolvedLinkException, IOException {
+ Preconditions.checkNotNull(f, "File cannot be null.");
+ // Just a sanity check. This should not happen.
Review comment:
What do you mean by : This should not happen. Ideally client call
shouldn't land here or This If check will never get hit(It does get hit, I
verified),
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]