Class ChannelWriterOutputView

java.lang.Object
org.apache.flink.runtime.memory.AbstractPagedOutputView
org.apache.flink.runtime.io.disk.iomanager.ChannelWriterOutputView
All Implemented Interfaces:
DataOutput, org.apache.flink.core.memory.DataOutputView, org.apache.flink.core.memory.MemorySegmentWritable

public final class ChannelWriterOutputView extends AbstractPagedOutputView
A DataOutputView that is backed by a BlockChannelWriter, making it effectively a data output stream. The view writes its data in blocks to the underlying channel, adding a minimal header to each block. The data can be re-read by a ChannelReaderInputView, if it uses the same block size.
  • Field Details

    • HEADER_MAGIC_NUMBER

      protected static final short HEADER_MAGIC_NUMBER
      The magic number that identifies blocks as blocks from a ChannelWriterOutputView.
      See Also:
    • HEADER_LENGTH

      protected static final int HEADER_LENGTH
      The length of the header put into the blocks.
      See Also:
    • HEADER_FLAGS_OFFSET

      protected static final int HEADER_FLAGS_OFFSET
      The offset to the flags in the header;
      See Also:
    • HEAD_BLOCK_LENGTH_OFFSET

      protected static final int HEAD_BLOCK_LENGTH_OFFSET
      The offset to the header field indicating the number of bytes in the block
      See Also:
    • FLAG_LAST_BLOCK

      protected static final short FLAG_LAST_BLOCK
      The flag marking a block as the last block.
      See Also:
  • Constructor Details

    • ChannelWriterOutputView

      public ChannelWriterOutputView(BlockChannelWriter<org.apache.flink.core.memory.MemorySegment> writer, List<org.apache.flink.core.memory.MemorySegment> memory, int segmentSize)
      Creates an new ChannelWriterOutputView that writes to the given channel and buffers data in the given memory segments. If the given memory segments are null, the writer takes its buffers directly from the return queue of the writer. Note that this variant locks if no buffers are contained in the return queue.
      Parameters:
      writer - The writer to write to.
      memory - The memory used to buffer data, or null, to utilize solely the return queue.
      segmentSize - The size of the memory segments.
    • ChannelWriterOutputView

      public ChannelWriterOutputView(BlockChannelWriter<org.apache.flink.core.memory.MemorySegment> writer, int segmentSize)
      Creates an new ChannelWriterOutputView that writes to the given channel. It uses only a single memory segment for the buffering, which it takes from the writer's return queue. Note that this variant locks if no buffers are contained in the return queue.
      Parameters:
      writer - The writer to write to.
      segmentSize - The size of the memory segments.
  • Method Details

    • close

      public List<org.apache.flink.core.memory.MemorySegment> close() throws IOException
      Closes this OutputView, closing the underlying writer and returning all memory segments.
      Returns:
      A list containing all memory segments originally supplied to this view.
      Throws:
      IOException - Thrown, if the underlying writer could not be properly closed.
    • getBlockCount

      public int getBlockCount()
      Gets the number of blocks used by this view.
      Returns:
      The number of blocks used.
    • getBytesWritten

      public long getBytesWritten()
      Gets the number of pay-load bytes already written. This excludes the number of bytes spent on headers in the segments.
      Returns:
      The number of bytes that have been written to this output view.
    • getBytesMemoryUsed

      public long getBytesMemoryUsed()
      Gets the number of bytes used by this output view, including written bytes and header bytes.
      Returns:
      The number of bytes that have been written to this output view.
    • nextSegment

      protected final org.apache.flink.core.memory.MemorySegment nextSegment(org.apache.flink.core.memory.MemorySegment current, int posInSegment) throws IOException
      Description copied from class: AbstractPagedOutputView
      This method must return a segment. If no more segments are available, it must throw an EOFException.
      Specified by:
      nextSegment in class AbstractPagedOutputView
      Parameters:
      current - The current memory segment
      posInSegment - The position in the segment, one after the last valid byte.
      Returns:
      The next memory segment.
      Throws:
      IOException