public static class HFileBlockIndex.BlockIndexReader extends Object implements HeapSize
Modifier and Type | Field and Description |
---|---|
private int[] |
blockDataSizes |
private byte[][] |
blockKeys |
private long[] |
blockOffsets |
private HFile.CachingBlockReader |
cachingBlockReader
A way to read
HFile blocks at a given offset |
private KeyValue.KVComparator |
comparator
Needed doing lookup on blocks.
|
private AtomicReference<byte[]> |
midKey
Pre-computed mid-key
|
private int |
midKeyEntry |
private long |
midLeafBlockOffset |
private int |
midLeafBlockOnDiskSize |
private int |
rootCount |
private int |
searchTreeLevel
The number of levels in the block index tree.
|
Constructor and Description |
---|
HFileBlockIndex.BlockIndexReader(KeyValue.KVComparator c,
int treeLevel) |
HFileBlockIndex.BlockIndexReader(KeyValue.KVComparator c,
int treeLevel,
HFile.CachingBlockReader cachingBlockReader) |
Modifier and Type | Method and Description |
---|---|
private void |
add(byte[] key,
long offset,
int dataSize)
Adds a new entry in the root block index.
|
(package private) static int |
binarySearchNonRootIndex(Cell key,
ByteBuffer nonRootIndex,
KeyValue.KVComparator comparator)
Performs a binary search over a non-root level index block.
|
void |
ensureNonEmpty()
Verifies that the block index is non-empty and throws an
IllegalStateException otherwise. |
private byte[] |
getNonRootIndexedKey(ByteBuffer nonRootIndex,
int i)
The indexed key at the ith position in the nonRootIndex.
|
int |
getRootBlockCount() |
int |
getRootBlockDataSize(int i) |
byte[] |
getRootBlockKey(int i) |
long |
getRootBlockOffset(int i) |
long |
heapSize() |
boolean |
isEmpty() |
BlockWithScanInfo |
loadDataBlockWithScanInfo(Cell key,
HFileBlock currentBlock,
boolean cacheBlocks,
boolean pread,
boolean isCompaction,
DataBlockEncoding expectedDataBlockEncoding)
Return the BlockWithScanInfo which contains the DataBlock with other scan
info such as nextIndexedKey.
|
(package private) static int |
locateNonRootIndexEntry(ByteBuffer nonRootBlock,
Cell key,
KeyValue.KVComparator comparator)
Search for one key using the secondary index in a non-root block.
|
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(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.
|
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)
Return the data block which contains this key.
|
String |
toString() |
private final KeyValue.KVComparator comparator
private byte[][] blockKeys
private long[] blockOffsets
private int[] blockDataSizes
private int rootCount
private long midLeafBlockOffset
private int midLeafBlockOnDiskSize
private int midKeyEntry
private AtomicReference<byte[]> midKey
private int searchTreeLevel
private HFile.CachingBlockReader cachingBlockReader
HFile
blocks at a given offsetpublic HFileBlockIndex.BlockIndexReader(KeyValue.KVComparator c, int treeLevel, HFile.CachingBlockReader cachingBlockReader)
public HFileBlockIndex.BlockIndexReader(KeyValue.KVComparator c, int treeLevel)
public boolean isEmpty()
public void ensureNonEmpty()
IllegalStateException
otherwise.public HFileBlock seekToDataBlock(Cell key, HFileBlock currentBlock, boolean cacheBlocks, boolean pread, boolean isCompaction, DataBlockEncoding expectedDataBlockEncoding) throws IOException
key
- the key we are looking forcurrentBlock
- the current block, to avoid re-reading the same blockcacheBlocks
- pread
- isCompaction
- 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 encodingIOException
public BlockWithScanInfo loadDataBlockWithScanInfo(Cell key, HFileBlock currentBlock, boolean cacheBlocks, boolean pread, boolean isCompaction, DataBlockEncoding expectedDataBlockEncoding) throws IOException
key
- the key we are looking forcurrentBlock
- the current block, to avoid re-reading the same blockcacheBlocks
- pread
- isCompaction
- 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 encoding.IOException
public byte[] midkey() 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.IOException
public byte[] getRootBlockKey(int i)
i
- from 0 to - 1
public long getRootBlockOffset(int i)
i
- from 0 to - 1
public int getRootBlockDataSize(int i)
i
- zero-based index of a root-level blockpublic int getRootBlockCount()
public int rootBlockContainingKey(byte[] key, int offset, int length)
key
- Key to findkey
(between 0 and the
number of blocks - 1) or -1 if this file does not contain the
request.public int rootBlockContainingKey(Cell key)
key
- Key to findprivate void add(byte[] key, long offset, int dataSize)
key
- Last key in the blockoffset
- file offset where the block is storeddataSize
- the uncompressed data sizeprivate byte[] getNonRootIndexedKey(ByteBuffer nonRootIndex, int i)
nonRootIndex
- i
- the ith positionstatic int binarySearchNonRootIndex(Cell key, ByteBuffer nonRootIndex, KeyValue.KVComparator comparator)
key
- the key we are searching for offsets to individual entries in
the blockIndex buffernonRootIndex
- the non-root index block buffer, starting with the secondary
index. The position is ignored.IOException
static int locateNonRootIndexEntry(ByteBuffer nonRootBlock, Cell key, KeyValue.KVComparator comparator)
nonRootBlock
- a non-root block without header. Initial position does not
matter.key
- the byte array containing the keypublic 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 entriesIOException
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 entriesIOException
public 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 entriesIOException
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.