apache/hadoop · error · FileAlreadyExistsException
Path {strB} already exists as dir; cannot create link here
Error message
Path {strB} already exists as dir; cannot create link here What it means
When the last component of a new link's source path already exists in the inode tree (typically an internal directory created earlier by a deeper mount), InodeTree throws FileAlreadyExistsException('Path <path> already exists as dir; cannot create link here'). A directory and a link cannot occupy the same mount point.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/InodeTree.java:476
throw new FileAlreadyExistsException("Path " + nextInode.fullPath +
" already exists as link");
}
} else {
assert(nextInode.isInternalDir());
curInode = (INodeDir<T>) nextInode;
}
}
// Now process the last component
// Add the link in 2 cases: does not exist or a link exists
String iPath = srcPaths[i];// last component
if (curInode.resolveInternal(iPath) != null) {
// directory/link already exists
StringBuilder strB = new StringBuilder(srcPaths[0]);
for (int j = 1; j <= i; ++j) {
strB.append('/').append(srcPaths[j]);
}
throw new FileAlreadyExistsException("Path " + strB +
" already exists as dir; cannot create link here");
}
final INodeLink<T> newLink;
final String fullPath = curInode.fullPath + (curInode == root ? "" : "/")
+ iPath;
switch (linkType) {
case SINGLE:
newLink = new INodeLink<T>(fullPath, aUgi,
initAndGetTargetFs(), target);
break;
case SINGLE_FALLBACK:
case MERGE_SLASH:
// Link fallback and link merge slash configuration
// are handled specially at InodeTree.
throw new IllegalArgumentException("Unexpected linkType: " + linkType);
case MERGE:
case NFLY:View on GitHub (pinned to 2add963021)
Solutions
- Delete the duplicate or conflicting entry so each source path is claimed exactly once
- Order and deduplicate mount keys when generating configuration
- Search every active config source for the offending fs.viewfs.mounttable keys
Example fix
<!-- before: /a/b mounted, then /a linked at the occupied dir --> <property><name>fs.viewfs.mounttable.cluster.link./a/b</name> <value>hdfs://nnB/b</value></property> <property><name>fs.viewfs.mounttable.cluster.link./a</name> <value>hdfs://nnA/a</value></property> <!-- after: one owner for /a --> <property><name>fs.viewfs.mounttable.cluster.link./a/b</name> <value>hdfs://nnB/b</value></property>
Defensive patterns
Strategy: try-catch
Validate before calling
static boolean hasDuplicateMountSources(Collection<String> srcs) {
return new HashSet<>(srcs).size() != srcs.size();
} Try / catch
Catch FileAlreadyExistsException at ViewFileSystem init; 'already exists as dir; cannot create link here' means a link and a directory claim the same path — locate both fs.viewfs.mounttable entries across all config files and keep one.
Prevention
- Claim each mount path exactly once
- Audit included config files for overlapping viewfs keys
- Validate generated mount tables with a duplicate/overlap check
When it happens
Trigger: Mount entries that first create internal directories (e.g. link./a/b) and then try to link at the same position (e.g. link./a); duplicate link, fallback or nfly entries for the same source path.
Common situations: Appending a root-level link after deeper mounts exist; configuration assembled from multiple files (core-site.xml plus an included file) that both claim the same path.
Related errors
- Path {nextInode.fullPath} already exists as link
- ViewFs: Non absolute mount name in config:{src}
- Unexpected mount table link entry '{key}'. Use linkMergeSlas
- ViewFs: Cannot initialize: Invalid entry in Mount table in c
- getServerDefaults on empty path is invalid
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/fee9499a0d749367.
Report an issue: GitHub.