Package org.apache.hadoop.hbase.io
Class FSDataInputStreamWrapper
java.lang.Object
org.apache.hadoop.hbase.io.FSDataInputStreamWrapper
- All Implemented Interfaces:
Closeable
,AutoCloseable
Wrapper for input stream(s) that takes care of the interaction of FS and HBase checksums, as well
as closing streams. Initialization is not thread-safe, but normal operation is; see method
comments.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate final boolean
private final boolean
private AtomicInteger
private final HFileSystem
private final FileLink
private final org.apache.hadoop.fs.Path
private final long
protected org.apache.hadoop.fs.Path
private static final FSDataInputStreamWrapper.ReadStatistics
private org.apache.hadoop.fs.FSDataInputStream
Two stream handles, one with and one without FS-level checksum.private org.apache.hadoop.fs.FSDataInputStream
private final Object
private boolean
private boolean
-
Constructor Summary
ModifierConstructorDescriptionFSDataInputStreamWrapper
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) FSDataInputStreamWrapper
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, boolean dropBehind, long readahead) FSDataInputStreamWrapper
(org.apache.hadoop.fs.FileSystem fs, FileLink link, boolean dropBehind, long readahead) private
FSDataInputStreamWrapper
(org.apache.hadoop.fs.FileSystem fs, FileLink link, org.apache.hadoop.fs.Path path, boolean dropBehind, long readahead) FSDataInputStreamWrapper
(org.apache.hadoop.fs.FSDataInputStream fsdis) For use in tests.FSDataInputStreamWrapper
(org.apache.hadoop.fs.FSDataInputStream fsdis, org.apache.hadoop.fs.FSDataInputStream noChecksum) For use in tests. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Report that checksum was ok, so we may ponder going back to HBase checksum.void
close()
CloseClose stream(s) if necessary.org.apache.hadoop.fs.FSDataInputStream
fallbackToFsChecksum
(int offCount) Read from non-checksum stream failed, fall back to FS checksum.getHfs()
static long
org.apache.hadoop.fs.Path
static long
org.apache.hadoop.fs.FSDataInputStream
getStream
(boolean useHBaseChecksum) Get the stream to use.static long
static long
void
prepareForBlockReader
(boolean forceNoHBaseChecksum) Prepares the streams for block reader.(package private) void
private void
setStreamOptions
(org.apache.hadoop.fs.FSDataInputStream in) boolean
Returns Whether we are presently using HBase checksum.void
unbuffer()
This will free sockets and file descriptors held by the stream only when the stream implements org.apache.hadoop.fs.CanUnbuffer.private void
updateInputStreamStatistics
(org.apache.hadoop.fs.FSDataInputStream stream)
-
Field Details
-
hfs
-
path
-
link
-
doCloseStreams
-
dropBehind
-
readahead
-
stream
Two stream handles, one with and one without FS-level checksum. HDFS checksum setting is on FS level, not single read level, so you have to keep two FS objects and two handles open to interleave different reads freely, which is very sad. This is what we do: 1) First, we need to read the trailer of HFile to determine checksum parameters. We always use FS checksum to do that, so ctor opensstream
. 2.1) After that, if HBase checksum is not used, we'd just always usestream
; 2.2) If HBase checksum can be used, we'll openstreamNoFsChecksum
, and closestream
. User MUST call prepareForBlockReader for that to happen; if they don't, (2.1) will be the default. 3) The users can callshouldUseHBaseChecksum()
, and pass its result togetStream(boolean)
to get stream (if Java had out/pointer params we could return both in one call). This stream is guaranteed to be set. 4) The first time HBase checksum fails, one would callfallbackToFsChecksum(int)
. That will take lock, and openstream
. While this is going on, others will continue to use the old stream; if they also want to fall back, they'll also callfallbackToFsChecksum(int)
, and block untilstream
is set. 5) After some number of checksumOk() calls, we will go back to using HBase checksum. We will have 2 handles; however we presume checksums fail so rarely that we don't care. -
streamNoFsChecksum
-
streamNoFsChecksumFirstCreateLock
-
useHBaseChecksumConfigured
-
useHBaseChecksum
-
hbaseChecksumOffCount
-
readStatistics
-
readerPath
-
-
Constructor Details
-
FSDataInputStreamWrapper
public FSDataInputStreamWrapper(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException - Throws:
IOException
-
FSDataInputStreamWrapper
public FSDataInputStreamWrapper(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, boolean dropBehind, long readahead) throws IOException - Throws:
IOException
-
FSDataInputStreamWrapper
public FSDataInputStreamWrapper(org.apache.hadoop.fs.FileSystem fs, FileLink link, boolean dropBehind, long readahead) throws IOException - Throws:
IOException
-
FSDataInputStreamWrapper
private FSDataInputStreamWrapper(org.apache.hadoop.fs.FileSystem fs, FileLink link, org.apache.hadoop.fs.Path path, boolean dropBehind, long readahead) throws IOException - Throws:
IOException
-
FSDataInputStreamWrapper
For use in tests. -
FSDataInputStreamWrapper
public FSDataInputStreamWrapper(org.apache.hadoop.fs.FSDataInputStream fsdis, org.apache.hadoop.fs.FSDataInputStream noChecksum) For use in tests.
-
-
Method Details
-
setStreamOptions
-
prepareForBlockReader
Prepares the streams for block reader. NOT THREAD SAFE. Must be called once, after any reads finish and before any other reads start (what happens in reality is we read the tail, then call this based on what's in the tail, then read blocks).- Parameters:
forceNoHBaseChecksum
- Force not using HBase checksum.- Throws:
IOException
-
shouldUseHBaseChecksum
Returns Whether we are presently using HBase checksum. -
getStream
Get the stream to use. Thread-safe.- Parameters:
useHBaseChecksum
- must be the value that shouldUseHBaseChecksum has returned at some point in the past, otherwise the result is undefined.
-
fallbackToFsChecksum
Read from non-checksum stream failed, fall back to FS checksum. Thread-safe.- Parameters:
offCount
- For how many checksumOk calls to turn off the HBase checksum.- Throws:
IOException
-
checksumOk
Report that checksum was ok, so we may ponder going back to HBase checksum. -
updateInputStreamStatistics
-
getTotalBytesRead
-
getLocalBytesRead
-
getShortCircuitBytesRead
-
getZeroCopyBytesRead
-
close
CloseClose stream(s) if necessary.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getHfs
-
unbuffer
This will free sockets and file descriptors held by the stream only when the stream implements org.apache.hadoop.fs.CanUnbuffer. NOT THREAD SAFE. Must be called only when all the clients using this stream to read the blocks have finished reading. If by chance the stream is unbuffered and there are clients still holding this stream for read then on next client read request a new socket will be opened by Datanode without client knowing about it and will serve its read request. Note: If this socket is idle for some time then the DataNode will close the socket and the socket will move into CLOSE_WAIT state and on the next client request on this stream, the current socket will be closed and a new socket will be opened to serve the requests. -
getReaderPath
-
setShouldUseHBaseChecksum
void setShouldUseHBaseChecksum()
-