apache/hadoop · error · InconsistentFSStateException

previous and finalized.tmpcannot exist together.

Error message

previous and finalized.tmpcannot exist together.

What it means

When finalized.tmp exists, Storage.analyzeStorage expects a finalize to be in flight (previous/ was renamed to finalized.tmp pending deletion; the normal outcome is COMPLETE_FINALIZE). If previous/ is also present, both halves of the finalize exist simultaneously and it throws InconsistentFSStateException (note the message concatenates without a space: 'previous and finalized.tmpcannot exist together.').

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java:754

        }
        return StorageState.NOT_FORMATTED;
      }

      if ((hasPreviousTmp?1:0) + (hasRemovedTmp?1:0)
          + (hasFinalizedTmp?1:0) + (hasCheckpointTmp?1:0) > 1)
        // more than one temp dirs
        throw new InconsistentFSStateException(root,
                                               "too many temporary directories.");

      // # of temp dirs == 1 should either recover or complete a transition
      if (hasCheckpointTmp) {
        return hasCurrent ? StorageState.COMPLETE_CHECKPOINT
                          : StorageState.RECOVER_CHECKPOINT;
      }

      if (hasFinalizedTmp) {
        if (hasPrevious)
          throw new InconsistentFSStateException(root,
                                                 STORAGE_DIR_PREVIOUS + " and " + STORAGE_TMP_FINALIZED
                                                 + "cannot exist together.");
        return StorageState.COMPLETE_FINALIZE;
      }

      if (hasPreviousTmp) {
        if (hasPrevious)
          throw new InconsistentFSStateException(root,
                                                 STORAGE_DIR_PREVIOUS + " and " + STORAGE_TMP_PREVIOUS
                                                 + " cannot exist together.");
        if (hasCurrent)
          return StorageState.COMPLETE_UPGRADE;
        return StorageState.RECOVER_UPGRADE;
      }
      
      assert hasRemovedTmp : "hasRemovedTmp must be true";
      if (!(hasCurrent ^ hasPrevious))
        throw new InconsistentFSStateException(root,

View on GitHub (pinned to 2add963021)

Solutions

  1. Stop the daemon and back up the whole storage directory
  2. Choose the target state: to complete the finalize, remove previous/ and keep finalized.tmp (boot then runs COMPLETE_FINALIZE, which deletes finalized.tmp); to abort the finalize, remove finalized.tmp and keep previous/
  3. Restart the daemon and confirm it reports NORMAL

Example fix

# previous/ AND finalized.tmp both present after crashed finalize
# goal: complete finalize (previous/ is only needed to undo it)
mv /dfs/nn/previous /backup/previous
# restart namenode -> COMPLETE_FINALIZE deletes finalized.tmp -> NORMAL
Defensive patterns

Strategy: try-catch

Validate before calling

File root = sd.getRoot();
boolean hasPrev = new File(root, "previous").exists();
boolean hasFin = new File(root, "finalized.tmp").exists();
if (hasPrev && hasFin) {
  throw new IOException("previous/ and finalized.tmp coexist in " + root
      + "; decide finalize-complete (remove previous/) or abort (remove finalized.tmp)");
}

Try / catch

try {
  daemon.start();
} catch (InconsistentFSStateException e) {
  if (e.getMessage().contains("finalized.tmp")) {
    haltWithRunbook("Crashed finalize: keep finalized.tmp and remove previous/ to complete, "
        + "or remove finalized.tmp to abort; back up first");
  } else throw e;
}

Prevention

When it happens

Trigger: A finalize crashed after finalized.tmp appeared but previous/ also (re)appeared — e.g., a backup of previous/ was restored mid-finalize, or duplicated directory content from rsync/snapshot revert.

Common situations: Finalize interrupted and an operator restored previous/ from a snapshot; storage dir cloned while finalize was running; snapshot rollback on the storage volume.

Related errors


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