{"record":{"id":"6b53a0241a4382d3","repo":"apache/hadoop","slug":"mkdirs-failed-to-create-6b53a0","errorCode":null,"errorMessage":"Mkdirs failed to create {}","messagePattern":"Mkdirs failed to create (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FileIoProvider.java","lineNumber":670,"sourceCode":"   *                     not exist and could not be created.\n   */\n  public boolean mkdirs(\n      @Nullable FsVolumeSpi volume, File dir) throws IOException {\n    final long begin = profilingEventHook.beforeMetadataOp(volume, MKDIRS);\n    boolean created = false;\n    boolean isDirectory;\n    try {\n      faultInjectorEventHook.beforeMetadataOp(volume, MKDIRS);\n      created = dir.mkdirs();\n      isDirectory = !created && dir.isDirectory();\n      profilingEventHook.afterMetadataOp(volume, MKDIRS, begin);\n    } catch(Exception e) {\n      onFailure(volume, begin);\n      throw e;\n    }\n\n    if (!created && !isDirectory) {\n      throw new IOException(\"Mkdirs failed to create \" + dir);\n    }\n    return created;\n  }\n\n  /**\n   * Create the target directory using {@link File#mkdirs()} only if\n   * it doesn't exist already.\n   *\n   * @param volume  target volume. null if unavailable.\n   * @param dir  directory to be created.\n   * @throws IOException  if the directory could not created\n   */\n  public void mkdirsWithExistsCheck(\n      @Nullable FsVolumeSpi volume, File dir) throws IOException {\n    final long begin = profilingEventHook.beforeMetadataOp(volume, MKDIRS);\n    boolean succeeded = false;\n    try {\n      faultInjectorEventHook.beforeMetadataOp(volume, MKDIRS);","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FileIoProvider.java#L652-L688","documentation":"FileIoProvider.mkdirs(volume, dir) calls java.io.File.mkdirs(); if it returns false and the path is still not a directory, an IOException('Mkdirs failed to create ' + dir) is thrown. File.mkdirs() returns false when a parent is missing or non-writable, a non-directory file already occupies the path, or the filesystem refuses the operation (ENOSPC, EIO, read-only mount).","triggerScenarios":"The DataNode creating a block-pool subdirectory or block subdir on a volume where a parent directory lacks write permission for the DN user, a regular file already exists at the path, the disk or inode table is full, or the underlying mount (NFS/fuse) errors out.","commonSituations":"DataNode started under a different user than the owner of dfs.datanode.data.dir; disk full or inode exhaustion; a stray file occupying a directory path; flaky fuse/NFS mounts backing a data dir.","solutions":["Check ownership and permissions on the target dir and all parents: chown -R <dn-user>:<dn-group> and chmod so the DataNode user can write.","Check disk and inode headroom on the volume: `df -h <vol>` and `df -i <vol>`; free space if either is exhausted.","Confirm nothing occupies the path as a plain file: `ls -ld <dir>`; remove or relocate the conflicting file.","If the volume sits on NFS/fuse, verify the mount is healthy (`mount`, dmesg) before retrying."],"exampleFix":"// before: assume mkdirs succeeds\nfileIoProvider.mkdirs(volume, dir);\n\n// after: pre-flight the conditions that make mkdirs fail\nPath p = dir.toPath();\nif (Files.exists(p) && !Files.isDirectory(p)) {\n  throw new IOException(\"path occupied by a non-directory file: \" + dir);\n}\nif (!Files.isWritable(p.getParent())) {\n  throw new IOException(\"parent not writable by \" + System.getProperty(\"user.name\"));\n}\nfileIoProvider.mkdirs(volume, dir);","handlingStrategy":"validation","validationCode":"Path p = dir.toPath();\nif (Files.exists(p) && !Files.isDirectory(p)) {\n  // a file occupies the path: remove or relocate it first\n}\nif (!Files.isWritable(p.getParent())) {\n  // fix ownership/permissions for the DataNode user before mkdirs\n}\nif (Files.getFileStore(p.getParent()).getUsableSpace() <= 0) {\n  // no space on volume: free some before mkdirs\n}","typeGuard":null,"tryCatchPattern":"try {\n  fileIoProvider.mkdirs(volume, dir);\n} catch (IOException e) {\n  // message names the dir; check perms, path conflicts, and df -h / df -i on that volume\n}","preventionTips":["Keep the entire data-dir tree owned and writable by the DataNode user","Monitor both disk space and inode usage on data volumes","Never place regular files where block-pool directories are expected"],"tags":["filesystem","mkdirs","permissions","disk-full","hdfs","datanode"],"backgroundTag":"mkdir-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}