{"record":{"id":"6489adac106b2072","repo":"apache/hadoop","slug":"cannot-create-directory-dir","errorCode":null,"errorMessage":"Cannot create directory: ${dir}","messagePattern":"Cannot create directory: (.+?)","errorType":"exception","errorClass":"DiskErrorException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DiskChecker.java","lineNumber":97,"sourceCode":"\n  /**\n   * Create the directory if it doesn't exist and check that dir is\n   * readable, writable and executable. Perform some disk IO to\n   * ensure that the disk is usable for writes.\n   *\n   * @param dir dir.\n   * @throws DiskErrorException disk problem.\n   */\n  public static void checkDirWithDiskIo(File dir)\n      throws DiskErrorException {\n    checkDirInternal(dir);\n    doDiskIo(dir);\n  }\n\n  private static void checkDirInternal(File dir)\n      throws DiskErrorException {    \n    if (!mkdirsWithExistsCheck(dir)) {\n      throw new DiskErrorException(\"Cannot create directory: \"\n                                   + dir.toString());\n    }\n    checkAccessByFileMethods(dir);\n  }\n\n  /**\n   * Create the local directory if necessary, check permissions and also ensure\n   * it can be read from and written into.\n   *\n   * @param localFS local filesystem\n   * @param dir directory\n   * @param expected permission\n   * @throws DiskErrorException disk problem.\n   * @throws IOException raised on errors performing I/O.\n   */\n  public static void checkDir(LocalFileSystem localFS, Path dir,\n                              FsPermission expected)\n      throws DiskErrorException, IOException {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DiskChecker.java#L79-L115","documentation":"DiskChecker.checkDirInternal calls mkdirsWithExistsCheck() (a race-tolerant mkdir) and throws DiskErrorException('Cannot create directory: <dir>') when mkdir fails and the path still does not exist. This check guards every local storage directory DataNodes and NodeManagers use (data dirs, local dirs, log dirs), at startup and during periodic health checks.","triggerScenarios":"A parent directory not writable by the daemon user; a path component exists as a regular file; a read-only or unmounted filesystem returning EACCES/EROFS from mkdir.","commonSituations":"dfs.datanode.data.dir, yarn.nodemanager.local-dirs or yarn.nodemanager.log-dirs pointing at unwritable paths; directory ownership changing after cluster handover; mounts lost after reboot; SELinux denials.","solutions":["Create the directory manually as the daemon user (sudo -u hdfs mkdir -p <dir>) to surface the real OS error","chown the directory to the daemon user or chmod it writable","Check the filesystem is mounted read-write and the mount survives reboots","Correct the typo'd path in the configuration"],"exampleFix":"# before\nsudo mkdir -p /data/dfs/dn && chmod 700 /data/dfs/dn   # owned by root, DataNode cannot create subdirs\n# after\nsudo mkdir -p /data/dfs/dn && sudo chown -R hdfs:hadoop /data/dfs/dn && sudo -u hdfs mkdir /data/dfs/dn/current","handlingStrategy":"validation","validationCode":"void preflightDirs(Path... dirs) throws IOException {\n  for (Path p : dirs) {\n    java.nio.file.Path d = java.nio.file.Paths.get(p.toString());\n    java.nio.file.Files.createDirectories(d);          // throws with the real OS reason\n    if (!java.nio.file.Files.isWritable(d)) {\n      throw new IOException(\"not writable by this user: \" + d);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  DiskChecker.checkDir(localFS, dir, expected);\n} catch (DiskErrorException e) {\n  // surface immediately at startup with the failing dir in the message\n  throw new RuntimeException(\"storage dir failed check: \" + dir, e);\n}","preventionTips":["Provision and chown storage dirs as the daemon user before first start","Run a create+write probe as the daemon user (sudo -u hdfs touch dir/.probe) in deployment scripts","Monitor mounts so directories survive reboots and failover"],"tags":["disk","filesystem","permissions","datanode","nodemanager","diskchecker"],"backgroundTag":"directory-creation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}