{"record":{"id":"cee3690de32b1181","repo":"apache/hadoop","slug":"mkdirs-failed-to-create-exists-cwd","errorCode":null,"errorMessage":"Mkdirs failed to create {} (exists={}, cwd={})","messagePattern":"Mkdirs failed to create (.+?) \\(exists=(.+?), cwd=(.+?)\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java","lineNumber":773,"sourceCode":"  @Override\n  public FSDataOutputStream create(Path f, FsPermission permission,\n      boolean overwrite, int bufferSize, short replication, long blockSize,\n      Progressable progress) throws IOException {\n    return create(f, permission, overwrite, true, bufferSize,\n        replication, blockSize, progress);\n  }\n\n  private FSDataOutputStream create(Path f, FsPermission permission,\n      boolean overwrite, boolean createParent, int bufferSize,\n      short replication, long blockSize,\n      Progressable progress) throws IOException {\n    Path parent = f.getParent();\n    if (parent != null) {\n      if (!createParent && !exists(parent)) {\n        throw new FileNotFoundException(\"Parent directory doesn't exist: \"\n            + parent);\n      } else if (!mkdirs(parent)) {\n        throw new IOException(\"Mkdirs failed to create \" + parent\n            + \" (exists=\" + exists(parent) + \", cwd=\" + getWorkingDirectory()\n            + \")\");\n      }\n    }\n    final FSDataOutputStream out;\n    if (writeChecksum) {\n      out = new FSDataOutputStream(\n          new ChecksumFSOutputSummer(this, f, overwrite, bufferSize, replication,\n              blockSize, progress, permission), null);\n    } else {\n      out = fs.create(f, permission, overwrite, bufferSize, replication,\n          blockSize, progress);\n      // remove the checksum file since we aren't writing one\n      Path checkFile = getChecksumFile(f);\n      if (fs.exists(checkFile)) {\n        fs.delete(checkFile, true);\n      }\n    }","sourceCodeStart":755,"sourceCodeEnd":791,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java#L755-L791","documentation":"In ChecksumFileSystem.create, after deciding parents must exist, mkdirs(parent) was invoked and returned false, so the create aborts with IOException. The message includes the parent path, whether it exists after the attempt, and the current working directory, which distinguishes the usual causes: a FILE occupies the parent path, the unix user lacks permission, or the volume is read-only/full.","triggerScenarios":"fs.create(path) (or append-free createInternal paths) where the parent chain is not creatable: parent exists as a regular file (e.g., earlier job wrote a file named 'out' and now 'out/part-0' is requested), parent directory owned by another user without write bit for the daemon's unix user, NFS/mount mounted read-only, or disk-full making the directory entry uncreatable.","commonSituations":"Re-running a job where a previous run left a file (not dir) at the output path; DataNode/NodeManager local dirs with wrong ownership after a user change; stale mount after NFS blip becoming read-only; CI containers running as non-root writing under /var paths.","solutions":["Check what sits at the parent path: FileStatus st = fs.getFileStatus(parent); if it isFile(), delete or rename that file and retry.","Fix unix permissions/ownership: chown/chgrp/chmod the parent chain so the effective daemon user can write; for local dirs ensure dfs.datanode.data.dir / yarn.nodemanager.local-dirs are writable.","Inspect the (exists=..., cwd=...) suffix in the message: exists=false plus a surprising path means a relative path resolved against an unexpected working directory - use absolute paths.","Verify the volume is mounted read-write and has free space (mount -o remount,rw; df -h)."],"exampleFix":"// before\nFSDataOutputStream out = fs.create(new Path(\"/data/out/part-0\"));\n// IOException: Mkdirs failed to create /data/out (exists=true, cwd=/home/me)\n\n// after: a previous run left a FILE at /data/out\nPath parent = new Path(\"/data/out\");\nif (fs.exists(parent) && fs.getFileStatus(parent).isFile()) {\n  fs.delete(parent, false);\n}\nfs.mkdirs(parent);\nFSDataOutputStream out = fs.create(new Path(parent, \"part-0\"));","handlingStrategy":"validation","validationCode":"Path parent = path.getParent();\nif (fs.exists(parent) && !fs.getFileStatus(parent).isDirectory()) {\n  throw new IllegalStateException(parent + \" is a FILE, not a directory\");\n}\nif (!fs.exists(parent) && !fs.mkdirs(parent)) {\n  throw new IOException(\"cannot create \" + parent + \" - check permissions/mount\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  out = fs.create(path);\n} catch (IOException e) { // 'Mkdirs failed to create ...'\n  // inspect (exists=, cwd=): resolve file-vs-dir conflict or unix permissions, then retry\n}","preventionTips":["Pre-flight check that each output parent is a directory and writable by the daemon user.","Clean stale outputs between runs so files never occupy directory names.","In ops runbooks, verify ownership of data dirs after user/host changes."],"tags":["hadoop","filesystem","mkdir","permissions","local-filesystem","path-conflict"],"backgroundTag":"mkdir-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}