static class HFileBlock.FSReaderImpl extends Object implements HFileBlock.FSReader
Modifier and Type | Field and Description |
---|---|
private ByteBuffAllocator |
allocator |
private HFileBlockDefaultDecodingContext |
defaultDecodingCtx
Default context used when BlockType !=
BlockType.ENCODED_DATA . |
private HFileBlockDecodingContext |
encodedBlockDecodingCtx |
private HFileContext |
fileContext |
private long |
fileSize
The size of the file we are reading from, or -1 if unknown.
|
protected int |
hdrSize
The size of the header
|
private HFileSystem |
hfs
The filesystem used to access data
|
private boolean |
isPreadAllBytes |
private String |
pathName |
private AtomicReference<HFileBlock.PrefetchedHeader> |
prefetchedHeader
Cache of the NEXT header after this.
|
private Lock |
streamLock |
private FSDataInputStreamWrapper |
streamWrapper
The file system stream of the underlying
HFile that does or doesn't do checksum
validations in the filesystem |
Constructor and Description |
---|
FSReaderImpl(ReaderContext readerContext,
HFileContext fileContext,
ByteBuffAllocator allocator,
org.apache.hadoop.conf.Configuration conf) |
Modifier and Type | Method and Description |
---|---|
private ByteBuff |
allocate(int size,
boolean intoHeap) |
HFileBlock.BlockIterator |
blockRange(long startOffset,
long endOffset)
Creates a block iterator over the given portion of the
HFile . |
private void |
cacheNextBlockHeader(long offset,
ByteBuff onDiskBlock,
int onDiskSizeWithHeader,
int headerLength)
Save away the next blocks header in atomic reference.
|
private static int |
checkAndGetSizeAsInt(long onDiskSizeWithHeaderL,
int hdrSize)
Returns Check
onDiskSizeWithHeaderL size is healthy and then return it as an int |
void |
closeStreams()
Closes the backing streams
|
HFileBlockDecodingContext |
getBlockDecodingContext()
Get a decoder for
BlockType.ENCODED_DATA blocks from this file. |
private ByteBuff |
getCachedHeader(long offset)
Check atomic reference cache for this block's header.
|
HFileBlockDecodingContext |
getDefaultBlockDecodingContext()
Get the default decoder for blocks from this file.
|
private int |
getNextBlockOnDiskSize(boolean readNextHeader,
ByteBuff onDiskBlock,
int onDiskSizeWithHeader) |
protected boolean |
readAtOffset(org.apache.hadoop.fs.FSDataInputStream istream,
ByteBuff dest,
int size,
boolean peekIntoNextBlock,
long fileOffset,
boolean pread)
Does a positional read or a seek and read into the given byte buffer.
|
HFileBlock |
readBlockData(long offset,
long onDiskSizeWithHeaderL,
boolean pread,
boolean updateMetrics,
boolean intoHeap)
Reads a version 2 block (version 1 blocks not supported and not expected).
|
protected HFileBlock |
readBlockDataInternal(org.apache.hadoop.fs.FSDataInputStream is,
long offset,
long onDiskSizeWithHeaderL,
boolean pread,
boolean verifyChecksum,
boolean updateMetrics,
boolean intoHeap)
Reads a version 2 block.
|
void |
setDataBlockEncoder(HFileDataBlockEncoder encoder,
org.apache.hadoop.conf.Configuration conf) |
void |
setIncludesMemStoreTS(boolean includesMemstoreTS) |
String |
toString() |
void |
unbufferStream()
To close the stream's socket.
|
private boolean |
validateChecksum(long offset,
ByteBuff data,
int hdrSize)
Generates the checksum for the header as well as the data and then validates it.
|
private void |
verifyOnDiskSizeMatchesHeader(int passedIn,
ByteBuff headerBuf,
long offset,
boolean verifyChecksum)
Verify the passed in onDiskSizeWithHeader aligns with what is in the header else something is
not right.
|
private FSDataInputStreamWrapper streamWrapper
HFile
that does or doesn't do checksum
validations in the filesystemprivate HFileBlockDecodingContext encodedBlockDecodingCtx
private final HFileBlockDefaultDecodingContext defaultDecodingCtx
BlockType.ENCODED_DATA
.private AtomicReference<HFileBlock.PrefetchedHeader> prefetchedHeader
private long fileSize
protected final int hdrSize
private HFileSystem hfs
private HFileContext fileContext
private final ByteBuffAllocator allocator
private final Lock streamLock
private final boolean isPreadAllBytes
FSReaderImpl(ReaderContext readerContext, HFileContext fileContext, ByteBuffAllocator allocator, org.apache.hadoop.conf.Configuration conf) throws IOException
IOException
public HFileBlock.BlockIterator blockRange(long startOffset, long endOffset)
HFileBlock.FSReader
HFile
. 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.blockRange
in interface HFileBlock.FSReader
startOffset
- the offset of the block to start iteration withendOffset
- the offset to end iteration at (exclusive)protected boolean readAtOffset(org.apache.hadoop.fs.FSDataInputStream istream, ByteBuff dest, int size, boolean peekIntoNextBlock, long fileOffset, boolean pread) throws IOException
ByteBuff.release()
for every exit to deallocate the ByteBuffers,
otherwise the memory leak may happen.dest
- destination buffersize
- size of readpeekIntoNextBlock
- whether to read the next block's on-disk sizefileOffset
- position in the stream to read atpread
- whether we should do a positional readistream
- The input source of dataIOException
- if any IO error happen.public HFileBlock readBlockData(long offset, long onDiskSizeWithHeaderL, boolean pread, boolean updateMetrics, boolean intoHeap) throws IOException
readBlockData
in interface HFileBlock.FSReader
offset
- the offset in the stream to read atonDiskSizeWithHeaderL
- the on-disk size of the block, including the header, or -1 if
unknown; i.e. when iterating over blocks reading in the file
metadata info.pread
- whether to use a positional readupdateMetrics
- whether to update the metricsintoHeap
- allocate ByteBuff of block from heap or off-heap.IOException
for more details about the
useHeap.
private static int checkAndGetSizeAsInt(long onDiskSizeWithHeaderL, int hdrSize) throws IOException
onDiskSizeWithHeaderL
size is healthy and then return it as an intIOException
private void verifyOnDiskSizeMatchesHeader(int passedIn, ByteBuff headerBuf, long offset, boolean verifyChecksum) throws IOException
IOException
private ByteBuff getCachedHeader(long offset)
HFileBlock.PrefetchedHeader
,
cacheNextBlockHeader(long, ByteBuff, int, int)
private void cacheNextBlockHeader(long offset, ByteBuff onDiskBlock, int onDiskSizeWithHeader, int headerLength)
getCachedHeader(long)
,
HFileBlock.PrefetchedHeader
private int getNextBlockOnDiskSize(boolean readNextHeader, ByteBuff onDiskBlock, int onDiskSizeWithHeader)
protected HFileBlock readBlockDataInternal(org.apache.hadoop.fs.FSDataInputStream is, long offset, long onDiskSizeWithHeaderL, boolean pread, boolean verifyChecksum, boolean updateMetrics, boolean intoHeap) throws IOException
offset
- the offset in the stream to read at.onDiskSizeWithHeaderL
- the on-disk size of the block, including the header and
checksums if present or -1 if unknown (as a long). Can be -1 if
we are doing raw iteration of blocks as when loading up file
metadata; i.e. the first read of a new file. Usually non-null
gotten from the file index.pread
- whether to use a positional readverifyChecksum
- Whether to use HBase checksums. If HBase checksum is switched
off, then use HDFS checksum. Can also flip on/off reading same
file if we hit a troublesome patch in an hfile.updateMetrics
- whether need to update the metrics.intoHeap
- allocate the ByteBuff of block from heap or off-heap.IOException
public void setIncludesMemStoreTS(boolean includesMemstoreTS)
setIncludesMemStoreTS
in interface HFileBlock.FSReader
public void setDataBlockEncoder(HFileDataBlockEncoder encoder, org.apache.hadoop.conf.Configuration conf)
setDataBlockEncoder
in interface HFileBlock.FSReader
public HFileBlockDecodingContext getBlockDecodingContext()
HFileBlock.FSReader
BlockType.ENCODED_DATA
blocks from this file.getBlockDecodingContext
in interface HFileBlock.FSReader
public HFileBlockDecodingContext getDefaultBlockDecodingContext()
HFileBlock.FSReader
getDefaultBlockDecodingContext
in interface HFileBlock.FSReader
private boolean validateChecksum(long offset, ByteBuff data, int hdrSize)
public void closeStreams() throws IOException
HFileBlock.FSReader
closeStreams
in interface HFileBlock.FSReader
IOException
public void unbufferStream()
HFileBlock.FSReader
unbufferStream
in interface HFileBlock.FSReader
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.