{"record":{"id":"eefde0c5171d9aef","repo":"apache/hadoop","slug":"is-not-a-file-the-directory-already-exist-at","errorCode":null,"errorMessage":"/ is not a file. The directory / already exist at: <theInternalDir.fullPath>","messagePattern":"/ is not a file\\. The directory / already exist at: <theInternalDir\\.fullPath>","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java","lineNumber":1455,"sourceCode":"    public void setWorkingDirectory(final Path new_dir) {\n      throw new RuntimeException(\n          \"Internal impl error: getWorkingDir should not have been called\");\n    }\n\n    @Override\n    public FSDataOutputStream append(final Path f, final int bufferSize,\n        final Progressable progress) throws IOException {\n      throw readOnlyMountTable(\"append\", f);\n    }\n\n    @Override\n    public FSDataOutputStream create(final Path f,\n        final FsPermission permission, final boolean overwrite,\n        final int bufferSize, final short replication, final long blockSize,\n        final Progressable progress) throws IOException {\n      Preconditions.checkNotNull(f, \"File cannot be null.\");\n      if (InodeTree.SlashPath.equals(f)) {\n        throw new FileAlreadyExistsException(\n            \"/ is not a file. The directory / already exist at: \"\n                + theInternalDir.fullPath);\n      }\n\n      if (this.fsState.getRootFallbackLink() != null) {\n\n        if (theInternalDir.getChildren().containsKey(f.getName())) {\n          throw new FileAlreadyExistsException(\n              \"A mount path(file/dir) already exist with the requested path: \"\n                  + theInternalDir.getChildren().get(f.getName()).fullPath);\n        }\n\n        FileSystem linkedFallbackFs =\n            this.fsState.getRootFallbackLink().getTargetFileSystem();\n        Path parent = Path.getPathWithoutSchemeAndAuthority(\n            new Path(theInternalDir.fullPath));\n        String leaf = f.getName();\n        Path fileToCreate = new Path(parent, leaf);","sourceCodeStart":1437,"sourceCodeEnd":1473,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java#L1437-L1473","documentation":"ViewFileSystem.InternalDir.create(...) is the target FileSystem for mount-table internal directories. When the create path after resolution is exactly the internal directory itself (remaining path equals '/'), creating a file there is impossible because that 'file' is the mount-table directory; the code throws FileAlreadyExistsException('/ is not a file. The directory / already exist at: <internalPath>').","triggerScenarios":"Creating a file whose viewfs path resolves to a mount-table-only directory, e.g. create('/data') when /data is only a parent of mounts (only /data/hdfs linked), or create('/') on a non-merge-slash mount table; writers that build the output path by stripping one component too many.","commonSituations":"Output/staging configuration pointing at the mount-table root instead of a mounted child; tools that derive 'parent + filename' where the parent is an internal dir; viewfs cutovers where /data became virtual but jobs still write directly to /data.","solutions":["Create the file under a mounted path, e.g. /data/hdfs/<file> instead of /data/<file>","Mount the directory itself: add fs.viewfs.mounttable.default.link.data=hdfs://nameservice1/data so it is a real target, not an internal dir","Configure a linkFallback for the internal dir so creates fall through to a backing cluster","Before creating, check fs.getFileStatus(dir).isDirectory() and fail with a clear message when the target is a mount-table directory"],"exampleFix":"// before\nFSDataOutputStream out = fs.create(new Path(\"/data\")); // /data is an internal dir -> throws\n\n// after\nif (fs.getFileStatus(new Path(\"/data\")).isDirectory()) {\n  throw new IOException(\"refusing to create file at mount-table directory /data\");\n}\nFSDataOutputStream out = fs.create(new Path(\"/data/hdfs/report.csv\")); // mounted child","handlingStrategy":"validation","validationCode":"// Refuse to create at a directory path\nif (fs.exists(f) && fs.getFileStatus(f).isDirectory()) {\n  throw new IOException(f + \" is a mount-table directory; cannot create file there\");\n}\nFSDataOutputStream out = fs.create(f);","typeGuard":null,"tryCatchPattern":"try {\n  out = fs.create(f);\n} catch (FileAlreadyExistsException e) {\n  // f resolved to an internal mount-table dir; redirect under a mounted child\n  out = fs.create(new Path(f, \"part-0000\"));\n}","preventionTips":["Always create files as leaf paths under mounted directories","Validate output-dir configuration at job setup, not at first write","Mount (or linkFallback) any directory applications must write into directly"],"tags":["viewfs","hadoop","create","file-already-exists","mount-table"],"backgroundTag":"file-already-exists","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}