Class S3APrefetchingInputStream
java.lang.Object
java.io.InputStream
org.apache.hadoop.fs.FSInputStream
org.apache.hadoop.fs.s3a.impl.streams.ObjectInputStream
org.apache.hadoop.fs.s3a.prefetch.S3APrefetchingInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.fs.CanSetReadahead,org.apache.hadoop.fs.PositionedReadable,org.apache.hadoop.fs.Seekable,org.apache.hadoop.fs.statistics.IOStatisticsSource,org.apache.hadoop.fs.StreamCapabilities
public class S3APrefetchingInputStream
extends ObjectInputStream
implements org.apache.hadoop.fs.CanSetReadahead, org.apache.hadoop.fs.StreamCapabilities, org.apache.hadoop.fs.statistics.IOStatisticsSource
Enhanced
InputStream for reading from S3.
This implementation provides improved read throughput by asynchronously prefetching
blocks of configurable size from the underlying S3 file.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.hadoop.fs.StreamCapabilities
org.apache.hadoop.fs.StreamCapabilities.StreamCapability -
Field Summary
Fields inherited from interface org.apache.hadoop.fs.StreamCapabilities
ABORTABLE_STREAM, DROPBEHIND, HFLUSH, HSYNC, IOSTATISTICS, IOSTATISTICS_CONTEXT, PREADBYTEBUFFER, READAHEAD, READBYTEBUFFER, UNBUFFER, VECTOREDIO, VECTOREDIO_BUFFERS_SLICED -
Constructor Summary
ConstructorsConstructorDescriptionS3APrefetchingInputStream(ObjectReadParameters parameters, org.apache.hadoop.conf.Configuration conf, PrefetchOptions prefetchOptions) Initializes a new instance of theS3APrefetchingInputStreamclass. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidBrute force stream close; invoked byLeakReporter.intReturns the number of bytes available for reading without blocking.voidclose()Closes this stream and releases all acquired resources.org.apache.hadoop.fs.statistics.IOStatisticsGets the internal IO statistics.longgetPos()Gets the current position.Access the input stream statistics.booleanhasCapability(String capability) Indicates whether the givencapabilityis supported by this stream.protected booleanisClosed()protected booleanProbe for stream being open.booleanintread()Reads and returns one byte from this stream.intread(byte[] buffer, int offset, int len) Reads up tolenbytes from this stream and copies them into the givenbufferstarting at the givenoffset.voidseek(long pos) Updates internal data such that the next read will take place at the givenpos.booleanseekToNewSource(long targetPos) voidsetReadahead(Long readahead) Sets the number of bytes to read ahead each time.protected voidMethods inherited from class org.apache.hadoop.fs.s3a.impl.streams.ObjectInputStream
finalize, getBoundedThreadPool, getBucket, getCallbacks, getContentLength, getContext, getInputPolicy, getKey, getObjectAttributes, getPathStr, getThreadIOStatistics, getUri, getVectoredIOContext, maxReadSizeForVectorReads, mergeThreadIOStatistics, minSeekForVectorReads, setInputPolicy, streamType, toStringMethods inherited from class org.apache.hadoop.fs.FSInputStream
read, readFully, readFully, validatePositionedReadArgsMethods inherited from class java.io.InputStream
mark, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferToMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.fs.PositionedReadable
readVectored, readVectored
-
Constructor Details
-
S3APrefetchingInputStream
public S3APrefetchingInputStream(ObjectReadParameters parameters, org.apache.hadoop.conf.Configuration conf, PrefetchOptions prefetchOptions) Initializes a new instance of theS3APrefetchingInputStreamclass.- Parameters:
parameters- creation parameters.conf- the configuration.prefetchOptions- prefetch stream specific options- Throws:
NullPointerException- if a required parameter is null.
-
-
Method Details
-
available
Returns the number of bytes available for reading without blocking.- Overrides:
availablein classInputStream- Returns:
- the number of bytes available for reading without blocking.
- Throws:
IOException- if there is an IO error during this operation.
-
getPos
Gets the current position. If the underlying S3 input stream is closed, it returns last read current position from the underlying steam. If the current position was never read and the underlying input stream is closed, this would return 0.- Specified by:
getPosin interfaceorg.apache.hadoop.fs.Seekable- Specified by:
getPosin classorg.apache.hadoop.fs.FSInputStream- Returns:
- the current position.
- Throws:
IOException- if there is an IO error during this operation.
-
read
Reads and returns one byte from this stream.- Specified by:
readin classInputStream- Returns:
- the next byte from this stream.
- Throws:
IOException- if there is an IO error during this operation.
-
read
Reads up tolenbytes from this stream and copies them into the givenbufferstarting at the givenoffset. Returns the number of bytes actually copied in to the given buffer.- Overrides:
readin classInputStream- Parameters:
buffer- the buffer to copy data into.offset- data is copied starting at this offset.len- max number of bytes to copy.- Returns:
- the number of bytes actually copied in to the given buffer.
- Throws:
IOException- if there is an IO error during this operation.
-
close
Closes this stream and releases all acquired resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classObjectInputStream- Throws:
IOException- if there is an IO error during this operation.
-
isStreamOpen
protected boolean isStreamOpen()Description copied from class:ObjectInputStreamProbe for stream being open. Not synchronized; the flag is volatile.- Specified by:
isStreamOpenin classObjectInputStream- Returns:
- true if the stream is still open.
-
abortInFinalizer
protected void abortInFinalizer()Description copied from class:ObjectInputStreamBrute force stream close; invoked byLeakReporter. All exceptions raised are ignored.- Specified by:
abortInFinalizerin classObjectInputStream
-
seek
Updates internal data such that the next read will take place at the givenpos.- Specified by:
seekin interfaceorg.apache.hadoop.fs.Seekable- Specified by:
seekin classorg.apache.hadoop.fs.FSInputStream- Parameters:
pos- new read position.- Throws:
IOException- if there is an IO error during this operation.
-
setReadahead
Sets the number of bytes to read ahead each time.- Specified by:
setReadaheadin interfaceorg.apache.hadoop.fs.CanSetReadahead- Parameters:
readahead- the number of bytes to read ahead each time..
-
hasCapability
Indicates whether the givencapabilityis supported by this stream.- Specified by:
hasCapabilityin interfaceorg.apache.hadoop.fs.StreamCapabilities- Overrides:
hasCapabilityin classObjectInputStream- Parameters:
capability- the capability to check.- Returns:
- true if the given
capabilityis supported by this stream, false otherwise.
-
getS3AStreamStatistics
Access the input stream statistics. This is for internal testing and may be removed without warning.- Overrides:
getS3AStreamStatisticsin classObjectInputStream- Returns:
- the statistics for this input stream
-
getIOStatistics
public org.apache.hadoop.fs.statistics.IOStatistics getIOStatistics()Gets the internal IO statistics.- Specified by:
getIOStatisticsin interfaceorg.apache.hadoop.fs.statistics.IOStatisticsSource- Overrides:
getIOStatisticsin classObjectInputStream- Returns:
- the internal IO statistics.
-
isClosed
protected boolean isClosed() -
throwIfClosed
- Throws:
IOException
-
seekToNewSource
- Specified by:
seekToNewSourcein interfaceorg.apache.hadoop.fs.Seekable- Specified by:
seekToNewSourcein classorg.apache.hadoop.fs.FSInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-