{"record":{"id":"bee0ec55e65e4f8a","repo":"apache/hadoop","slug":"mismatched-block-ids-or-generation-stamps-for-the","errorCode":null,"errorMessage":"Mismatched block IDs or generation stamps for the old last block of file {}, the old last block is {}, and the block read from editlog is {}","messagePattern":"Mismatched block IDs or generation stamps for the old last block of file (.+?), the old last block is (.+?), and the block read from editlog is (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java","lineNumber":1093,"sourceCode":"    return sb.toString();\n  }\n\n  /**\n   * Add a new block into the given INodeFile\n   */\n  private void addNewBlock(AddBlockOp op, INodeFile file,\n      ErasureCodingPolicy ecPolicy) throws IOException {\n    BlockInfo[] oldBlocks = file.getBlocks();\n    Block pBlock = op.getPenultimateBlock();\n    Block newBlock= op.getLastBlock();\n    \n    if (pBlock != null) { // the penultimate block is not null\n      assert oldBlocks != null && oldBlocks.length > 0;\n      // compare pBlock with the last block of oldBlocks\n      BlockInfo oldLastBlock = oldBlocks[oldBlocks.length - 1];\n      if (oldLastBlock.getBlockId() != pBlock.getBlockId()\n          || oldLastBlock.getGenerationStamp() != pBlock.getGenerationStamp()) {\n        throw new IOException(\n            \"Mismatched block IDs or generation stamps for the old last block of file \"\n                + op.getPath() + \", the old last block is \" + oldLastBlock\n                + \", and the block read from editlog is \" + pBlock);\n      }\n      \n      oldLastBlock.setNumBytes(pBlock.getNumBytes());\n      if (!oldLastBlock.isComplete()) {\n        fsNamesys.getBlockManager().forceCompleteBlock(oldLastBlock);\n        fsNamesys.getBlockManager().processQueuedMessagesForBlock(pBlock);\n      }\n    } else { // the penultimate block is null\n      Preconditions.checkState(oldBlocks == null || oldBlocks.length == 0);\n    }\n    // add the new block\n    final BlockInfo newBlockInfo;\n    boolean isStriped = ecPolicy != null;\n    if (isStriped) {\n      newBlockInfo = new BlockInfoStriped(newBlock, ecPolicy);","sourceCodeStart":1075,"sourceCodeEnd":1111,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java#L1075-L1111","documentation":"addNewBlock replays OP_ADD_BLOCK: the op's penultimate block must equal the file's current last block in both block id and generation stamp. A mismatch means the namespace's block state diverges from the edit log, and replay stops with IOException naming the file, the old last block, and the block read from the log.","triggerScenarios":"OP_ADD_BLOCK replayed against a file whose block list came from a different image/edits generation; duplicated or out-of-order OP_ADD_BLOCK transactions; corrupted block id or genstamp fields inside the op.","commonSituations":"fsimage restored from one point in time and edits from another; segments duplicated during manual recovery; disk corruption after a host failure.","solutions":["Restore fsimage and edits from the same checkpoint epoch","Recover with 'hdfs namenode -recover', accepting that the skipped transactions are lost","Check JournalNode or NFS journal copies for duplicated or truncated segments, then re-bootstrap standbys from the active"],"exampleFix":"# before: mixed image and edits replay OP_ADD_BLOCK against stale block state\n# IOException: Mismatched block IDs ... for the old last block of file /data/x\n\n# after: single-epoch restore and recovery\nrm -rf /hadoop/dfs/name/current && cp -a backup/current /hadoop/dfs/name/current\nhdfs namenode -recover   # if the chain is still inconsistent","handlingStrategy":"try-catch","validationCode":"hdfs oev -i <segment> -o /tmp/check.xml -p xml\n# a full parse proves block fields and checksums are intact before replay","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadFSEdits(storage, 0);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Mismatched block IDs\")) {\n    // block state diverged from the log: restore a single-epoch image+edits\n    // pair, or restart with 'hdfs namenode -recover' and accept the loss\n  }\n  throw e;\n}","preventionTips":["Keep QJM JournalNodes on separate hosts and monitor their health","Restore image and edits from the same backup epoch","Avoid copying segment files by hand between name directories"],"tags":["hdfs","namenode","edit-log","replay","blocks","generation-stamp","corruption"],"backgroundTag":"edit-log-replay-inconsistency","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}