apache/hadoop · error · DiskErrorException
Not a directory: ${dir}
Error message
Not a directory: ${dir} What it means
After ensuring the directory exists, DiskChecker.checkAccessByFileMethods requires dir.isDirectory(); a path that exists but is a regular file (or a symlink to one) throws DiskErrorException('Not a directory: <dir>'), failing the storage-directory health check.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DiskChecker.java:156
private static void checkDirInternal(LocalFileSystem localFS, Path dir,
FsPermission expected)
throws DiskErrorException, IOException {
mkdirsWithExistsAndPermissionCheck(localFS, dir, expected);
checkAccessByFileMethods(localFS.pathToFile(dir));
}
/**
* Checks that the current running process can read, write, and execute the
* given directory by using methods of the File object.
*
* @param dir File to check
* @throws DiskErrorException if dir is not readable, not writable, or not
* executable
*/
private static void checkAccessByFileMethods(File dir)
throws DiskErrorException {
if (!dir.isDirectory()) {
throw new DiskErrorException("Not a directory: "
+ dir.toString());
}
if (!FileUtil.canRead(dir)) {
throw new DiskErrorException("Directory is not readable: "
+ dir.toString());
}
if (!FileUtil.canWrite(dir)) {
throw new DiskErrorException("Directory is not writable: "
+ dir.toString());
}
if (!FileUtil.canExecute(dir)) {
throw new DiskErrorException("Directory is not executable: "
+ dir.toString());
}
}View on GitHub (pinned to 2add963021)
Solutions
- Fix the configuration value to point at a real directory
- If a file occupies the path, move it away and create the directory
- Repair symlinks that resolve to regular files
Example fix
# before: yarn.nodemanager.local-dirs = /var/log/hadoop-yarn (a file) # after: point at a directory yarn.nodemanager.local-dirs = /var/lib/hadoop-yarn/local
Defensive patterns
Strategy: validation
Validate before calling
for (String dir : configuredDirs) {
java.nio.file.Path p = java.nio.file.Paths.get(dir);
if (java.nio.file.Files.exists(p) && !java.nio.file.Files.isDirectory(p)) {
throw new IllegalStateException("configured dir is a regular file: " + dir);
}
} Prevention
- Validate storage-dir config values against the filesystem during deployment
- Use config management (Ansible/Chef) that creates directories, not just declares paths
- Avoid symlinking storage paths to files
When it happens
Trigger: A configured data/local/log dir path that is actually a regular file; a symlink in the path resolving to a file; a path built by string concatenation landing on a file.
Common situations: Config values with typos pointing at a jar or log file; admins replacing a directory with a symlink to a file; deployment scripts touching a file where a dir is expected.
Related errors
- Cannot create directory: ${dir}
- Directory is not readable: ${dir}
- Directory is not writable: ${dir}
- Directory is not executable: ${dir}
- Failed to delete ${file}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/cae60ce9862e0828.
Report an issue: GitHub.