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 SummaryNested Classes
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final booleanprivate final booleanprivate AtomicIntegerprivate final HFileSystemprivate final FileLinkprivate final org.apache.hadoop.fs.Pathprivate final longprotected org.apache.hadoop.fs.Pathprivate static final FSDataInputStreamWrapper.ReadStatisticsprivate org.apache.hadoop.fs.FSDataInputStreamTwo stream handles, one with and one without FS-level checksum.private org.apache.hadoop.fs.FSDataInputStreamprivate final Objectprivate booleanprivate boolean
- 
Constructor SummaryConstructorsModifierConstructorDescriptionFSDataInputStreamWrapper(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) privateFSDataInputStreamWrapper(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 SummaryModifier and TypeMethodDescriptionvoidReport that checksum was ok, so we may ponder going back to HBase checksum.voidclose()CloseClose stream(s) if necessary.org.apache.hadoop.fs.FSDataInputStreamfallbackToFsChecksum(int offCount) Read from non-checksum stream failed, fall back to FS checksum.getHfs()static longorg.apache.hadoop.fs.Pathstatic longorg.apache.hadoop.fs.FSDataInputStreamgetStream(boolean useHBaseChecksum) Get the stream to use.static longstatic longvoidprepareForBlockReader(boolean forceNoHBaseChecksum) Prepares the streams for block reader.(package private) voidprivate voidsetStreamOptions(org.apache.hadoop.fs.FSDataInputStream in) booleanReturns Whether we are presently using HBase checksum.voidunbuffer()This will free sockets and file descriptors held by the stream only when the stream implements org.apache.hadoop.fs.CanUnbuffer.private voidupdateInputStreamStatistics(org.apache.hadoop.fs.FSDataInputStream stream) 
- 
Field Details- 
hfs
- 
path
- 
link
- 
doCloseStreams
- 
dropBehind
- 
readahead
- 
streamTwo 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 untilstreamis 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- 
FSDataInputStreamWrapperpublic FSDataInputStreamWrapper(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException - Throws:
- IOException
 
- 
FSDataInputStreamWrapperpublic FSDataInputStreamWrapper(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, boolean dropBehind, long readahead) throws IOException - Throws:
- IOException
 
- 
FSDataInputStreamWrapperpublic FSDataInputStreamWrapper(org.apache.hadoop.fs.FileSystem fs, FileLink link, boolean dropBehind, long readahead) throws IOException - Throws:
- IOException
 
- 
FSDataInputStreamWrapperprivate FSDataInputStreamWrapper(org.apache.hadoop.fs.FileSystem fs, FileLink link, org.apache.hadoop.fs.Path path, boolean dropBehind, long readahead) throws IOException - Throws:
- IOException
 
- 
FSDataInputStreamWrapperFor use in tests.
- 
FSDataInputStreamWrapperpublic FSDataInputStreamWrapper(org.apache.hadoop.fs.FSDataInputStream fsdis, org.apache.hadoop.fs.FSDataInputStream noChecksum) For use in tests.
 
- 
- 
Method Details- 
setStreamOptions
- 
prepareForBlockReaderPrepares 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
 
- 
shouldUseHBaseChecksumReturns Whether we are presently using HBase checksum.
- 
getStreamGet 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.
 
- 
fallbackToFsChecksumRead 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
 
- 
checksumOkReport that checksum was ok, so we may ponder going back to HBase checksum.
- 
updateInputStreamStatistics
- 
getTotalBytesRead
- 
getLocalBytesRead
- 
getShortCircuitBytesRead
- 
getZeroCopyBytesRead
- 
closeCloseClose stream(s) if necessary.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
- 
getHfs
- 
unbufferThis 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
- 
setShouldUseHBaseChecksumvoid setShouldUseHBaseChecksum()
 
-