org.apache.hadoop.hbase.io.hfile
Class HFileBlockIndex.BlockIndexReader

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.HFileBlockIndex.BlockIndexReader
All Implemented Interfaces:
HeapSize
Enclosing class:
HFileBlockIndex

public static class HFileBlockIndex.BlockIndexReader
extends java.lang.Object
implements HeapSize

The reader will always hold the root level index in the memory. Index blocks at all other levels will be cached in the LRU cache in practice, although this API does not enforce that. All non-root (leaf and intermediate) index blocks contain what we call a "secondary index": an array of offsets to the entries within the block. This allows us to do binary search for the entry corresponding to the given key without having to deserialize the block.


Constructor Summary
HFileBlockIndex.BlockIndexReader(org.apache.hadoop.io.RawComparator<byte[]> c, int treeLevel)
           
HFileBlockIndex.BlockIndexReader(org.apache.hadoop.io.RawComparator<byte[]> c, int treeLevel, HFile.CachingBlockReader cachingBlockReader)
           
 
Method Summary
 void ensureNonEmpty()
          Verifies that the block index is non-empty and throws an IllegalStateException otherwise.
 int getRootBlockCount()
           
 int getRootBlockDataSize(int i)
           
 byte[] getRootBlockKey(int i)
           
 long getRootBlockOffset(int i)
           
 long heapSize()
           
 boolean isEmpty()
           
 BlockWithScanInfo loadDataBlockWithScanInfo(byte[] key, int keyOffset, int keyLength, HFileBlock currentBlock, boolean cacheBlocks, boolean pread, boolean isCompaction)
          Return the BlockWithScanInfo which contains the DataBlock with other scan info such as nextIndexedKey.
 byte[] midkey()
          An approximation to the HFile's mid-key.
 void readMultiLevelIndexRoot(HFileBlock blk, int numEntries)
          Read the root-level metadata of a multi-level block index.
 void readRootIndex(java.io.DataInput in, int numEntries)
          Read in the root-level index from the given input stream.
 java.io.DataInputStream readRootIndex(HFileBlock blk, int numEntries)
          Read in the root-level index from the given input stream.
 int rootBlockContainingKey(byte[] key, int offset, int length)
          Finds the root-level index block containing the given key.
 HFileBlock seekToDataBlock(byte[] key, int keyOffset, int keyLength, HFileBlock currentBlock, boolean cacheBlocks, boolean pread, boolean isCompaction)
          Return the data block which contains this key.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HFileBlockIndex.BlockIndexReader

public HFileBlockIndex.BlockIndexReader(org.apache.hadoop.io.RawComparator<byte[]> c,
                                        int treeLevel,
                                        HFile.CachingBlockReader cachingBlockReader)

HFileBlockIndex.BlockIndexReader

public HFileBlockIndex.BlockIndexReader(org.apache.hadoop.io.RawComparator<byte[]> c,
                                        int treeLevel)
Method Detail

isEmpty

public boolean isEmpty()
Returns:
true if the block index is empty.

ensureNonEmpty

public void ensureNonEmpty()
Verifies that the block index is non-empty and throws an IllegalStateException otherwise.


seekToDataBlock

public HFileBlock seekToDataBlock(byte[] key,
                                  int keyOffset,
                                  int keyLength,
                                  HFileBlock currentBlock,
                                  boolean cacheBlocks,
                                  boolean pread,
                                  boolean isCompaction)
                           throws java.io.IOException
Return the data block which contains this key. This function will only be called when the HFile version is larger than 1.

Parameters:
key - the key we are looking for
keyOffset - the offset of the key in its byte array
keyLength - the length of the key
currentBlock - the current block, to avoid re-reading the same block
Returns:
reader a basic way to load blocks
Throws:
java.io.IOException

loadDataBlockWithScanInfo

public BlockWithScanInfo loadDataBlockWithScanInfo(byte[] key,
                                                   int keyOffset,
                                                   int keyLength,
                                                   HFileBlock currentBlock,
                                                   boolean cacheBlocks,
                                                   boolean pread,
                                                   boolean isCompaction)
                                            throws java.io.IOException
Return the BlockWithScanInfo which contains the DataBlock with other scan info such as nextIndexedKey. This function will only be called when the HFile version is larger than 1.

Parameters:
key - the key we are looking for
keyOffset - the offset of the key in its byte array
keyLength - the length of the key
currentBlock - the current block, to avoid re-reading the same block
cacheBlocks -
pread -
isCompaction -
Returns:
the BlockWithScanInfo which contains the DataBlock with other scan info such as nextIndexedKey.
Throws:
java.io.IOException

midkey

public byte[] midkey()
              throws java.io.IOException
An approximation to the HFile's mid-key. Operates on block boundaries, and does not go inside blocks. In other words, returns the first key of the middle block of the file.

Returns:
the first key of the middle block
Throws:
java.io.IOException

getRootBlockKey

public byte[] getRootBlockKey(int i)
Parameters:
i - from 0 to - 1

getRootBlockOffset

public long getRootBlockOffset(int i)
Parameters:
i - from 0 to - 1

getRootBlockDataSize

public int getRootBlockDataSize(int i)
Parameters:
i - zero-based index of a root-level block
Returns:
the on-disk size of the root-level block for version 2, or the uncompressed size for version 1

getRootBlockCount

public int getRootBlockCount()
Returns:
the number of root-level blocks in this block index

rootBlockContainingKey

public int rootBlockContainingKey(byte[] key,
                                  int offset,
                                  int length)
Finds the root-level index block containing the given key.

Parameters:
key - Key to find
Returns:
Offset of block containing key (between 0 and the number of blocks - 1) or -1 if this file does not contain the request.

readRootIndex

public void readRootIndex(java.io.DataInput in,
                          int numEntries)
                   throws java.io.IOException
Read in the root-level index from the given input stream. Must match what was written into the root level by HFileBlockIndex.BlockIndexWriter.writeIndexBlocks(FSDataOutputStream) at the offset that function returned.

Parameters:
in - the buffered input stream or wrapped byte input stream
numEntries - the number of root-level index entries
Throws:
java.io.IOException

readRootIndex

public java.io.DataInputStream readRootIndex(HFileBlock blk,
                                             int numEntries)
                                      throws java.io.IOException
Read in the root-level index from the given input stream. Must match what was written into the root level by HFileBlockIndex.BlockIndexWriter.writeIndexBlocks(FSDataOutputStream) at the offset that function returned.

Parameters:
blk - the HFile block
numEntries - the number of root-level index entries
Returns:
the buffered input stream or wrapped byte input stream
Throws:
java.io.IOException

readMultiLevelIndexRoot

public void readMultiLevelIndexRoot(HFileBlock blk,
                                    int numEntries)
                             throws java.io.IOException
Read the root-level metadata of a multi-level block index. Based on readRootIndex(DataInput, int), but also reads metadata necessary to compute the mid-key in a multi-level index.

Parameters:
blk - the HFile block
numEntries - the number of root-level index entries
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

heapSize

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


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