{"record":{"id":"21d6658aadf823e2","repo":"apache/hadoop","slug":"trying-to-commit-inconsistent-block-id-blockid","errorCode":null,"errorMessage":"Trying to commit inconsistent block: id = {blockId}, expected id = {expectedId}","messagePattern":"Trying to commit inconsistent block: id = (.+?), expected id = (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfo.java","lineNumber":444,"sourceCode":"  public List<ReplicaUnderConstruction> setGenerationStampAndVerifyReplicas(\n      long genStamp) {\n    Preconditions.checkState(uc != null && !isComplete());\n    // Set the generation stamp for the block.\n    setGenerationStamp(genStamp);\n\n    return uc.getStaleReplicas(genStamp);\n  }\n\n  /**\n   * Commit block's length and generation stamp as reported by the client.\n   * Set block state to {@link BlockUCState#COMMITTED}.\n   * @param block - contains client reported block length and generation\n   * @return staleReplica's List.\n   * @throws IOException if block ids are inconsistent.\n   */\n  List<ReplicaUnderConstruction> commitBlock(Block block) throws IOException {\n    if (getBlockId() != block.getBlockId()) {\n      throw new IOException(\"Trying to commit inconsistent block: id = \"\n          + block.getBlockId() + \", expected id = \" + getBlockId());\n    }\n    Preconditions.checkState(!isComplete());\n    uc.commit();\n    this.setNumBytes(block.getNumBytes());\n    // Sort out invalid replicas.\n    return setGenerationStampAndVerifyReplicas(block.getGenerationStamp());\n  }\n}\n","sourceCodeStart":426,"sourceCodeEnd":454,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfo.java#L426-L454","documentation":"BlockInfo.commitBlock is invoked by the NameNode when a client commits the last block of a file (close/append completion): the client-reported Block must carry the same block ID as the stored under-construction BlockInfo. A mismatch throws IOException('Trying to commit inconsistent block: id = X, expected id = Y') before any metadata is mutated. This is a fail-fast integrity guard against NameNode namespace/block state divergence - essentially never expected on a healthy cluster.","triggerScenarios":"Lease recovery, append or file-close paths where the stored BlockUC block ID differs from what the client reports - caused by NameNode bugs, corrupted/inconsistent edit logs or fsimage, downgrade/upgrade edge cases, or races between multiple writers and recovery.","commonSituations":"Rare; seen around HDFS bug reports involving lease recovery races or block-recovery replay. If it recurs for the same file, the file's block metadata is suspect. Not caused by user configuration.","solutions":["Capture the NameNode log around the throw (file path, block id, expected id) and retry the client operation - many one-off occurrences are benign recovery races","Run hdfs fsck on the affected file/path to check block consistency","If persistent, search/report an HDFS JIRA with the log excerpt and stack; the file may need to be deleted or recovered from backup, since this signals namespace-level inconsistency"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { fs.close(); / fs.append(...) }\ncatch (IOException e) {\n  if (e.getMessage().startsWith(\"Trying to commit inconsistent block\")) { captureNNLog(); runFsck(path); reportToCommunity(e); }\n  throw e;\n}","preventionTips":["Keep NameNodes on patched releases - occurrences of this error usually map to fixed lease-recovery bugs","Never force-start a NameNode on inconsistent edits/images; keep reliable checkpoints/fsimage backups","On first occurrence, capture the block/file IDs and hdfs fsck output before retrying writes to that file"],"tags":["hdfs","namenode","block-management","data-integrity","lease-recovery"],"backgroundTag":"metadata-consistency-error","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}