apache/hadoop · error · IOException
Cannot create directory {curDir}
Error message
Cannot create directory {curDir} What it means
The second guard in Storage.StorageDirectory.clearDirectory(): after successfully deleting current/, curDir.mkdirs() must recreate it, and failure throws IOException('Cannot create directory <curDir>'). This is a plain filesystem failure — the parent must be writable and the path must be free.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java:447
* Derived storage is responsible for setting specific storage values and
* writing the version file to disk.
*
* @throws IOException
*/
public void clearDirectory() throws IOException {
File curDir = this.getCurrentDir();
if (curDir == null) {
// if the directory is null, there is nothing to do.
return;
}
if (curDir.exists()) {
File[] files = FileUtil.listFiles(curDir);
LOG.info("Will remove files: {}", Arrays.toString(files));
if (!(FileUtil.fullyDelete(curDir)))
throw new IOException("Cannot remove current directory: " + curDir);
}
if (!curDir.mkdirs()) {
throw new IOException("Cannot create directory " + curDir);
}
if (permission != null) {
try {
Set<PosixFilePermission> permissions =
PosixFilePermissions.fromString(permission.toString());
Files.setPosixFilePermissions(curDir.toPath(), permissions);
} catch (UnsupportedOperationException uoe) {
// Default to FileUtil for non posix file systems
FileUtil.setPermission(curDir, permission);
}
}
}
/**
* Directory {@code current} contains latest files defining
* the file system meta-data.
*
* @return the directory pathView on GitHub (pinned to 2add963021)
Solutions
- Check parent directory permissions/ownership for the daemon user (chown/chmod the storage root)
- Remove any non-directory file occupying the current path
- Free space and confirm the mount is read-write (df -h, mount), then retry the operation
Example fix
# before df -h /dfs/nn # 100% full, or root-owned # after sudo chown -R hdfs:hdfs /dfs/nn && sudo chmod 755 /dfs/nn df -h /dfs/nn # space available sudo -u hdfs hdfs namenode -format
Defensive patterns
Strategy: validation
Validate before calling
File curDir = sd.getCurrentDir();
File parent = curDir.getParentFile();
if (!parent.canWrite()) throw new IOException("No write permission on " + parent);
if (curDir.exists() && !curDir.isDirectory()) throw new IOException(curDir + " is a file");
if (parent.getUsableSpace() < MIN_FREE_BYTES) throw new IOException("Insufficient space under " + parent);
sd.clearDirectory(); Try / catch
try {
sd.clearDirectory();
} catch (IOException e) {
if (e.getMessage().startsWith("Cannot create directory")) {
throw new IOException("Fix permissions/space on parent of " + sd.getCurrentDir(), e);
} else throw e;
} Prevention
- Pre-flight format scripts: check parent ownership, writability, and free space (df) first
- Keep storage mounts dedicated and monitored for fill/read-only transitions
- Ensure no regular file can shadow the 'current' path
When it happens
Trigger: Format/rollback/finalize where current/ was deleted but recreation fails: no write permission on the parent directory, a non-directory file occupies the path, the filesystem is read-only, or the disk is full.
Common situations: Storage dir owned by root while the daemon runs as hdfs; a leftover file named 'current'; read-only mount after disk errors; full data disk on a DataNode.
Related errors
- Cannot remove current directory: {curDir}
- Cannot create directory {rootPath}
- Can't format the storage directory because the current direc
- Failed to delete {dir}
- Unable to download to any storage directory
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/5a976e33608cd9ec.
Report an issue: GitHub.