static class HFileBlock.FSReaderImpl extends Object implements HFileBlock.FSReader
Modifier and Type | Field and Description |
---|---|
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 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(org.apache.hadoop.fs.FSDataInputStream istream,
long fileSize,
HFileContext fileContext)
A constructor that reads files with the latest minor version.
|
FSReaderImpl(FSDataInputStreamWrapper stream,
long fileSize,
HFileSystem hfs,
org.apache.hadoop.fs.Path path,
HFileContext fileContext) |
Modifier and Type | Method and Description |
---|---|
HFileBlock.BlockIterator |
blockRange(long startOffset,
long endOffset)
Creates a block iterator over the given portion of the
HFile . |
private void |
cacheNextBlockHeader(long offset,
byte[] header,
int headerOffset,
int headerLength)
Save away the next blocks header in atomic reference.
|
private static int |
checkAndGetSizeAsInt(long onDiskSizeWithHeaderL,
int hdrSize) |
void |
closeStreams()
Closes the backing streams
|
HFileBlockDecodingContext |
getBlockDecodingContext()
Get a decoder for
BlockType.ENCODED_DATA blocks from this file. |
private ByteBuffer |
getCachedHeader(long offset)
Check atomic reference cache for this block's header.
|
HFileBlockDecodingContext |
getDefaultBlockDecodingContext()
Get the default decoder for blocks from this file.
|
protected int |
readAtOffset(org.apache.hadoop.fs.FSDataInputStream istream,
byte[] dest,
int destOffset,
int size,
boolean peekIntoNextBlock,
long fileOffset,
boolean pread)
Does a positional read or a seek and read into the given buffer.
|
HFileBlock |
readBlockData(long offset,
long onDiskSizeWithHeaderL,
boolean pread,
boolean updateMetrics)
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)
Reads a version 2 block.
|
void |
setDataBlockEncoder(HFileDataBlockEncoder encoder) |
void |
setIncludesMemStoreTS(boolean includesMemstoreTS) |
String |
toString() |
void |
unbufferStream()
To close the stream's socket.
|
private boolean |
validateChecksum(long offset,
ByteBuffer data,
int hdrSize)
Generates the checksum for the header as well as the data and then validates it.
|
private void |
verifyOnDiskSizeMatchesHeader(int passedIn,
ByteBuffer 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 Lock streamLock
FSReaderImpl(FSDataInputStreamWrapper stream, long fileSize, HFileSystem hfs, org.apache.hadoop.fs.Path path, HFileContext fileContext) throws IOException
IOException
FSReaderImpl(org.apache.hadoop.fs.FSDataInputStream istream, long fileSize, HFileContext fileContext) 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 int readAtOffset(org.apache.hadoop.fs.FSDataInputStream istream, byte[] dest, int destOffset, int size, boolean peekIntoNextBlock, long fileOffset, boolean pread) throws IOException
dest
- destination bufferdestOffset
- offset into the destination buffer at where to put the bytes we readsize
- 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 datadest
INCLUDES the
next headerIOException
public HFileBlock readBlockData(long offset, long onDiskSizeWithHeaderL, boolean pread, boolean updateMetrics) 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 readIOException
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, ByteBuffer headerBuf, long offset, boolean verifyChecksum) throws IOException
IOException
private ByteBuffer getCachedHeader(long offset)
HFileBlock.PrefetchedHeader
,
cacheNextBlockHeader(long, byte[], int, int)
private void cacheNextBlockHeader(long offset, byte[] header, int headerOffset, int headerLength)
getCachedHeader(long)
,
HFileBlock.PrefetchedHeader
protected HFileBlock readBlockDataInternal(org.apache.hadoop.fs.FSDataInputStream is, long offset, long onDiskSizeWithHeaderL, boolean pread, boolean verifyChecksum, boolean updateMetrics) 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.IOException
public void setIncludesMemStoreTS(boolean includesMemstoreTS)
setIncludesMemStoreTS
in interface HFileBlock.FSReader
public void setDataBlockEncoder(HFileDataBlockEncoder encoder)
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, ByteBuffer data, int hdrSize) throws IOException
IOException
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.