Class BlockMetadataHeader
java.lang.Object
org.apache.hadoop.hdfs.server.datanode.BlockMetadataHeader
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBlockMetadataHeader(short version, org.apache.hadoop.util.DataChecksum checksum) -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.hadoop.util.DataChecksumGet the checksumstatic intReturns the size of the headershortGet the versionstatic BlockMetadataHeaderRead the header without changing the position of the FileChannel.static org.apache.hadoop.util.DataChecksumreadDataChecksum(DataInputStream metaIn, Object name) Read the checksum header from the meta input stream.static org.apache.hadoop.util.DataChecksumreadDataChecksum(FileInputStream inputStream, int bufSize, File metaFile) Read the checksum header from the meta file.static BlockMetadataHeaderThis reads all the fields till the beginning of checksum.static BlockMetadataHeaderReads header at the top of metadata file and returns the header.static BlockMetadataHeaderRead the header at the beginning of the given block meta file.static voidwriteHeader(DataOutputStream out, BlockMetadataHeader header) This writes all the fields till the beginning of checksum.static voidwriteHeader(DataOutputStream out, org.apache.hadoop.util.DataChecksum checksum) Writes all the fields till the beginning of checksum.
-
Field Details
-
VERSION
public static final short VERSION- See Also:
-
-
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
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
This reads all the fields till the beginning of checksum.- Returns:
- Metadata Header
- Throws:
IOException
-
readHeader
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
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
-