org.apache.hadoop.hbase.io.hfile
Class HFileBlock

java.lang.Object
  extended by org.apache.hadoop.hbase.regionserver.metrics.SchemaConfigured
      extended by org.apache.hadoop.hbase.io.hfile.HFileBlock
All Implemented Interfaces:
HeapSize, Cacheable, SchemaMetrics.SchemaAware

public class HFileBlock
extends SchemaConfigured
implements Cacheable

Reading HFile version 1 and 2 blocks, and writing version 2 blocks.

The version 2 block representation in the block cache is the same as above, except that the data section is always uncompressed in the cache.


Nested Class Summary
static interface HFileBlock.BlockIterator
          An interface allowing to iterate HFileBlocks.
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.
 
Field Summary
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 boolean FILL_HEADER
           
 
Fields inherited from class org.apache.hadoop.hbase.regionserver.metrics.SchemaConfigured
SCHEMA_CONFIGURED_UNALIGNED_HEAP_SIZE
 
Method Summary
 void assumeUncompressed()
          An additional sanity-check in case no compression is being used.
 boolean doesIncludeMemstoreTS()
           
 boolean equals(Object comparison)
           
 void expectType(BlockType expectedType)
           
 BlockType getBlockType()
           
 ByteBuffer getBufferReadOnly()
          Returns the buffer this block stores internally.
 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_WITH_CHECKSUM for the minor version
 int getNextBlockOnDiskSizeWithHeader()
           
 long getOffset()
           
 int getOnDiskSizeWithHeader()
           
 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.
 long heapSize()
           
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.
 String toString()
           
 
Methods inherited from class org.apache.hadoop.hbase.regionserver.metrics.SchemaConfigured
createUnknown, getColumnFamilyName, getSchemaMetrics, getTableName, isSchemaConfigured, passSchemaMetricsTo, resetSchemaMetricsConf, schemaConfAsJSON, schemaConfigurationChanged
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.hadoop.hbase.io.hfile.Cacheable
getSchemaMetrics
 

Field Detail

FILL_HEADER

public static final boolean FILL_HEADER
See Also:
Constant Field Values

DONT_FILL_HEADER

public static final boolean DONT_FILL_HEADER
See Also:
Constant Field Values

ENCODED_HEADER_SIZE

public static final int ENCODED_HEADER_SIZE
The size of block header when blockType is BlockType.ENCODED_DATA. This extends normal header by adding the id of encoder.

See Also:
Constant Field Values

BYTE_BUFFER_HEAP_SIZE

public static final int BYTE_BUFFER_HEAP_SIZE
Method Detail

getBlockType

public BlockType getBlockType()
Specified by:
getBlockType in interface Cacheable
Returns:
the block type of this cached HFile block

getDataBlockEncodingId

public short getDataBlockEncodingId()
Returns:
get data block encoding id that was used to encode this block

getOnDiskSizeWithHeader

public int getOnDiskSizeWithHeader()
Returns:
the on-disk size of the block with header size included. This includes the header, the data and the checksum data.

getUncompressedSizeWithoutHeader

public int getUncompressedSizeWithoutHeader()
Returns:
the uncompressed size of the data part of the block, header not included

getPrevBlockOffset

public long getPrevBlockOffset()
Returns:
the offset of the previous block of the same type in the file, or -1 if unknown

getBufferReadOnly

public ByteBuffer getBufferReadOnly()
Returns the buffer this block stores internally. The clients must not modify the buffer object. This method has to be public because it is used in 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.

Returns:
the buffer of this block for read-only operations

toString

public String toString()
Overrides:
toString in class Object

assumeUncompressed

public void assumeUncompressed()
                        throws IOException
An additional sanity-check in case no compression is being used.

Throws:
IOException

expectType

public void expectType(BlockType expectedType)
                throws IOException
Parameters:
expectedType - the expected type of this block
Throws:
IOException - if this block's type is different than expected

getOffset

public long getOffset()
Returns:
the offset of this block in the file it was read from

getByteStream

public DataInputStream getByteStream()
Returns:
a byte stream reading the data section of this block

heapSize

public long heapSize()
Specified by:
heapSize in interface HeapSize
Overrides:
heapSize in class SchemaConfigured
Returns:
Approximate 'exclusive deep size' of implementing object. Includes count of payload and hosting object sizings.

readWithExtra

public static boolean readWithExtra(InputStream in,
                                    byte[] buf,
                                    int bufOffset,
                                    int necessaryLen,
                                    int extraLen)
                             throws IOException
Read from an input stream. Analogous to IOUtils.readFully(InputStream, byte[], int, int), but specifies a number of "extra" bytes that would be desirable but not absolutely necessary to read.

Parameters:
in - the input stream to read from
buf - the buffer to read into
bufOffset - the destination offset in the buffer
necessaryLen - the number of bytes that are absolutely necessary to read
extraLen - the number of extra bytes that would be nice to read
Returns:
true if succeeded reading the extra bytes
Throws:
IOException - if failed to read the necessary bytes

getNextBlockOnDiskSizeWithHeader

public int getNextBlockOnDiskSizeWithHeader()
Returns:
the on-disk size of the next block (including the header size) that was read by peeking into the next block's header

getSerializedLength

public int getSerializedLength()
Description copied from interface: Cacheable
Returns the length of the ByteBuffer required to serialized the object. If the object cannot be serialized, it should also return 0.

Specified by:
getSerializedLength in interface Cacheable
Returns:
int length in bytes of the serialized form.

serialize

public void serialize(ByteBuffer destination)
Description copied from interface: Cacheable
Serializes its data into destination.

Specified by:
serialize in interface Cacheable

getDeserializer

public CacheableDeserializer<Cacheable> getDeserializer()
Description copied from interface: Cacheable
Returns CacheableDeserializer instance which reconstructs original object from ByteBuffer.

Specified by:
getDeserializer in interface Cacheable
Returns:
CacheableDeserialzer instance.

equals

public boolean equals(Object comparison)
Overrides:
equals in class Object

doesIncludeMemstoreTS

public boolean doesIncludeMemstoreTS()

getDataBlockEncoding

public DataBlockEncoding getDataBlockEncoding()

headerSize

public int headerSize()
Returns the size of this block header.


getDummyHeaderForVersion

public byte[] getDummyHeaderForVersion()
Return the appropriate DUMMY_HEADER_WITH_CHECKSUM for the minor version



Copyright © 2014 The Apache Software Foundation. All Rights Reserved.