Skip to content

Commit da9970d

Browse files
abhishekdas99omalley
authored andcommitted
HADOOP-18129: Change URI to String in INodeLink to reduce memory footprint of ViewFileSystem
Fixes #3996
1 parent 8294bd5 commit da9970d

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ enum LinkType {
273273
* is changed later it is then ignored (a dir with null entries)
274274
*/
275275
public static class INodeLink<T> extends INode<T> {
276-
final URI[] targetDirLinkList;
276+
final String[] targetDirLinkList;
277277
private T targetFileSystem; // file system object created from the link.
278278
// Function to initialize file system. Only applicable for simple links
279279
private Function<URI, T> fileSystemInitMethod;
@@ -283,7 +283,7 @@ public static class INodeLink<T> extends INode<T> {
283283
* Construct a mergeLink or nfly.
284284
*/
285285
INodeLink(final String pathToNode, final UserGroupInformation aUgi,
286-
final T targetMergeFs, final URI[] aTargetDirLinkList) {
286+
final T targetMergeFs, final String[] aTargetDirLinkList) {
287287
super(pathToNode, aUgi);
288288
targetFileSystem = targetMergeFs;
289289
targetDirLinkList = aTargetDirLinkList;
@@ -294,11 +294,11 @@ public static class INodeLink<T> extends INode<T> {
294294
*/
295295
INodeLink(final String pathToNode, final UserGroupInformation aUgi,
296296
Function<URI, T> createFileSystemMethod,
297-
final URI aTargetDirLink) {
297+
final String aTargetDirLink) throws URISyntaxException {
298298
super(pathToNode, aUgi);
299299
targetFileSystem = null;
300-
targetDirLinkList = new URI[1];
301-
targetDirLinkList[0] = aTargetDirLink;
300+
targetDirLinkList = new String[1];
301+
targetDirLinkList[0] = new URI(aTargetDirLink).toString();
302302
this.fileSystemInitMethod = createFileSystemMethod;
303303
}
304304

@@ -336,7 +336,8 @@ public T getTargetFileSystem() throws IOException {
336336
if (targetFileSystem != null) {
337337
return targetFileSystem;
338338
}
339-
targetFileSystem = fileSystemInitMethod.apply(targetDirLinkList[0]);
339+
targetFileSystem =
340+
fileSystemInitMethod.apply(URI.create(targetDirLinkList[0]));
340341
if (targetFileSystem == null) {
341342
throw new IOException(
342343
"Could not initialize target File System for URI : " +
@@ -404,7 +405,7 @@ private void createLink(final String src, final String target,
404405
switch (linkType) {
405406
case SINGLE:
406407
newLink = new INodeLink<T>(fullPath, aUgi,
407-
initAndGetTargetFs(), new URI(target));
408+
initAndGetTargetFs(), target);
408409
break;
409410
case SINGLE_FALLBACK:
410411
case MERGE_SLASH:
@@ -413,10 +414,10 @@ private void createLink(final String src, final String target,
413414
throw new IllegalArgumentException("Unexpected linkType: " + linkType);
414415
case MERGE:
415416
case NFLY:
416-
final URI[] targetUris = StringUtils.stringToURI(
417-
StringUtils.getStrings(target));
417+
final String[] targetUris = StringUtils.getStrings(target);
418418
newLink = new INodeLink<T>(fullPath, aUgi,
419-
getTargetFileSystem(settings, targetUris), targetUris);
419+
getTargetFileSystem(settings, StringUtils.stringToURI(targetUris)),
420+
targetUris);
420421
break;
421422
default:
422423
throw new IllegalArgumentException(linkType + ": Infeasible linkType");
@@ -633,8 +634,7 @@ protected InodeTree(final Configuration config, final String viewName,
633634
if (isMergeSlashConfigured) {
634635
Preconditions.checkNotNull(mergeSlashTarget);
635636
root = new INodeLink<T>(mountTableName, ugi,
636-
initAndGetTargetFs(),
637-
new URI(mergeSlashTarget));
637+
initAndGetTargetFs(), mergeSlashTarget);
638638
mountPoints.add(new MountPoint<T>("/", (INodeLink<T>) root));
639639
rootFallbackLink = null;
640640
} else {
@@ -652,7 +652,7 @@ protected InodeTree(final Configuration config, final String viewName,
652652
+ "not allowed.");
653653
}
654654
fallbackLink = new INodeLink<T>(mountTableName, ugi,
655-
initAndGetTargetFs(), new URI(le.getTarget()));
655+
initAndGetTargetFs(), le.getTarget());
656656
continue;
657657
case REGEX:
658658
addRegexMountEntry(le);
@@ -677,7 +677,7 @@ protected InodeTree(final Configuration config, final String viewName,
677677
.info("Empty mount table detected for {} and considering itself "
678678
+ "as a linkFallback.", theUri);
679679
rootFallbackLink = new INodeLink<T>(mountTableName, ugi,
680-
initAndGetTargetFs(), theUri);
680+
initAndGetTargetFs(), theUri.toString());
681681
getRootDir().addFallbackLink(rootFallbackLink);
682682
}
683683
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,27 @@ public static class MountPoint {
216216
/**
217217
* Array of target FileSystem URIs.
218218
*/
219-
private final URI[] targetFileSystemURIs;
219+
private final String[] targetFileSystemPaths;
220220

221-
MountPoint(Path srcPath, URI[] targetFs) {
221+
MountPoint(Path srcPath, String[] targetFs) {
222222
mountedOnPath = srcPath;
223-
targetFileSystemURIs = targetFs;
223+
targetFileSystemPaths = targetFs;
224224
}
225225

226226
public Path getMountedOnPath() {
227227
return mountedOnPath;
228228
}
229229

230230
public URI[] getTargetFileSystemURIs() {
231-
return targetFileSystemURIs;
231+
URI[] targetUris = new URI[targetFileSystemPaths.length];
232+
for (int i = 0; i < targetFileSystemPaths.length; i++) {
233+
targetUris[i] = URI.create(targetFileSystemPaths[i]);
234+
}
235+
return targetUris;
236+
}
237+
238+
public String[] getTargetFileSystemPaths() {
239+
return targetFileSystemPaths;
232240
}
233241
}
234242

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,18 @@ static AccessControlException readOnlyMountTable(final String operation,
185185

186186

187187
static public class MountPoint {
188-
private Path src; // the src of the mount
189-
private URI[] targets; // target of the mount; Multiple targets imply mergeMount
190-
MountPoint(Path srcPath, URI[] targetURIs) {
188+
// the src of the mount
189+
private Path src;
190+
// Target of the mount; Multiple targets imply mergeMount
191+
private String[] targets;
192+
MountPoint(Path srcPath, String[] targetURIs) {
191193
src = srcPath;
192194
targets = targetURIs;
193195
}
194196
Path getSrc() {
195197
return src;
196198
}
197-
URI[] getTargets() {
199+
String[] getTargets() {
198200
return targets;
199201
}
200202
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,4 +1687,22 @@ public void testTargetFileSystemLazyInitializationForChecksumMethods()
16871687
// viewfs inner cache is disabled
16881688
assertEquals(cacheSize + 1, TestFileUtil.getCacheSize());
16891689
}
1690+
1691+
@Test
1692+
public void testInvalidMountPoints() throws Exception {
1693+
final String clusterName = "cluster" + new Random().nextInt();
1694+
Configuration config = new Configuration(conf);
1695+
config.set(ConfigUtil.getConfigViewFsPrefix(clusterName) + "." +
1696+
Constants.CONFIG_VIEWFS_LINK + "." + "/invalidPath",
1697+
"othermockfs:|mockauth/mockpath");
1698+
1699+
try {
1700+
FileSystem viewFs = FileSystem.get(
1701+
new URI("viewfs://" + clusterName + "/"), config);
1702+
fail("FileSystem should not initialize. Should fail with IOException");
1703+
} catch (IOException ex) {
1704+
assertTrue("Should get URISyntax Exception",
1705+
ex.getMessage().startsWith("URISyntax exception"));
1706+
}
1707+
}
16901708
}

0 commit comments

Comments
 (0)