{"record":{"id":"a052a838939a88d9","repo":"apache/hadoop","slug":"mismatched-block-ids-or-generation-stamps-attempt","errorCode":null,"errorMessage":"Mismatched block IDs or generation stamps, attempting to replace block {} with {} as block # {}/{} of {}","messagePattern":"Mismatched block IDs or generation stamps, attempting to replace block (.+?) with (.+?) as block # (.+?)/(.+?) of (.+?)","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":1147,"sourceCode":"      throws IOException {\n    // Update its block list\n    BlockInfo[] oldBlocks = file.getBlocks();\n    Block[] newBlocks = op.getBlocks();\n    String path = op.getPath();\n    \n    // Are we only updating the last block's gen stamp.\n    boolean isGenStampUpdate = oldBlocks.length == newBlocks.length;\n    \n    // First, update blocks in common\n    for (int i = 0; i < oldBlocks.length && i < newBlocks.length; i++) {\n      BlockInfo oldBlock = oldBlocks[i];\n      Block newBlock = newBlocks[i];\n      \n      boolean isLastBlock = i == newBlocks.length - 1;\n      if (oldBlock.getBlockId() != newBlock.getBlockId() ||\n          (oldBlock.getGenerationStamp() != newBlock.getGenerationStamp() && \n              !(isGenStampUpdate && isLastBlock))) {\n        throw new IOException(\"Mismatched block IDs or generation stamps, \" +\n            \"attempting to replace block \" + oldBlock + \" with \" + newBlock +\n            \" as block # \" + i + \"/\" + newBlocks.length + \" of \" +\n            path);\n      }\n      \n      oldBlock.setNumBytes(newBlock.getNumBytes());\n      boolean changeMade =\n        oldBlock.getGenerationStamp() != newBlock.getGenerationStamp();\n      final long newGenerationStamp = newBlock.getGenerationStamp();\n      oldBlock.setGenerationStamp(newGenerationStamp);\n      // Update global generation stamp in Standby NameNode\n      fsNamesys.getBlockManager().getBlockIdManager().\n          setGenerationStampIfGreater(newGenerationStamp);\n\n      if (!oldBlock.isComplete() &&\n          (!isLastBlock || op.shouldCompleteLastBlock())) {\n        changeMade = true;\n        fsNamesys.getBlockManager().forceCompleteBlock(oldBlock);","sourceCodeStart":1129,"sourceCodeEnd":1165,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java#L1129-L1165","documentation":"updateBlocks aligns a file's existing block list with the new list carried by an OP_ADD, OP_CLOSE, or OP_SET_BLOCKS op. For shared indices the block ids must match, and generation stamps must match except on the last block when the op is a pure generation-stamp update (equal-length lists). Any other mismatch throws IOException with both blocks, the index, and the path.","triggerScenarios":"Replaying a block-list update whose prefix disagrees with the file's current blocks: image and edits from different generations, the same update replayed twice, or corrupted block records in the op.","commonSituations":"Same family as other replay inconsistencies: mixed backup files, duplicated segments, post-crash corruption.","solutions":["Restore a consistent fsimage plus edits from one checkpoint epoch","Run 'hdfs namenode -recover' to skip the inconsistent section","Audit all journal copies (JournalNodes, NFS) for duplicated, overlapping, or truncated segments"],"exampleFix":"# before: replay halts on 'Mismatched block IDs ... attempting to replace block'\nhdfs --daemon start namenode\n\n# after: verify the segment chain, then recover\nhdfs oev -i <suspect-segment> -o /tmp/check.xml -p xml   # confirm parse failure\nhdfs namenode -recover","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  loader.loadFSEdits(storage, 0);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"attempting to replace block\")) {\n    // block list prefix disagrees with namespace state: single-epoch restore\n    // or 'hdfs namenode -recover'\n  }\n  throw e;\n}","preventionTips":["Take regular checkpoints so replay windows stay small","Keep disk and journal backends healthy; corruption is the usual root cause","Never mix segments from different recovery attempts in one directory"],"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"}