apache/hadoop · error · java.io.IOException

Cannot import image from a checkpoint. NameNode already con

Error message

Cannot import image from a checkpoint.  NameNode already contains an image in {root}

What it means

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.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java:410

          // name-node fails if any of the configured storage dirs are missing
          throw new InconsistentFSStateException(sd.getRoot(),
                      "storage directory does not exist or is not accessible.");
        case NOT_FORMATTED:
          break;
        case NORMAL:
          break;
        default:  // recovery is possible
          sd.doRecover(curState);
        }
        if (curState != StorageState.NOT_FORMATTED 
            && startOpt != StartupOption.ROLLBACK) {
          // read and verify consistency with other directories
          storage.readProperties(sd, startOpt);
          isFormatted = true;
        }
        if (startOpt == StartupOption.IMPORT && isFormatted)
          // import of a checkpoint is allowed only into empty image directories
          throw new IOException("Cannot import image from a checkpoint. " 
              + " NameNode already contains an image in " + sd.getRoot());
      } catch (IOException ioe) {
        sd.unlock();
        throw ioe;
      }
      dataDirStates.put(sd,curState);
    }
    return isFormatted;
  }

  /** Check if upgrade is in progress. */
  public static void checkUpgrade(NNStorage storage) throws IOException {
    // Upgrade or rolling upgrade is allowed only if there are 
    // no previous fs states in any of the local directories
    for (Iterator<StorageDirectory> it = storage.dirIterator(false); it.hasNext();) {
      StorageDirectory sd = it.next();
      if (sd.getPreviousDir().exists())
        throw new InconsistentFSStateException(sd.getRoot(),

View on GitHub (pinned to 2add963021)

Solutions

  1. Back up and then empty the NameNode dirs: mv <name.dir>/current <name.dir>/current.bak.
  2. Re-run 'hdfs namenode -importCheckpoint'.
  3. Verify dfs.namenode.checkpoint.dir(edits.dir) points at the checkpointer's files before re-importing.
  4. If the existing image must be kept, import on a different node or a different name.dir instead.

Example fix

# before
hdfs namenode -importCheckpoint
# IOException: NameNode already contains an image in /dfs/nn

# after
mv /dfs/nn/current /dfs/nn/current.bak
hdfs namenode -importCheckpoint
Defensive patterns

Strategy: validation

Validate before calling

boolean anyFormatted = nameDirs.stream()
    .anyMatch(u -> Files.exists(Paths.get(u.getPath(), "current", "VERSION")));
if (anyFormatted) {
  throw new IllegalStateException(
      "Refusing import: name.dir not empty — back it up and clean it first");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/c7f5c6fb435fef6e. Report an issue: GitHub.