{"record":{"id":"c7f5c6fb435fef6e","repo":"apache/hadoop","slug":"cannot-import-image-from-a-checkpoint-namenode-a","errorCode":null,"errorMessage":"Cannot import image from a checkpoint.  NameNode already contains an image in {root}","messagePattern":"Cannot import image from a checkpoint\\.  NameNode already contains an image in (.+?)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java","lineNumber":410,"sourceCode":"          // name-node fails if any of the configured storage dirs are missing\n          throw new InconsistentFSStateException(sd.getRoot(),\n                      \"storage directory does not exist or is not accessible.\");\n        case NOT_FORMATTED:\n          break;\n        case NORMAL:\n          break;\n        default:  // recovery is possible\n          sd.doRecover(curState);\n        }\n        if (curState != StorageState.NOT_FORMATTED \n            && startOpt != StartupOption.ROLLBACK) {\n          // read and verify consistency with other directories\n          storage.readProperties(sd, startOpt);\n          isFormatted = true;\n        }\n        if (startOpt == StartupOption.IMPORT && isFormatted)\n          // import of a checkpoint is allowed only into empty image directories\n          throw new IOException(\"Cannot import image from a checkpoint. \" \n              + \" NameNode already contains an image in \" + sd.getRoot());\n      } catch (IOException ioe) {\n        sd.unlock();\n        throw ioe;\n      }\n      dataDirStates.put(sd,curState);\n    }\n    return isFormatted;\n  }\n\n  /** Check if upgrade is in progress. */\n  public static void checkUpgrade(NNStorage storage) throws IOException {\n    // Upgrade or rolling upgrade is allowed only if there are \n    // no previous fs states in any of the local directories\n    for (Iterator<StorageDirectory> it = storage.dirIterator(false); it.hasNext();) {\n      StorageDirectory sd = it.next();\n      if (sd.getPreviousDir().exists())\n        throw new InconsistentFSStateException(sd.getRoot(),","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java#L392-L428","documentation":"With startup option -importCheckpoint, recoverStorageDirs() found existing formatted state (a readable VERSION) in one of the NameNode's own storage directories. Importing a checkpoint only writes into empty directories so it can never overwrite live namespace metadata; any already-formatted dir aborts the import with this IOException.","triggerScenarios":"Running 'hdfs namenode -importCheckpoint' when dfs.namenode.name.dir already contains current/VERSION; re-running the import after a first (partial) attempt left state behind.","commonSituations":"Disaster-recovery drills where the target node was not cleaned first; double-running import; expecting import to merge metadata (it replaces, and only into empty dirs).","solutions":["Back up and then empty the NameNode dirs: mv <name.dir>/current <name.dir>/current.bak.","Re-run 'hdfs namenode -importCheckpoint'.","Verify dfs.namenode.checkpoint.dir(edits.dir) points at the checkpointer's files before re-importing.","If the existing image must be kept, import on a different node or a different name.dir instead."],"exampleFix":"# before\nhdfs namenode -importCheckpoint\n# IOException: NameNode already contains an image in /dfs/nn\n\n# after\nmv /dfs/nn/current /dfs/nn/current.bak\nhdfs namenode -importCheckpoint","handlingStrategy":"validation","validationCode":"boolean anyFormatted = nameDirs.stream()\n    .anyMatch(u -> Files.exists(Paths.get(u.getPath(), \"current\", \"VERSION\")));\nif (anyFormatted) {\n  throw new IllegalStateException(\n      \"Refusing import: name.dir not empty — back it up and clean it first\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat -importCheckpoint as destructive: clean target dirs explicitly in the runbook.","Always back up current/ before import drills.","Remember import replaces metadata; it does not merge."],"tags":["hdfs","namenode","checkpoint","import","startup"],"backgroundTag":"import-conflict","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}