Skip to content

Commit ac9a07b

Browse files
HDFS-15478: When Empty mount points, we are assigning fallback link to self. But it should not use full URI for target fs. (#2160). Contributed by Uma Maheswara Rao G.
1 parent 1b29c9b commit ac9a07b

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public void initialize(final URI theUri, final Configuration conf)
294294
myUri = new URI(getScheme(), authority, "/", null, null);
295295
boolean initingUriAsFallbackOnNoMounts =
296296
!FsConstants.VIEWFS_TYPE.equals(getType());
297-
fsState = new InodeTree<FileSystem>(conf, tableName, theUri,
297+
fsState = new InodeTree<FileSystem>(conf, tableName, myUri,
298298
initingUriAsFallbackOnNoMounts) {
299299
@Override
300300
protected FileSystem getTargetFileSystem(final URI uri)

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsOverloadSchemeListStatus.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,30 @@ public void testListStatusACL() throws IOException, URISyntaxException {
127127

128128
/**
129129
* Tests that ViewFSOverloadScheme should consider initialized fs as fallback
130-
* if there are no mount links configured.
130+
* if there are no mount links configured. It should add fallback with the
131+
* chrootedFS at it's uri's root.
131132
*/
132133
@Test(timeout = 30000)
133134
public void testViewFSOverloadSchemeWithoutAnyMountLinks() throws Exception {
134-
try (FileSystem fs = FileSystem.get(TEST_DIR.toPath().toUri(), conf)) {
135+
Path initUri = new Path(TEST_DIR.toURI().toString(), "init");
136+
try (FileSystem fs = FileSystem.get(initUri.toUri(), conf)) {
135137
ViewFileSystemOverloadScheme vfs = (ViewFileSystemOverloadScheme) fs;
136138
assertEquals(0, vfs.getMountPoints().length);
137-
Path testFallBack = new Path("test", FILE_NAME);
138-
assertTrue(vfs.mkdirs(testFallBack));
139-
FileStatus[] status = vfs.listStatus(testFallBack.getParent());
140-
assertEquals(FILE_NAME, status[0].getPath().getName());
141-
assertEquals(testFallBack.getName(),
142-
vfs.getFileLinkStatus(testFallBack).getPath().getName());
139+
Path testOnFallbackPath = new Path(TEST_DIR.toURI().toString(), "test");
140+
assertTrue(vfs.mkdirs(testOnFallbackPath));
141+
FileStatus[] status = vfs.listStatus(testOnFallbackPath.getParent());
142+
assertEquals(Path.getPathWithoutSchemeAndAuthority(testOnFallbackPath),
143+
Path.getPathWithoutSchemeAndAuthority(status[0].getPath()));
144+
//Check directly on localFS. The fallBackFs(localFS) should be chrooted
145+
//at it's root. So, after
146+
FileSystem lfs = vfs.getRawFileSystem(testOnFallbackPath, conf);
147+
FileStatus[] statusOnLocalFS =
148+
lfs.listStatus(testOnFallbackPath.getParent());
149+
assertEquals(testOnFallbackPath.getName(),
150+
statusOnLocalFS[0].getPath().getName());
151+
//initUri should not have exist in lfs, as it would have chrooted on it's
152+
// root only.
153+
assertFalse(lfs.exists(initUri));
143154
}
144155
}
145156

hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/ViewFsOverloadScheme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ If a user wants to continue use the same fs.defaultFS and wants to have more mou
3434
Example if fs.defaultFS is `hdfs://mycluster`, then the mount link configuration key name should be like in the following format `fs.viewfs.mounttable.*mycluster*.link.<mountLinkPath>`.
3535
Even if the initialized fs uri has hostname:port, it will simply ignore the port number and only consider the hostname as the mount table name. We will discuss more example configurations in following sections.
3636
If there are no mount links configured with the initializing uri's hostname as the mount table name, then it will automatically consider the current uri as fallback(`fs.viewfs.mounttable.*mycluster*.linkFallback`) target fs uri.
37+
If the initialized uri contains path part, it will consider only scheme and authority part, but not the path part. Example, if the initialized uri contains `hdfs://mycluster/data`, it will consider only `hdfs://mycluster` as fallback target fs uri.
38+
The path part `data` will be ignored.
3739

3840
Another important improvement with the ViewFileSystemOverloadScheme is, administrators need not copy the `mount-table.xml` configuration file to 1000s of client nodes. Instead, they can keep the mount-table configuration file in a Hadoop compatible file system. So, keeping the configuration file in a central place makes administrators life easier as they can update mount-table in single place.
3941

0 commit comments

Comments
 (0)