Package org.apache.hadoop.hbase.io.hfile
Interface HFileBlock.FSReader
- All Known Implementing Classes:
HFileBlock.FSReaderImpl
- Enclosing class:
- HFileBlock
static interface HFileBlock.FSReader
An HFile block reader with iteration ability.
-
Method Summary
Modifier and TypeMethodDescriptionblockRange
(long startOffset, long endOffset) Creates a block iterator over the given portion of theHFile
.void
Closes the backing streamsGet a decoder forBlockType.ENCODED_DATA
blocks from this file.Get the default decoder for blocks from this file.readBlockData
(long offset, long onDiskSize, boolean pread, boolean updateMetrics, boolean intoHeap) Reads the block at the given offset in the file with the given on-disk size and uncompressed size.void
setDataBlockEncoder
(HFileDataBlockEncoder encoder, org.apache.hadoop.conf.Configuration conf) void
setIncludesMemStoreTS
(boolean includesMemstoreTS) void
To close the stream's socket.
-
Method Details
-
readBlockData
HFileBlock readBlockData(long offset, long onDiskSize, boolean pread, boolean updateMetrics, boolean intoHeap) throws IOException Reads the block at the given offset in the file with the given on-disk size and uncompressed size.- Parameters:
offset
- of the file to readonDiskSize
- the on-disk size of the entire block, including all applicable headers, or -1 if unknownpread
- true to use pread, otherwise use the stream read.updateMetrics
- update the metrics or not.intoHeap
- allocate the block's ByteBuff byByteBuffAllocator
or JVM heap. For LRUBlockCache, we must ensure that the block to cache is an heap one, because the memory occupation is based on heap now, also forCombinedBlockCache
, we use the heap LRUBlockCache as L1 cache to cache small blocks such as IndexBlock or MetaBlock for faster access. So introduce an flag here to decide whether allocate from JVM heap or not so that we can avoid an extra off-heap to heap memory copy when using LRUBlockCache. For most cases, we known what's the expected block type we'll read, while for some special case (Example: HFileReaderImpl#readNextDataBlock()), we cannot pre-decide what's the expected block type, then we can only allocate block's ByteBuff fromByteBuffAllocator
firstly, and then when caching it inLruBlockCache
we'll check whether the ByteBuff is from heap or not, if not then we'll clone it to an heap one and cache it.- Returns:
- the newly read block
- Throws:
IOException
-
blockRange
Creates a block iterator over the given portion of theHFile
. The iterator returns blocks starting with offset such that offset <= startOffset < endOffset. Returned blocks are always unpacked. Used when no hfile index available; e.g. reading in the hfile index blocks themselves on file open.- Parameters:
startOffset
- the offset of the block to start iteration withendOffset
- the offset to end iteration at (exclusive)- Returns:
- an iterator of blocks between the two given offsets
-
closeStreams
Closes the backing streams- Throws:
IOException
-
getBlockDecodingContext
Get a decoder forBlockType.ENCODED_DATA
blocks from this file. -
getDefaultBlockDecodingContext
Get the default decoder for blocks from this file. -
setIncludesMemStoreTS
-
setDataBlockEncoder
-
unbufferStream
void unbufferStream()To close the stream's socket. Note: This can be concurrently called from multiple threads and implementation should take care of thread safety.
-