@InterfaceAudience.Private public class HFileBlock extends Object implements Cacheable
HFile
version 1 and 2 blocks, and writing version 2 blocks.
HFile
's compression algorithm, with a type-specific
magic record stored in the beginning of the compressed data (i.e. one needs
to uncompress the compressed block to determine the block type). There is
only a single compression algorithm setting for all blocks. Offset and size
information from the block index are required to read a block.
HFile
, similarly to what was done in
version 1.
Modifier and Type | Class and Description |
---|---|
static interface |
HFileBlock.BlockIterator
An interface allowing to iterate
HFileBlock s. |
static interface |
HFileBlock.BlockWritable
Something that can be written into a block.
|
static interface |
HFileBlock.FSReader
A full-fledged reader with iteration ability.
|
static class |
HFileBlock.Writer
Unified version 2
HFile block writer. |
Modifier and Type | Field and Description |
---|---|
static int |
BYTE_BUFFER_HEAP_SIZE |
static boolean |
DONT_FILL_HEADER |
static int |
ENCODED_HEADER_SIZE
The size of block header when blockType is
BlockType.ENCODED_DATA . |
static int |
EXTRA_SERIALIZATION_SPACE |
static boolean |
FILL_HEADER |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object comparison) |
void |
expectType(BlockType expectedType) |
BlockType |
getBlockType() |
ByteBuffer |
getBufferReadOnly()
Returns the buffer this block stores internally.
|
ByteBuffer |
getBufferReadOnlyWithHeader()
Returns the buffer of this block, including header data.
|
ByteBuffer |
getBufferWithoutHeader()
Returns a buffer that does not include the header or checksum.
|
DataInputStream |
getByteStream() |
DataBlockEncoding |
getDataBlockEncoding() |
short |
getDataBlockEncodingId() |
CacheableDeserializer<Cacheable> |
getDeserializer()
Returns CacheableDeserializer instance which reconstructs original object from ByteBuffer.
|
byte[] |
getDummyHeaderForVersion()
Return the appropriate DUMMY_HEADER for the minor version
|
HFileContext |
getHFileContext() |
int |
getNextBlockOnDiskSizeWithHeader() |
long |
getOffset() |
int |
getOnDiskSizeWithHeader() |
int |
getOnDiskSizeWithoutHeader() |
long |
getPrevBlockOffset() |
int |
getSerializedLength()
Returns the length of the ByteBuffer required to serialized the object.
|
int |
getUncompressedSizeWithoutHeader() |
int |
headerSize()
Returns the size of this block header.
|
static int |
headerSize(boolean usesHBaseChecksum)
Maps a minor version to the size of the header.
|
long |
heapSize() |
boolean |
isUnpacked()
Return true when this block's buffer has been unpacked, false otherwise.
|
static boolean |
readWithExtra(InputStream in,
byte[] buf,
int bufOffset,
int necessaryLen,
int extraLen)
Read from an input stream.
|
void |
serialize(ByteBuffer destination)
Serializes its data into destination.
|
void |
serializeExtraInfo(ByteBuffer destination) |
String |
toString() |
static String |
toStringHeader(ByteBuffer buf)
Convert the contents of the block header into a human readable string.
|
static void |
verifyUncompressed(ByteBuffer buf,
boolean useHBaseChecksum)
An additional sanity-check in case no compression or encryption is being used.
|
public static final boolean FILL_HEADER
public static final boolean DONT_FILL_HEADER
public static final int ENCODED_HEADER_SIZE
BlockType.ENCODED_DATA
.
This extends normal header by adding the id of encoder.public static final int BYTE_BUFFER_HEAP_SIZE
public static final int EXTRA_SERIALIZATION_SPACE
public BlockType getBlockType()
getBlockType
in interface Cacheable
public short getDataBlockEncodingId()
public int getOnDiskSizeWithHeader()
public int getOnDiskSizeWithoutHeader()
public int getUncompressedSizeWithoutHeader()
public long getPrevBlockOffset()
public ByteBuffer getBufferWithoutHeader()
public ByteBuffer getBufferReadOnly()
CompoundBloomFilter
to avoid object creation on every Bloom filter lookup, but has to
be used with caution. Checksum data is not included in the returned
buffer but header data is.public ByteBuffer getBufferReadOnlyWithHeader()
BucketCache
to avoid buffer copy.public boolean isUnpacked()
public static void verifyUncompressed(ByteBuffer buf, boolean useHBaseChecksum) throws IOException
IOException
public void expectType(BlockType expectedType) throws IOException
expectedType
- the expected type of this blockIOException
- if this block's type is different than expectedpublic long getOffset()
public DataInputStream getByteStream()
public long heapSize()
public static boolean readWithExtra(InputStream in, byte[] buf, int bufOffset, int necessaryLen, int extraLen) throws IOException
IOUtils.readFully(InputStream, byte[], int, int)
, but specifies a
number of "extra" bytes that would be desirable but not absolutely
necessary to read.in
- the input stream to read frombuf
- the buffer to read intobufOffset
- the destination offset in the buffernecessaryLen
- the number of bytes that are absolutely necessary to
readextraLen
- the number of extra bytes that would be nice to readIOException
- if failed to read the necessary bytespublic int getNextBlockOnDiskSizeWithHeader()
public int getSerializedLength()
Cacheable
getSerializedLength
in interface Cacheable
public void serialize(ByteBuffer destination)
Cacheable
public void serializeExtraInfo(ByteBuffer destination)
public CacheableDeserializer<Cacheable> getDeserializer()
Cacheable
getDeserializer
in interface Cacheable
public DataBlockEncoding getDataBlockEncoding()
public int headerSize()
public static int headerSize(boolean usesHBaseChecksum)
public byte[] getDummyHeaderForVersion()
public HFileContext getHFileContext()
public static String toStringHeader(ByteBuffer buf) throws IOException
IOException
Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.