{"record":{"id":"cabd9c556c2b5390","repo":"apache/hadoop","slug":"cannot-create-directory-curdir-cabd9c","errorCode":null,"errorMessage":"Cannot create directory {curDir}","messagePattern":"Cannot create directory (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNUpgradeUtil.java","lineNumber":170,"sourceCode":"   */\n  public static void renameCurToTmp(StorageDirectory sd) throws IOException {\n    File curDir = sd.getCurrentDir();\n    File prevDir = sd.getPreviousDir();\n    final File tmpDir = sd.getPreviousTmp();\n\n    Preconditions.checkState(curDir.exists(),\n        \"Current directory must exist for preupgrade.\");\n    Preconditions.checkState(!prevDir.exists(),\n        \"Previous directory must not exist for preupgrade.\");\n    Preconditions.checkState(!tmpDir.exists(),\n        \"Previous.tmp directory must not exist for preupgrade.\"\n            + \"Consider restarting for recovery.\");\n\n    // rename current to tmp\n    NNStorage.rename(curDir, tmpDir);\n\n    if (!curDir.mkdir()) {\n      throw new IOException(\"Cannot create directory \" + curDir);\n    }\n  }\n  \n  /**\n   * Perform the upgrade of the storage dir to the given storage info. The new\n   * storage info is written into the current directory, and the previous.tmp\n   * directory is renamed to previous.\n   * \n   * @param sd the storage directory to upgrade\n   * @param storage info about the new upgraded versions.\n   * @throws IOException in the event of error\n   */\n  public static void doUpgrade(StorageDirectory sd, Storage storage)\n      throws IOException {\n    LOG.info(\"Performing upgrade of storage directory \" + sd.getRoot());\n    try {\n      // Write the version file, since saveFsImage only makes the\n      // fsimage_<txid>, and the directory is otherwise empty.","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNUpgradeUtil.java#L152-L188","documentation":"Thrown by NNUpgradeUtil.doPreUpgrade during an upgrade. The code first renames 'current' to 'previous.tmp' (after Preconditions confirmed current existed and previous/previous.tmp did not), then calls curDir.mkdir() to create a fresh 'current'. If mkdir() returns false, the IOException is raised: the storage directory's parent is not writable, the filesystem is read-only or full, or a concurrent process raced the rename.","triggerScenarios":"'hdfs namenode -upgrade' (or journal node / storage-dir upgrade path calling doPreUpgrade) where the NameNode user cannot create 'current' after the rename: no write permission on the name dir, ENOSPC, a read-only or NFS-ro mount, or a second NameNode process recreating 'current' between rename and mkdir.","commonSituations":"Name dirs owned by root while NN runs as 'hdfs'; disk full on the name volume; NFS/SAN mount mounted read-only during maintenance; accidentally starting two NameNode processes against the same dfs.namenode.name.dir.","solutions":["Verify ownership and write permission of every dfs.namenode.name.dir / dfs.namenode.edits.dir for the NN user: 'sudo -u hdfs ls -ld <dir>'; fix with chown/chmod.","Check disk space ('df -h <name-dir>') and mount flags ('mount | grep <dir>'); free space or remount read-write.","Ensure exactly one NameNode process is running ('jps', pid files); kill the stale one holding or recreating the directory.","If the failure left 'previous.tmp' behind, restarting the NameNode triggers recovery of the interrupted rename before retrying the upgrade (the Preconditions message hints at this)."],"exampleFix":"// before\nsudo -u hdfs hdfs namenode -upgrade   # NN user cannot write the name dir\n\n// after\nchown -R hdfs:hdfs /data/dfs/name\nchmod 700 /data/dfs/name\nsudo -u hdfs hdfs namenode -upgrade","handlingStrategy":"validation","validationCode":"// pre-flight before 'hdfs namenode -upgrade'\nfor (Path p : nameDirs) {\n  File f = new File(p.toString());\n  if (!Files.isWritable(f.getParentFile().toPath()))\n    throw new IllegalStateException(\"name dir not writable: \" + f);\n  if (f.getUsableSpace() < MIN_BYTES) throw new IllegalStateException(\"low disk: \" + f);\n}\nFiles.list(dir).filter(n -> n.getFileName().toString().startsWith(\"previous\")).forEach(n -> fail(\"stale previous dir: \" + n));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a write/canary test as the NN user in every dfs.namenode.name.dir before upgrade windows.","Disk-space and mount-read-only alerts on name volumes; upgrades blocked while alerts fire.","Enforce single-NameNode-per-storage-dir with fencing (format/node id checks) so a second process cannot race the rename."],"tags":["hdfs","namenode","upgrade","permissions","disk-full","filesystem"],"backgroundTag":"storage-directory-not-writable","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}