Class BlockMetadataHeader

java.lang.Object
org.apache.hadoop.hdfs.server.datanode.BlockMetadataHeader

@Private @Evolving public class BlockMetadataHeader extends Object
BlockMetadataHeader manages metadata for data blocks on Datanodes. This is not related to the Block related functionality in Namenode. The biggest part of data block metadata is CRC for the block.
  • Field Details

  • Constructor Details

    • BlockMetadataHeader

      @VisibleForTesting public BlockMetadataHeader(short version, org.apache.hadoop.util.DataChecksum checksum)
  • Method Details

    • getVersion

      public short getVersion()
      Get the version
    • getChecksum

      public org.apache.hadoop.util.DataChecksum getChecksum()
      Get the checksum
    • readDataChecksum

      public static org.apache.hadoop.util.DataChecksum readDataChecksum(FileInputStream inputStream, int bufSize, File metaFile) throws IOException
      Read the checksum header from the meta file. inputStream must be closed by the caller.
      Returns:
      the data checksum obtained from the header.
      Throws:
      IOException
    • readDataChecksum

      public static org.apache.hadoop.util.DataChecksum readDataChecksum(DataInputStream metaIn, Object name) throws IOException
      Read the checksum header from the meta input stream.
      Returns:
      the data checksum obtained from the header.
      Throws:
      IOException
    • preadHeader

      public static BlockMetadataHeader preadHeader(FileChannel fc) throws IOException
      Read the header without changing the position of the FileChannel. This is used by the client for short-circuit reads.
      Parameters:
      fc - The FileChannel to read.
      Returns:
      the Metadata Header.
      Throws:
      IOException - on error.
    • readHeader

      public static BlockMetadataHeader readHeader(DataInputStream in) throws IOException
      This reads all the fields till the beginning of checksum.
      Returns:
      Metadata Header
      Throws:
      IOException
    • readHeader

      public static BlockMetadataHeader readHeader(FileInputStream fis) throws IOException
      Reads header at the top of metadata file and returns the header. Closes the input stream after reading the header.
      Returns:
      metadata header for the block
      Throws:
      IOException
    • readHeader

      public static BlockMetadataHeader readHeader(RandomAccessFile raf) throws IOException
      Read the header at the beginning of the given block meta file. The current file position will be altered by this method. If an error occurs, the file is not closed.
      Throws:
      IOException
    • writeHeader

      @VisibleForTesting public static void writeHeader(DataOutputStream out, BlockMetadataHeader header) throws IOException
      This writes all the fields till the beginning of checksum.
      Parameters:
      out - DataOutputStream
      Throws:
      IOException
    • writeHeader

      public static void writeHeader(DataOutputStream out, org.apache.hadoop.util.DataChecksum checksum) throws IOException
      Writes all the fields till the beginning of checksum.
      Throws:
      IOException - on error
    • getHeaderSize

      public static int getHeaderSize()
      Returns the size of the header