{"record":{"id":"3f6793e101707057","repo":"apache/hadoop","slug":"previous-and-finalized-tmpcannot-exist-together","errorCode":null,"errorMessage":"previous and finalized.tmpcannot exist together.","messagePattern":"previous and finalized\\.tmpcannot exist together\\.","errorType":"exception","errorClass":"InconsistentFSStateException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java","lineNumber":754,"sourceCode":"        }\n        return StorageState.NOT_FORMATTED;\n      }\n\n      if ((hasPreviousTmp?1:0) + (hasRemovedTmp?1:0)\n          + (hasFinalizedTmp?1:0) + (hasCheckpointTmp?1:0) > 1)\n        // more than one temp dirs\n        throw new InconsistentFSStateException(root,\n                                               \"too many temporary directories.\");\n\n      // # of temp dirs == 1 should either recover or complete a transition\n      if (hasCheckpointTmp) {\n        return hasCurrent ? StorageState.COMPLETE_CHECKPOINT\n                          : StorageState.RECOVER_CHECKPOINT;\n      }\n\n      if (hasFinalizedTmp) {\n        if (hasPrevious)\n          throw new InconsistentFSStateException(root,\n                                                 STORAGE_DIR_PREVIOUS + \" and \" + STORAGE_TMP_FINALIZED\n                                                 + \"cannot exist together.\");\n        return StorageState.COMPLETE_FINALIZE;\n      }\n\n      if (hasPreviousTmp) {\n        if (hasPrevious)\n          throw new InconsistentFSStateException(root,\n                                                 STORAGE_DIR_PREVIOUS + \" and \" + STORAGE_TMP_PREVIOUS\n                                                 + \" cannot exist together.\");\n        if (hasCurrent)\n          return StorageState.COMPLETE_UPGRADE;\n        return StorageState.RECOVER_UPGRADE;\n      }\n      \n      assert hasRemovedTmp : \"hasRemovedTmp must be true\";\n      if (!(hasCurrent ^ hasPrevious))\n        throw new InconsistentFSStateException(root,","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java#L736-L772","documentation":"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.').","triggerScenarios":"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.","commonSituations":"Finalize interrupted and an operator restored previous/ from a snapshot; storage dir cloned while finalize was running; snapshot rollback on the storage volume.","solutions":["Stop the daemon and back up the whole storage directory","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/","Restart the daemon and confirm it reports NORMAL"],"exampleFix":"# previous/ AND finalized.tmp both present after crashed finalize\n# goal: complete finalize (previous/ is only needed to undo it)\nmv /dfs/nn/previous /backup/previous\n# restart namenode -> COMPLETE_FINALIZE deletes finalized.tmp -> NORMAL","handlingStrategy":"try-catch","validationCode":"File root = sd.getRoot();\nboolean hasPrev = new File(root, \"previous\").exists();\nboolean hasFin = new File(root, \"finalized.tmp\").exists();\nif (hasPrev && hasFin) {\n  throw new IOException(\"previous/ and finalized.tmp coexist in \" + root\n      + \"; decide finalize-complete (remove previous/) or abort (remove finalized.tmp)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  daemon.start();\n} catch (InconsistentFSStateException e) {\n  if (e.getMessage().contains(\"finalized.tmp\")) {\n    haltWithRunbook(\"Crashed finalize: keep finalized.tmp and remove previous/ to complete, \"\n        + \"or remove finalized.tmp to abort; back up first\");\n  } else throw e;\n}","preventionTips":["Do not restore previous/ from snapshots while a finalize is in flight","Verify finalize completed (previous/ gone) before taking storage snapshots","One transition at a time; let each finish before the next"],"tags":["hdfs","storage","finalize","upgrade","inconsistent-state","recovery"],"backgroundTag":"inconsistent-storage-state","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}