{"record":{"id":"6965d95a9c4c518b","repo":"apache/hadoop","slug":"cannot-rollback-to-a-newer-state-datanode-previou","errorCode":null,"errorMessage":"Cannot rollback to a newer state.\nDatanode previous state: LV = {} CTime = {} is newer than the namespace state: LV = {} CTime = {}","messagePattern":"Cannot rollback to a newer state\\.\nDatanode previous state: LV = (.+?) CTime = (.+?) is newer than the namespace state: LV = (.+?) CTime = (.+?)","errorType":"exception","errorClass":"InconsistentFSStateException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceStorage.java","lineNumber":621,"sourceCode":"  void doRollback(StorageDirectory bpSd, NamespaceInfo nsInfo)\n      throws IOException {\n    File prevDir = bpSd.getPreviousDir();\n    // regular startup if previous dir does not exist\n    if (prevDir == null || !prevDir.exists()) {\n      return;\n    }\n    // read attributes out of the VERSION file of previous directory\n    BlockPoolSliceStorage prevInfo = new BlockPoolSliceStorage();\n    prevInfo.readPreviousVersionProperties(bpSd);\n\n    // We allow rollback to a state, which is either consistent with\n    // the namespace state or can be further upgraded to it.\n    // In another word, we can only roll back when ( storedLV >= software LV)\n    // && ( DN.previousCTime <= NN.ctime)\n    if (!(prevInfo.getLayoutVersion() >=\n        DataNodeLayoutVersion.getCurrentLayoutVersion() &&\n        prevInfo.getCTime() <= nsInfo.getCTime())) { // cannot rollback\n      throw new InconsistentFSStateException(bpSd.getRoot(),\n          \"Cannot rollback to a newer state.\\nDatanode previous state: LV = \"\n              + prevInfo.getLayoutVersion() + \" CTime = \" + prevInfo.getCTime()\n              + \" is newer than the namespace state: LV = \"\n              + DataNodeLayoutVersion.getCurrentLayoutVersion() + \" CTime = \"\n              + nsInfo.getCTime());\n    }\n\n    LOG.info(\"Rolling back storage directory {}.\\n   target LV = {}; target \"\n            + \"CTime = {}\", bpSd.getRoot(), nsInfo.getLayoutVersion(),\n        nsInfo.getCTime());\n    File tmpDir = bpSd.getRemovedTmp();\n    assert !tmpDir.exists() : \"removed.tmp directory must not exist.\";\n    // 1. rename current to tmp\n    File curDir = bpSd.getCurrentDir();\n    assert curDir.exists() : \"Current directory must exist.\";\n    rename(curDir, tmpDir);\n    \n    // 2. rename previous to current","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceStorage.java#L603-L639","documentation":"Error \"Cannot rollback to a newer state.\nDatanode previous state: LV = {} CTime = {} is newer than the namespace state: LV = {} CTime = {}\" thrown in apache/hadoop.","triggerScenarios":"Rolling back an HDFS upgrade when the DataNode storage was already formatted or finalized by a newer software version than the NameNode, or when the VERSION cTime on the DataNode is ahead of the namespace state.","commonSituations":"Rollback requested while the DataNode storage layout version or cTime is newer than the NameNode namespace state. Prevent by verifying LV/CTime in each storage directory's VERSION file before running rollback.","solutions":["Do not attempt a rollback (-rollback) when the DataNode's stored layout version or CTime is newer than the NameNode's namespace state; rollback is only supported to an older state.","Verify the DataNode and NameNode software versions match, and check the storage directory VERSION files (layoutVersion and cTime) on both sides to confirm which side was upgraded first."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}