@InterfaceAudience.Private public class ChecksumUtil extends Object
Modifier and Type | Field and Description |
---|---|
private static byte[] |
DUMMY_VALUE
This is used to reserve space in a byte buffer
|
private static boolean |
generateExceptions
This is used by unit tests to make checksum failures throw an
exception instead of returning null.
|
static org.slf4j.Logger |
LOG |
Constructor and Description |
---|
ChecksumUtil() |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
generateChecksums(byte[] indata,
int startOffset,
int endOffset,
byte[] outdata,
int outOffset,
ChecksumType checksumType,
int bytesPerChecksum)
Generates a checksum for all the data in indata.
|
static void |
generateExceptionForChecksumFailureForTest(boolean value)
Mechanism to throw an exception in case of hbase checksum
failure.
|
(package private) static long |
numBytes(long datasize,
int bytesPerChecksum)
Returns the number of bytes needed to store the checksums for
a specified data size
|
(package private) static long |
numChunks(long datasize,
int bytesPerChecksum)
Returns the number of checksum chunks needed to store the checksums for
a specified data size
|
(package private) static void |
reserveSpaceForChecksums(ByteArrayOutputStream baos,
int numBytes,
int bytesPerChecksum)
Write dummy checksums to the end of the specified bytes array
to reserve space for writing checksums later
|
(package private) static boolean |
validateChecksum(ByteBuffer buffer,
String pathName,
long offset,
int hdrSize)
Validates that the data in the specified HFileBlock matches the checksum.
|
public static final org.slf4j.Logger LOG
private static byte[] DUMMY_VALUE
private static boolean generateExceptions
public ChecksumUtil()
static void generateChecksums(byte[] indata, int startOffset, int endOffset, byte[] outdata, int outOffset, ChecksumType checksumType, int bytesPerChecksum) throws IOException
indata
- input data streamstartOffset
- starting offset in the indata stream from where to
compute checkums fromendOffset
- ending offset in the indata stream upto
which checksums needs to be computedoutdata
- the output buffer where checksum values are writtenoutOffset
- the starting offset in the outdata where the
checksum values are writtenchecksumType
- type of checksumbytesPerChecksum
- number of bytes per checksum valueIOException
static boolean validateChecksum(ByteBuffer buffer, String pathName, long offset, int hdrSize) throws IOException
buffer
- Contains the data in following order: HFileBlock header, data, checksums.pathName
- Path of the HFile to which the data
belongs. Only used for logging.offset
- offset of the data being validated. Only used for logging.hdrSize
- Size of the block header in data
. Only used for logging.IOException
static long numBytes(long datasize, int bytesPerChecksum)
datasize
- number of bytes of databytesPerChecksum
- number of bytes in a checksum chunkstatic long numChunks(long datasize, int bytesPerChecksum)
datasize
- number of bytes of databytesPerChecksum
- number of bytes in a checksum chunkstatic void reserveSpaceForChecksums(ByteArrayOutputStream baos, int numBytes, int bytesPerChecksum) throws IOException
baos
- OutputStream to write dummy checkum valuesnumBytes
- Number of bytes of data for which dummy checksums
need to be generatedbytesPerChecksum
- Number of bytes per checksum valueIOException
public static void generateExceptionForChecksumFailureForTest(boolean value)
value
- Setting this to true will cause hbase checksum
verification failures to generate exceptions.Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.