{"record":{"id":"a9fb00f403cab8c3","repo":"apache/hadoop","slug":"failed-to-create-directory","errorCode":null,"errorMessage":"Failed to create directory {}","messagePattern":"Failed to create directory (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceStorage.java","lineNumber":569,"sourceCode":"      throws  IOException {\n    int filesRestored = 0;\n    File[] children = trashRoot.exists() ? trashRoot.listFiles() : null;\n    if (children == null) {\n      return 0;\n    }\n\n    File restoreDirectory = null;\n    for (File child : children) {\n      if (child.isDirectory()) {\n        // Recurse to process subdirectories.\n        filesRestored += restoreBlockFilesFromTrash(child);\n        continue;\n      }\n\n      if (restoreDirectory == null) {\n        restoreDirectory = new File(getRestoreDirectory(child));\n        if (!restoreDirectory.exists() && !restoreDirectory.mkdirs()) {\n          throw new IOException(\"Failed to create directory \" + restoreDirectory);\n        }\n      }\n\n      final File newChild = new File(restoreDirectory, child.getName());\n\n      if (newChild.exists() && newChild.length() >= child.length()) {\n        // Failsafe - we should not hit this case but let's make sure\n        // we never overwrite a newer version of a block file with an\n        // older version.\n        LOG.info(\"Not overwriting {} with smaller file from \" +\n            \"trash directory. This message can be safely ignored.\", newChild);\n      } else if (!child.renameTo(newChild)) {\n        throw new IOException(\"Failed to rename \" + child + \" to \" + newChild);\n      } else {\n        ++filesRestored;\n      }\n    }\n    FileUtil.fullyDelete(trashRoot);","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceStorage.java#L551-L587","documentation":"While restoring block files from the rolling-upgrade trash directory back into current/ (restoreBlockFilesFromTrash), mkdirs() for the target restore directory failed — the directory hierarchy for the restored block could not be created.","triggerScenarios":"No write permission or no space on the volume; a non-directory file exists at the path where the directory should be created; read-only mount during rollback.","commonSituations":"Rolling-upgrade rollback on a full disk; DN user changed since the upgrade; leftover stray files colliding with the restore path.","solutions":["Check free space (df) and inodes on the volume; free space if needed","Fix ownership/permissions so the DN user can write under current/finalized/","Remove any non-directory file occupying the target path, then retry the rollback"],"exampleFix":"df -h /dfs/dn\nchown -R hdfs:hdfs /dfs/dn/current/BP-*/current\nhdfs --daemon start datanode -rollback","handlingStrategy":"try-catch","validationCode":"// Pre-rollback checks:\nif (targetDir.getUsableSpace() < minFreeBytes) throw new IOException(\"insufficient space\");\nif (!Files.isWritable(targetDir.getCanonicalFile().getParentFile().toPath())) {\n  throw new IOException(\"no write permission for restore target\");\n}","typeGuard":null,"tryCatchPattern":"catch (IOException e) {\n  if (e.getMessage().contains(\"Failed to create directory\")) {\n    // stop the rollback cleanly; operator frees space/fixes perms, then retry\n    abortRollbackForOperatorIntervention(e);\n  }\n}","preventionTips":["Keep headroom on DN volumes (monitor free space/inodes) before starting a rolling-upgrade rollback","Verify DN-user ownership of the whole storage tree before upgrades/rollbacks"],"tags":["hdfs","datanode","storage","rollback","disk-full"],"backgroundTag":"filesystem-permission-denied","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}