{"record":{"id":"b6a4ac84d673e1e5","repo":"apache/hadoop","slug":"recorded-block-size-is-but-datanode-returned","errorCode":null,"errorMessage":"Recorded block size is {}, but datanode returned {} bytes","messagePattern":"Recorded block size is (.+?), but datanode returned (.+?) bytes","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java","lineNumber":1149,"sourceCode":"      }  catch (IOException ex) {\n        // Put chosen node into dead list, continue\n        LOG.info(\"Failed to connect to \" + targetAddr + \":\" + ex);\n        deadNodes.add(chosenNode);\n      }\n    }\n\n    long bytesRead = 0L;\n    try {\n      bytesRead = copyBock(blockReader, fos);\n    } catch (Exception e) {\n      throw new Exception(\"Could not copy block data for \" + lblock.getBlock(),\n          e);\n    } finally {\n      blockReader.close();\n    }\n\n    if (bytesRead != block.getNumBytes()) {\n      throw new IOException(\"Recorded block size is \" + block.getNumBytes()\n          + \", but datanode returned \" + bytesRead + \" bytes\");\n    }\n  }\n\n  private long copyBock(BlockReader blockReader, OutputStream os)\n      throws IOException {\n    final byte[] buf = new byte[8192];\n    int cnt = 0;\n    long bytesRead = 0L;\n    while ((cnt = blockReader.read(buf, 0, buf.length)) > 0) {\n      os.write(buf, 0, cnt);\n      bytesRead += cnt;\n    }\n    return bytesRead;\n  }\n\n  @Override\n  public DataEncryptionKey newDataEncryptionKey() throws IOException {","sourceCodeStart":1131,"sourceCodeEnd":1167,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java#L1131-L1167","documentation":"Error \"Recorded block size is {}, but datanode returned {} bytes\" thrown in apache/hadoop.","triggerScenarios":"A DataNode returns a byte count different from the block size recorded in the NameNode metadata.","commonSituations":"Disk corruption, truncated blocks, or mixed-version metadata after an unclean shutdown.","solutions":["Investigate the DataNode serving the mismatched size; the block may be corrupt — consider recovering or deleting the file."],"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"}