abstract static class HFileBlockIndex.BlockIndexReader extends Object implements HeapSize
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.
| Modifier and Type | Field and Description | 
|---|---|
| protected int[] | blockDataSizes | 
| protected long[] | blockOffsets | 
| protected int | midKeyEntry | 
| protected long | midLeafBlockOffset | 
| protected int | midLeafBlockOnDiskSize | 
| protected int | rootCount | 
| protected int | searchTreeLevelThe number of levels in the block index tree. | 
| Constructor and Description | 
|---|
| BlockIndexReader() | 
| Modifier and Type | Method and Description | 
|---|---|
| protected abstract void | add(byte[] key,
   long offset,
   int dataSize) | 
| (package private) static int | binarySearchNonRootIndex(Cell key,
                        ByteBuff nonRootIndex,
                        CellComparator comparator)Performs a binary search over a non-root level index block. | 
| protected abstract long | calculateHeapSizeForBlockKeys(long heapSize) | 
| void | ensureNonEmpty()Verifies that the block index is non-empty and throws an  IllegalStateExceptionotherwise. | 
| protected byte[] | getNonRootIndexedKey(ByteBuff nonRootIndex,
                    int i)The indexed key at the ith position in the nonRootIndex. | 
| int | getRootBlockCount()Returns the number of root-level blocks in this block index | 
| int | getRootBlockDataSize(int i) | 
| long | getRootBlockOffset(int i) | 
| long | heapSize()Return the approximate 'exclusive deep size' of implementing object. | 
| protected abstract void | initialize(int numEntries) | 
| abstract boolean | isEmpty()Returns true if the block index is empty. | 
| abstract BlockWithScanInfo | loadDataBlockWithScanInfo(Cell key,
                         HFileBlock currentBlock,
                         boolean cacheBlocks,
                         boolean pread,
                         boolean isCompaction,
                         DataBlockEncoding expectedDataBlockEncoding,
                         HFile.CachingBlockReader cachingBlockReader)Return the BlockWithScanInfo, a data structure which contains the Data HFileBlock with other
 scan info such as the key that starts the next HFileBlock. | 
| (package private) static int | locateNonRootIndexEntry(ByteBuff nonRootBlock,
                       Cell key,
                       CellComparator comparator)Search for one key using the secondary index in a non-root block. | 
| abstract Cell | midkey(HFile.CachingBlockReader cachingBlockReader)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(DataInput in,
             int numEntries)Read in the root-level index from the given input stream. | 
| 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. | 
| abstract int | rootBlockContainingKey(byte[] key,
                      int offset,
                      int length,
                      CellComparator comp)Finds the root-level index block containing the given key. | 
| abstract int | rootBlockContainingKey(Cell key)Finds the root-level index block containing the given key. | 
| HFileBlock | seekToDataBlock(Cell key,
               HFileBlock currentBlock,
               boolean cacheBlocks,
               boolean pread,
               boolean isCompaction,
               DataBlockEncoding expectedDataBlockEncoding,
               HFile.CachingBlockReader cachingBlockReader)Return the data block which contains this key. | 
protected long[] blockOffsets
protected int[] blockDataSizes
protected int rootCount
protected long midLeafBlockOffset
protected int midLeafBlockOnDiskSize
protected int midKeyEntry
protected int searchTreeLevel
BlockIndexReader()
public abstract boolean isEmpty()
public void ensureNonEmpty()
IllegalStateException
 otherwise.public HFileBlock seekToDataBlock(Cell key, HFileBlock currentBlock, boolean cacheBlocks, boolean pread, boolean isCompaction, DataBlockEncoding expectedDataBlockEncoding, HFile.CachingBlockReader cachingBlockReader) throws IOException
key - the key we are looking forcurrentBlock - the current block, to avoid re-reading the same block nnn * @param
                     expectedDataBlockEncoding the data block encoding the caller is expecting
                     the data block to be in, or null to not perform this check and return the
                     block irrespective of the encodingIOExceptionpublic abstract BlockWithScanInfo loadDataBlockWithScanInfo(Cell key, HFileBlock currentBlock, boolean cacheBlocks, boolean pread, boolean isCompaction, DataBlockEncoding expectedDataBlockEncoding, HFile.CachingBlockReader cachingBlockReader) throws IOException
key - the key we are looking forcurrentBlock - the current block, to avoid re-reading the same blockexpectedDataBlockEncoding - the data block encoding the caller is expecting the data
                                  block to be in, or null to not perform this check and return
                                  the block irrespective of the encoding.IOExceptionpublic abstract Cell midkey(HFile.CachingBlockReader cachingBlockReader) throws IOException
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.IOExceptionpublic long getRootBlockOffset(int i)
i - from 0 to - 1public int getRootBlockDataSize(int i)
i - zero-based index of a root-level blockpublic int getRootBlockCount()
public abstract int rootBlockContainingKey(byte[] key, int offset, int length, CellComparator comp)
key (between 0 and the number of blocks - 1)
         or -1 if this file does not contain the request.public int rootBlockContainingKey(byte[] key, int offset, int length)
key (between 0 and the number of blocks - 1)
         or -1 if this file does not contain the request.public abstract int rootBlockContainingKey(Cell key)
protected byte[] getNonRootIndexedKey(ByteBuff nonRootIndex, int i)
static int binarySearchNonRootIndex(Cell key, ByteBuff nonRootIndex, CellComparator comparator)
static int locateNonRootIndexEntry(ByteBuff nonRootBlock, Cell key, CellComparator comparator)
public void readRootIndex(DataInput in, int numEntries) throws IOException
HFileBlockIndex.BlockIndexWriter.writeIndexBlocks(FSDataOutputStream) at the offset
 that function returned.in - the buffered input stream or wrapped byte input streamnumEntries - the number of root-level index entries nIOExceptionprotected abstract void initialize(int numEntries)
protected abstract void add(byte[] key, long offset, int dataSize)
public DataInputStream readRootIndex(HFileBlock blk, int numEntries) throws IOException
HFileBlockIndex.BlockIndexWriter.writeIndexBlocks(FSDataOutputStream) at the offset
 that function returned.blk - the HFile blocknumEntries - the number of root-level index entriesIOExceptionpublic void readMultiLevelIndexRoot(HFileBlock blk, int numEntries) throws IOException
readRootIndex(DataInput, int), but also reads metadata necessary to compute the
 mid-key in a multi-level index.blk - the HFile blocknumEntries - the number of root-level index entries nIOExceptionpublic long heapSize()
HeapSizeprotected abstract long calculateHeapSizeForBlockKeys(long heapSize)
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.