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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final shortThe flag marking a block as the last block.protected static final intThe offset to the header field indicating the number of bytes in the blockprotected static final intThe offset to the flags in the header;protected static final intThe length of the header put into the blocks.protected static final shortThe magic number that identifies blocks as blocks from a ChannelWriterOutputView.Fields inherited from class org.apache.flink.runtime.memory.AbstractPagedOutputView
headerLength, segmentSize -
Constructor Summary
ConstructorsConstructorDescriptionChannelWriterOutputView(BlockChannelWriter<org.apache.flink.core.memory.MemorySegment> writer, int segmentSize) Creates an new ChannelWriterOutputView that writes to the given channel.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. -
Method Summary
Modifier and TypeMethodDescriptionList<org.apache.flink.core.memory.MemorySegment>close()Closes this OutputView, closing the underlying writer and returning all memory segments.intGets the number of blocks used by this view.longGets the number of bytes used by this output view, including written bytes and header bytes.longGets the number of pay-load bytes already written.protected final org.apache.flink.core.memory.MemorySegmentnextSegment(org.apache.flink.core.memory.MemorySegment current, int posInSegment) This method must return a segment.Methods inherited from class org.apache.flink.runtime.memory.AbstractPagedOutputView
advance, clear, getCurrentPositionInSegment, getCurrentSegment, getHeaderLength, getSegmentSize, seekOutput, skipBytesToWrite, write, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Field Details
-
HEADER_MAGIC_NUMBER
protected static final short HEADER_MAGIC_NUMBERThe magic number that identifies blocks as blocks from a ChannelWriterOutputView.- See Also:
-
HEADER_LENGTH
protected static final int HEADER_LENGTHThe length of the header put into the blocks.- See Also:
-
HEADER_FLAGS_OFFSET
protected static final int HEADER_FLAGS_OFFSETThe offset to the flags in the header;- See Also:
-
HEAD_BLOCK_LENGTH_OFFSET
protected static final int HEAD_BLOCK_LENGTH_OFFSETThe offset to the header field indicating the number of bytes in the block- See Also:
-
FLAG_LAST_BLOCK
protected static final short FLAG_LAST_BLOCKThe 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
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:AbstractPagedOutputViewThis method must return a segment. If no more segments are available, it must throw anEOFException.- Specified by:
nextSegmentin classAbstractPagedOutputView- Parameters:
current- The current memory segmentposInSegment- The position in the segment, one after the last valid byte.- Returns:
- The next memory segment.
- Throws:
IOException
-