apache/hadoop · error · IOException
Mkdirs failed to create {} (exists={}, cwd={})
Error message
Mkdirs failed to create {} (exists={}, cwd={}) What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java:773
@Override
public FSDataOutputStream create(Path f, FsPermission permission,
boolean overwrite, int bufferSize, short replication, long blockSize,
Progressable progress) throws IOException {
return create(f, permission, overwrite, true, bufferSize,
replication, blockSize, progress);
}
private FSDataOutputStream create(Path f, FsPermission permission,
boolean overwrite, boolean createParent, int bufferSize,
short replication, long blockSize,
Progressable progress) throws IOException {
Path parent = f.getParent();
if (parent != null) {
if (!createParent && !exists(parent)) {
throw new FileNotFoundException("Parent directory doesn't exist: "
+ parent);
} else if (!mkdirs(parent)) {
throw new IOException("Mkdirs failed to create " + parent
+ " (exists=" + exists(parent) + ", cwd=" + getWorkingDirectory()
+ ")");
}
}
final FSDataOutputStream out;
if (writeChecksum) {
out = new FSDataOutputStream(
new ChecksumFSOutputSummer(this, f, overwrite, bufferSize, replication,
blockSize, progress, permission), null);
} else {
out = fs.create(f, permission, overwrite, bufferSize, replication,
blockSize, progress);
// remove the checksum file since we aren't writing one
Path checkFile = getChecksumFile(f);
if (fs.exists(checkFile)) {
fs.delete(checkFile, true);
}
}View on GitHub (pinned to 2add963021)
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).
Example fix
// before
FSDataOutputStream out = fs.create(new Path("/data/out/part-0"));
// IOException: Mkdirs failed to create /data/out (exists=true, cwd=/home/me)
// after: a previous run left a FILE at /data/out
Path parent = new Path("/data/out");
if (fs.exists(parent) && fs.getFileStatus(parent).isFile()) {
fs.delete(parent, false);
}
fs.mkdirs(parent);
FSDataOutputStream out = fs.create(new Path(parent, "part-0")); Defensive patterns
Strategy: validation
Validate before calling
Path parent = path.getParent();
if (fs.exists(parent) && !fs.getFileStatus(parent).isDirectory()) {
throw new IllegalStateException(parent + " is a FILE, not a directory");
}
if (!fs.exists(parent) && !fs.mkdirs(parent)) {
throw new IOException("cannot create " + parent + " - check permissions/mount");
} Try / catch
try {
out = fs.create(path);
} catch (IOException e) { // 'Mkdirs failed to create ...'
// inspect (exists=, cwd=): resolve file-vs-dir conflict or unix permissions, then retry
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Checksum file not a length multiple of checksum size in {} a
- Checksum error: {} at {}
- Checksum error: {} at {} exp: {} got: {}
- Append is not supported by ChecksumFileSystem
- Truncate is not supported by ChecksumFileSystem
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/cee3690de32b1181.
Report an issue: GitHub.