{"record":{"id":"788afae348357949","repo":"apache/hadoop","slug":"eof-while-reading-header-from-meta-the-meta-file","errorCode":null,"errorMessage":"EOF while reading header from meta. The meta file may be truncated or corrupt","messagePattern":"EOF while reading header from meta\\. 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":151,"sourceCode":"      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\n   */\n  public static BlockMetadataHeader readHeader(DataInputStream in)\n      throws IOException {\n    try {\n      return readHeader(in.readShort(), in);\n    } catch (EOFException eof) {\n      // The attempt to read the header threw EOF, indicating there are not\n      // enough bytes in the meta file for the header.\n      throw new CorruptMetaHeaderException(\"EOF while reading header from meta\"+\n          \". The meta file may be truncated or corrupt\", eof);\n    }\n  }\n\n  /**\n   * Reads header at the top of metadata file and returns the header.\n   * Closes the input stream after reading the header.\n   *\n   * @return metadata header for the block\n   * @throws IOException\n   */\n  public static BlockMetadataHeader readHeader(\n      FileInputStream fis) throws IOException {\n    try (DataInputStream in = new DataInputStream(\n        new BufferedInputStream(fis))) {\n      return readHeader(in);\n    }\n  }","sourceCodeStart":133,"sourceCodeEnd":169,"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#L133-L169","documentation":"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.","triggerScenarios":"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.","commonSituations":"Empty .meta files left after kill -9, disk-full writes, or truncated files copied across volumes.","solutions":["Check the file size of the reported .meta - anything below the header size (version short + checksum header) is unrecoverable","Delete the block/meta pair and let the NameNode re-replicate","Fix the crash/disk-full condition that produced the truncated file"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (fileLength(metaFile) < BlockMetadataHeader.getHeaderSize()) {\n  // too short even for version+checksum header: skip readHeader, quarantine\n  quarantine(metaFile);\n}","typeGuard":null,"tryCatchPattern":"catch (CorruptMetaHeaderException e) { /* truncated meta: delete pair, re-replicate */ }","preventionTips":["Check file length before parsing meta headers in custom tooling","Avoid leaving partial .meta files: shut down DataNodes cleanly before maintenance"],"tags":["hdfs","datanode","block-metadata","truncated-file","eof"],"backgroundTag":"corrupt-block-metadata","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}