{"record":{"id":"7d499413bc90f4c0","repo":"apache/hadoop","slug":"directory-is-not-writable-dir","errorCode":null,"errorMessage":"Directory is not writable: ${dir}","messagePattern":"Directory is not writable: (.+?)","errorType":"exception","errorClass":"DiskErrorException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DiskChecker.java","lineNumber":166,"sourceCode":"   * \n   * @param dir File to check\n   * @throws DiskErrorException if dir is not readable, not writable, or not\n   *   executable\n   */\n  private static void checkAccessByFileMethods(File dir)\n      throws DiskErrorException {\n    if (!dir.isDirectory()) {\n      throw new DiskErrorException(\"Not a directory: \"\n          + dir.toString());\n    }\n\n    if (!FileUtil.canRead(dir)) {\n      throw new DiskErrorException(\"Directory is not readable: \"\n                                   + dir.toString());\n    }\n\n    if (!FileUtil.canWrite(dir)) {\n      throw new DiskErrorException(\"Directory is not writable: \"\n                                   + dir.toString());\n    }\n\n    if (!FileUtil.canExecute(dir)) {\n      throw new DiskErrorException(\"Directory is not executable: \"\n                                   + dir.toString());\n    }\n  }\n\n  /**\n   * The semantics of mkdirsWithExistsCheck method is different from the mkdirs\n   * method provided in the Sun's java.io.File class in the following way:\n   * While creating the non-existent parent directories, this method checks for\n   * the existence of those directories if the mkdir fails at any point (since\n   * that directory might have just been created by some other process).\n   * If both mkdir() and the exists() check fails for any seemingly\n   * non-existent directory, then we signal an error; Sun's mkdir would signal\n   * an error (return false) if a directory it is attempting to create already","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DiskChecker.java#L148-L184","documentation":"checkAccessByFileMethods rejects a storage directory whose FileUtil.canWrite(dir) returns false, throwing DiskErrorException('Directory is not writable: <dir>'). Without the write bit the daemon cannot create files or subdirectories, so the directory fails the health check.","triggerScenarios":"Directory mode lacks the write bit for the daemon user (e.g. 555); directory owned by another user; a read-only mount even when mode bits look fine.","commonSituations":"Storage dirs created by provisioning tools as root; umask/settings producing read-only dirs; volumes remounted read-only after an fsck or disk error.","solutions":["Add the write bit: chmod u+w <dir> (or chmod 755) as appropriate","chown the directory to the daemon user/group","Confirm the filesystem is mounted read-write (mount | grep <dir>)","Re-test with sudo -u <daemon> touch <dir>/.probe"],"exampleFix":"# before\nsudo -u hdfs touch /data/dfs/dn/.probe   # Permission denied\n# after\nsudo chmod 755 /data/dfs/dn && sudo chown hdfs:hadoop /data/dfs/dn && sudo -u hdfs touch /data/dfs/dn/.probe","handlingStrategy":"validation","validationCode":"import java.nio.file.*;\nfor (String dir : configuredDirs) {\n  Path p = Paths.get(dir);\n  if (!Files.isWritable(p)) {\n    throw new IllegalStateException(\"directory not writable by \" + System.getProperty(\"user.name\") + \": \" + dir);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["chown storage dirs to the daemon user at provisioning time","Verify with `sudo -u <daemon> touch <dir>/.probe` before starting services","Watch for volumes flipping read-only after disk errors (check `mount` output)"],"tags":["disk","permissions","filesystem","diskchecker","writable"],"backgroundTag":"permission-denied","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}