Class ChannelReaderInputView
java.lang.Object
org.apache.flink.runtime.memory.AbstractPagedInputView
org.apache.flink.runtime.io.disk.iomanager.AbstractChannelReaderInputView
org.apache.flink.runtime.io.disk.iomanager.ChannelReaderInputView
- All Implemented Interfaces:
DataInput,org.apache.flink.core.memory.DataInputView
- Direct Known Subclasses:
HeaderlessChannelReaderInputView
A
DataInputView that is backed by a BlockChannelReader, making it effectively a data input stream. The view reads it data in blocks
from the underlying channel. The view can only read data that has been written by a ChannelWriterOutputView, due to block formatting.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected final BlockChannelReader<org.apache.flink.core.memory.MemorySegment>Fields inherited from class org.apache.flink.runtime.memory.AbstractPagedInputView
headerLength -
Constructor Summary
ConstructorsConstructorDescriptionChannelReaderInputView(BlockChannelReader<org.apache.flink.core.memory.MemorySegment> reader, List<org.apache.flink.core.memory.MemorySegment> memory, boolean waitForFirstBlock) Creates a new channel reader that reads from the given channel until the last block (as marked by aChannelWriterOutputView) is found.ChannelReaderInputView(BlockChannelReader<org.apache.flink.core.memory.MemorySegment> reader, List<org.apache.flink.core.memory.MemorySegment> memory, int numBlocks, boolean waitForFirstBlock) Creates a new channel reader that reads from the given channel, expecting a specified number of blocks in the channel. -
Method Summary
Modifier and TypeMethodDescriptionList<org.apache.flink.core.memory.MemorySegment>close()Closes this InputView, closing the underlying reader and returning all memory segments.Get the underlying channel.protected intgetLimitForSegment(org.apache.flink.core.memory.MemorySegment segment) Gets the limit for reading bytes from the given memory segment.booleanisClosed()protected org.apache.flink.core.memory.MemorySegmentnextSegment(org.apache.flink.core.memory.MemorySegment current) Gets the next segment from the asynchronous block reader.protected voidsendReadRequest(org.apache.flink.core.memory.MemorySegment seg) Sends a new read requests, if further requests remain.voidMethods inherited from class org.apache.flink.runtime.memory.AbstractPagedInputView
advance, clear, doAdvance, getCurrentPositionInSegment, getCurrentSegment, getCurrentSegmentLimit, getHeaderLength, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seekInput, skipBytes, skipBytesToRead
-
Field Details
-
reader
-
numRequestsRemaining
protected int numRequestsRemaining
-
-
Constructor Details
-
ChannelReaderInputView
public ChannelReaderInputView(BlockChannelReader<org.apache.flink.core.memory.MemorySegment> reader, List<org.apache.flink.core.memory.MemorySegment> memory, boolean waitForFirstBlock) throws IOException Creates a new channel reader that reads from the given channel until the last block (as marked by aChannelWriterOutputView) is found.- Parameters:
reader- The reader that reads the data from disk back into memory.memory- A list of memory segments that the reader uses for reading the data in. If the list contains more than one segment, the reader will asynchronously pre-fetch blocks ahead.waitForFirstBlock- A flag indicating weather this constructor call should block until the first block has returned from the asynchronous I/O reader.- Throws:
IOException- Thrown, if the read requests for the first blocks fail to be served by the reader.
-
ChannelReaderInputView
public ChannelReaderInputView(BlockChannelReader<org.apache.flink.core.memory.MemorySegment> reader, List<org.apache.flink.core.memory.MemorySegment> memory, int numBlocks, boolean waitForFirstBlock) throws IOException Creates a new channel reader that reads from the given channel, expecting a specified number of blocks in the channel.WARNING: The reader will lock if the number of blocks given here is actually lower than the actual number of blocks in the channel.
- Parameters:
reader- The reader that reads the data from disk back into memory.memory- A list of memory segments that the reader uses for reading the data in. If the list contains more than one segment, the reader will asynchronously pre-fetch blocks ahead.numBlocks- The number of blocks this channel will read. If this value is given, the reader avoids issuing pre-fetch requests for blocks beyond the channel size.waitForFirstBlock- A flag indicating weather this constructor call should block until the first block has returned from the asynchronous I/O reader.- Throws:
IOException- Thrown, if the read requests for the first blocks fail to be served by the reader.
-
-
Method Details
-
waitForFirstBlock
- Throws:
IOException
-
isClosed
public boolean isClosed() -
close
Closes this InputView, closing the underlying reader and returning all memory segments.- Specified by:
closein classAbstractChannelReaderInputView- Returns:
- A list containing all memory segments originally supplied to this view.
- Throws:
IOException- Thrown, if the underlying reader could not be properly closed.
-
getChannel
Description copied from class:AbstractChannelReaderInputViewGet the underlying channel.- Specified by:
getChannelin classAbstractChannelReaderInputView
-
nextSegment
protected org.apache.flink.core.memory.MemorySegment nextSegment(org.apache.flink.core.memory.MemorySegment current) throws IOException Gets the next segment from the asynchronous block reader. If more requests are to be issued, the method first sends a new request with the current memory segment. If no more requests are pending, the method adds the segment to the readers return queue, which thereby effectively collects all memory segments. Secondly, the method fetches the next non-consumed segment returned by the reader. If no further segments are available, this method thrown anEOFException.- Specified by:
nextSegmentin classAbstractPagedInputView- Parameters:
current- The memory segment used for the next request.- Returns:
- The memory segment to read from next.
- Throws:
EOFException- Thrown, if no further segments are available.IOException- Thrown, if an I/O error occurred while reading- See Also:
-
getLimitForSegment
protected int getLimitForSegment(org.apache.flink.core.memory.MemorySegment segment) Description copied from class:AbstractPagedInputViewGets the limit for reading bytes from the given memory segment. This method must return the position of the byte after the last valid byte in the given memory segment. When the position returned by this method is reached, the view will attempt to switch to the next memory segment.- Specified by:
getLimitForSegmentin classAbstractPagedInputView- Parameters:
segment- The segment to determine the limit for.- Returns:
- The limit for the given memory segment.
-
sendReadRequest
Sends a new read requests, if further requests remain. Otherwise, this method adds the segment directly to the readers return queue.- Parameters:
seg- The segment to use for the read request.- Throws:
IOException- Thrown, if the reader is in error.
-