Class ChannelReaderInputView

All Implemented Interfaces:
DataInput, org.apache.flink.core.memory.DataInputView
Direct Known Subclasses:
HeaderlessChannelReaderInputView

public class ChannelReaderInputView extends AbstractChannelReaderInputView
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 Details

    • reader

      protected final BlockChannelReader<org.apache.flink.core.memory.MemorySegment> 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 a ChannelWriterOutputView) 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

      public void waitForFirstBlock() throws IOException
      Throws:
      IOException
    • isClosed

      public boolean isClosed()
    • close

      public List<org.apache.flink.core.memory.MemorySegment> close() throws IOException
      Closes this InputView, closing the underlying reader and returning all memory segments.
      Specified by:
      close in class AbstractChannelReaderInputView
      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

      public FileIOChannel getChannel()
      Description copied from class: AbstractChannelReaderInputView
      Get the underlying channel.
      Specified by:
      getChannel in class AbstractChannelReaderInputView
    • 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 an EOFException.
      Specified by:
      nextSegment in class AbstractPagedInputView
      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: AbstractPagedInputView
      Gets 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:
      getLimitForSegment in class AbstractPagedInputView
      Parameters:
      segment - The segment to determine the limit for.
      Returns:
      The limit for the given memory segment.
    • sendReadRequest

      protected void sendReadRequest(org.apache.flink.core.memory.MemorySegment seg) throws IOException
      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.