apache/hadoop · error · CorruptMetaHeaderException

EOF while reading header from meta. The meta file may be tru

Error message

EOF while reading header from meta. The meta file may be truncated or corrupt

What it means

The stream-based BlockMetadataHeader.readHeader(DataInputStream) caught an EOFException while reading the version short (or checksum fields): the meta file holds fewer bytes than the minimal header. The EOFException is wrapped in CorruptMetaHeaderException so callers treat the replica metadata as unusable rather than a plain stream error.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockMetadataHeader.java:151

      throw new CorruptMetaHeaderException("The block meta file header is "+
          "corrupt", e);
    }
    return new BlockMetadataHeader(version, dataChecksum);
  }

  /**
   * This reads all the fields till the beginning of checksum.
   * @return Metadata Header
   * @throws IOException
   */
  public static BlockMetadataHeader readHeader(DataInputStream in)
      throws IOException {
    try {
      return readHeader(in.readShort(), in);
    } catch (EOFException eof) {
      // The attempt to read the header threw EOF, indicating there are not
      // enough bytes in the meta file for the header.
      throw new CorruptMetaHeaderException("EOF while reading header from meta"+
          ". The meta file may be truncated or corrupt", eof);
    }
  }

  /**
   * Reads header at the top of metadata file and returns the header.
   * Closes the input stream after reading the header.
   *
   * @return metadata header for the block
   * @throws IOException
   */
  public static BlockMetadataHeader readHeader(
      FileInputStream fis) throws IOException {
    try (DataInputStream in = new DataInputStream(
        new BufferedInputStream(fis))) {
      return readHeader(in);
    }
  }

View on GitHub (pinned to 2add963021)

Solutions

  1. Check the file size of the reported .meta - anything below the header size (version short + checksum header) is unrecoverable
  2. Delete the block/meta pair and let the NameNode re-replicate
  3. Fix the crash/disk-full condition that produced the truncated file
Defensive patterns

Strategy: validation

Validate before calling

if (fileLength(metaFile) < BlockMetadataHeader.getHeaderSize()) {
  // too short even for version+checksum header: skip readHeader, quarantine
  quarantine(metaFile);
}

Try / catch

catch (CorruptMetaHeaderException e) { /* truncated meta: delete pair, re-replicate */ }

Prevention

When it happens

Trigger: readHeader(DataInputStream) is called on a 0- or 1-byte .meta file - e.g. by DataNode verification paths or tools that scan replica metadata after a crash or disk-full event.

Common situations: Empty .meta files left after kill -9, disk-full writes, or truncated files copied across volumes.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/788afae348357949. Report an issue: GitHub.