abhishekdas99 commented on a change in pull request #2010:
URL: https://github.com/apache/hadoop/pull/2010#discussion_r424753014
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java
##########
@@ -1226,7 +1229,38 @@ public FileStatus getFileStatus(Path f) throws
IOException {
myUri, null));
}
}
- return result;
+ if (fallbackStatuses.length > 0) {
+ return consolidateFileStatuses(fallbackStatuses, result);
+ } else {
+ return result;
+ }
+ }
+
+ private FileStatus[] consolidateFileStatuses(FileStatus[] fallbackStatuses,
+ FileStatus[] mountPointStatuses) {
+ ArrayList<FileStatus> result = new ArrayList<>();
+ Set<String> pathSet = new HashSet<>();
+ int i = 0;
+ for (FileStatus status : mountPointStatuses) {
+ result.add(status);
+ pathSet.add(status.getPath().getName());
+ }
+ for (FileStatus status : fallbackStatuses) {
+ if (!pathSet.contains(status.getPath().getName())) {
+ result.add(status);
+ }
+ }
+ return result.toArray(new FileStatus[0]);
+ }
+
+ private FileStatus[] listStatusForFallbackLink() throws IOException {
+ if (theInternalDir.isRoot() && theInternalDir.getFallbackLink() != null)
{
+ URI fallBackUri =
theInternalDir.getFallbackLink().targetDirLinkList[0];
Review comment:
`theInternalDir.getFallbackLink().targetFileSystem` is going to return
`ChRootedFileSystem` which will wrap the path with `fullPath(Path p)` method.
That was causing error. I have used the underlying filesystem object of the
`ChRootedFileSystem`
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/InodeTree.java
##########
@@ -149,6 +150,17 @@ boolean isRoot() {
return isRoot;
}
+ INodeLink<T> getFallbackLink() {
+ return fallbackLink;
+ }
+
Review comment:
Done.
##########
File path:
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java
##########
@@ -261,4 +261,53 @@ public void testConfLinkFallbackWithMountPoint() throws
Exception {
e.getMessage().contains(expectedErrorMsg));
}
}
+
Review comment:
Done
##########
File path:
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java
##########
@@ -261,4 +261,53 @@ public void testConfLinkFallbackWithMountPoint() throws
Exception {
e.getMessage().contains(expectedErrorMsg));
}
}
+
+ @Test
+ public void testListingWithFallbackLink() throws Exception {
+ fsTarget.mkdirs(new Path(targetTestRoot, "fallbackDir/dir1"));
+ fsTarget.mkdirs(new Path(targetTestRoot, "fallbackDir/dir2"));
+ String clusterName = Constants.CONFIG_VIEWFS_DEFAULT_MOUNT_TABLE;
+ URI viewFsUri = new URI(FsConstants.VIEWFS_SCHEME, clusterName,
+ "/", null, null);
+
+ int itemCount = 0;
+ try(FileSystem vfs = FileSystem.get(viewFsUri, conf)) {
+ itemCount = vfs.listStatus(new Path(viewFsUri.toString())).length;
+ }
+
+ ConfigUtil.addLinkFallback(conf, clusterName,
+ new Path(targetTestRoot, "fallbackDir").toUri());
+
+ try (FileSystem vfs = FileSystem.get(viewFsUri, conf)) {
+ FileStatus[] statuses = vfs.listStatus(new Path(viewFsUri.toString()));
+ assertTrue("Listing didn't include fallback link",
Review comment:
Added the assert for paths
##########
File path:
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java
##########
@@ -261,4 +261,53 @@ public void testConfLinkFallbackWithMountPoint() throws
Exception {
e.getMessage().contains(expectedErrorMsg));
}
}
+
+ @Test
+ public void testListingWithFallbackLink() throws Exception {
+ fsTarget.mkdirs(new Path(targetTestRoot, "fallbackDir/dir1"));
+ fsTarget.mkdirs(new Path(targetTestRoot, "fallbackDir/dir2"));
+ String clusterName = Constants.CONFIG_VIEWFS_DEFAULT_MOUNT_TABLE;
+ URI viewFsUri = new URI(FsConstants.VIEWFS_SCHEME, clusterName,
+ "/", null, null);
+
+ int itemCount = 0;
+ try(FileSystem vfs = FileSystem.get(viewFsUri, conf)) {
+ itemCount = vfs.listStatus(new Path(viewFsUri.toString())).length;
+ }
+
+ ConfigUtil.addLinkFallback(conf, clusterName,
+ new Path(targetTestRoot, "fallbackDir").toUri());
+
+ try (FileSystem vfs = FileSystem.get(viewFsUri, conf)) {
+ FileStatus[] statuses = vfs.listStatus(new Path(viewFsUri.toString()));
+ assertTrue("Listing didn't include fallback link",
+ statuses.length == itemCount + 2);
+ }
+ }
+
+ @Test
+ public void testListingWithFallbackLinkWithSameMountDirectories()
+ throws Exception {
+ // Creating two directories under the fallback dircetory.
+ // user directory already exists as configured mount point.
+ fsTarget.mkdirs(new Path(targetTestRoot, "fallbackDir/user"));
+ fsTarget.mkdirs(new Path(targetTestRoot, "fallbackDir/user1"));
+ String clusterName = Constants.CONFIG_VIEWFS_DEFAULT_MOUNT_TABLE;
+ URI viewFsUri = new URI(FsConstants.VIEWFS_SCHEME, clusterName,
+ "/", null, null);
+
+ int itemCount = 0;
+ try(FileSystem vfs = FileSystem.get(viewFsUri, conf)) {
+ itemCount = vfs.listStatus(new Path(viewFsUri.toString())).length;
+ }
+
+ ConfigUtil.addLinkFallback(conf, clusterName,
+ new Path(targetTestRoot, "fallbackDir").toUri());
+
+ try (FileSystem vfs = FileSystem.get(viewFsUri, conf)) {
+ FileStatus[] statuses = vfs.listStatus(new Path(viewFsUri.toString()));
+ assertTrue("The same directory name in fallback link should be shaded",
Review comment:
Added a check to make sure the fallback path is not the one which has
the same as the mount path.
----------------------------------------------------------------
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]