{"record":{"id":"f9642d83ecc80abb","repo":"apache/hadoop","slug":"eof-while-reading-header-from-the-metadata-file-t","errorCode":null,"errorMessage":"EOF while reading header from the metadata file. The meta file may be truncated or corrupt","messagePattern":"EOF while reading header from the metadata file\\. The meta file may be truncated or corrupt","errorType":"exception","errorClass":"CorruptMetaHeaderException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockMetadataHeader.java","lineNumber":124,"sourceCode":"    return header.getChecksum();\n  }\n\n  /**\n   * Read the header without changing the position of the FileChannel.\n   * This is used by the client for short-circuit reads.\n   *\n   * @param fc The FileChannel to read.\n   * @return the Metadata Header.\n   * @throws IOException on error.\n   */\n  public static BlockMetadataHeader preadHeader(FileChannel fc)\n      throws IOException {\n    final byte arr[] = new byte[getHeaderSize()];\n    ByteBuffer buf = ByteBuffer.wrap(arr);\n\n    while (buf.hasRemaining()) {\n      if (fc.read(buf, buf.position()) <= 0) {\n        throw new CorruptMetaHeaderException(\"EOF while reading header from \"+\n            \"the metadata file. The meta file may be truncated or corrupt\");\n      }\n    }\n    short version = (short)((arr[0] << 8) | (arr[1] & 0xff));\n    DataChecksum dataChecksum;\n    try {\n      dataChecksum = DataChecksum.newDataChecksum(arr, 2);\n    } catch (InvalidChecksumSizeException e) {\n      throw new CorruptMetaHeaderException(\"The block meta file header is \"+\n          \"corrupt\", e);\n    }\n    return new BlockMetadataHeader(version, dataChecksum);\n  }\n\n  /**\n   * This reads all the fields till the beginning of checksum.\n   * @return Metadata Header\n   * @throws IOException","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockMetadataHeader.java#L106-L142","documentation":"BlockMetadataHeader.preadHeader reads the fixed-size meta header (version + checksum descriptor) from a block .meta file via FileChannel. A read() returning <= 0 while header bytes remain means the file is shorter than getHeaderSize() - truncated or empty. The CorruptMetaHeaderException marks the replica metadata unusable for serving or verification.","triggerScenarios":"A DataNode or tooling path opens a .meta file whose length is below the header size: crash before the header was flushed, disk full during block creation, or a zero-length file left behind after kill -9.","commonSituations":"DN crash or reboot mid-write; full data disks; interrupted block moves/copies; bit rot on metadata volumes.","solutions":["Run 'hdfs fsck /' to locate corrupt/missing replicas and identify the affected block and files","Delete the affected block/meta pair (or its block subdirectory) so the NameNode schedules re-replication from other replicas","Fix the root cause: free disk space, stop the crash/hardware errors","If no other replica exists, restore from backup - the data is unrecoverable without a valid meta header"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Path meta = blockMetaPath(blockId);\nif (Files.size(meta) < BlockMetadataHeader.getHeaderSize()) {\n  // truncated/empty header: quarantine before attempting preadHeader\n  quarantine(meta);\n}","typeGuard":null,"tryCatchPattern":"catch (CorruptMetaHeaderException e) { deleteBlockAndMeta(block); requestReReplication(block); }","preventionTips":["Monitor disk full conditions and DN crash rates - the usual root causes","Run hdfs fsck periodically to catch corrupt replicas early"],"tags":["hdfs","datanode","block-metadata","corruption","disk"],"backgroundTag":"corrupt-block-metadata","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}