@NotThreadSafe public class PartitionSortedBuffer extends Object implements SortBuffer
SortBuffer implementation which sorts all appended records only by subpartition index.
Records of the same subpartition keep the appended order.
It maintains a list of MemorySegments as a joint buffer. Data will be appended to the
joint buffer sequentially. When writing a record, an index entry will be appended first. An index
entry consists of 4 fields: 4 bytes for record length, 4 bytes for Buffer.DataType and 8 bytes
for address pointing to the next index entry of the same channel which will be used to index the
next record to read when coping data from this SortBuffer. For simplicity, no index entry
can span multiple segments. The corresponding record data is seated right after its index entry
and different from the index entry, records have variable length thus may span multiple segments.
| 构造器和说明 |
|---|
PartitionSortedBuffer(BufferPool bufferPool,
int numSubpartitions,
int bufferSize,
int numGuaranteedBuffers,
int[] customReadOrder) |
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
append(ByteBuffer source,
int targetChannel,
Buffer.DataType dataType)
Appends data of the specified channel to this
SortBuffer and returns true if all
bytes of the source buffer is copied to this SortBuffer successfully, otherwise if
returns false, nothing will be copied. |
BufferWithChannel |
copyIntoSegment(org.apache.flink.core.memory.MemorySegment target)
Copies data in this
SortBuffer to the target MemorySegment in channel index
order and returns BufferWithChannel which contains the copied data and the
corresponding channel index. |
void |
finish()
Finishes this
SortBuffer which means no record can be appended any more. |
boolean |
hasRemaining()
Returns true if there is still data can be consumed in this
SortBuffer. |
boolean |
isFinished()
Whether this
SortBuffer is finished or not. |
boolean |
isReleased()
Whether this
SortBuffer is released or not. |
long |
numBytes()
Returns the number of bytes written to this
SortBuffer. |
long |
numRecords()
Returns the number of records written to this
SortBuffer. |
void |
release()
Releases this
SortBuffer which releases all resources. |
public PartitionSortedBuffer(BufferPool bufferPool, int numSubpartitions, int bufferSize, int numGuaranteedBuffers, @Nullable int[] customReadOrder)
public boolean append(ByteBuffer source, int targetChannel, Buffer.DataType dataType) throws IOException
SortBufferSortBuffer and returns true if all
bytes of the source buffer is copied to this SortBuffer successfully, otherwise if
returns false, nothing will be copied.append 在接口中 SortBufferIOExceptionpublic BufferWithChannel copyIntoSegment(org.apache.flink.core.memory.MemorySegment target)
SortBufferSortBuffer to the target MemorySegment in channel index
order and returns BufferWithChannel which contains the copied data and the
corresponding channel index.copyIntoSegment 在接口中 SortBufferpublic long numRecords()
SortBufferSortBuffer.numRecords 在接口中 SortBufferpublic long numBytes()
SortBufferSortBuffer.numBytes 在接口中 SortBufferpublic boolean hasRemaining()
SortBufferSortBuffer.hasRemaining 在接口中 SortBufferpublic void finish()
SortBufferSortBuffer which means no record can be appended any more.finish 在接口中 SortBufferpublic boolean isFinished()
SortBufferSortBuffer is finished or not.isFinished 在接口中 SortBufferpublic void release()
SortBufferSortBuffer which releases all resources.release 在接口中 SortBufferpublic boolean isReleased()
SortBufferSortBuffer is released or not.isReleased 在接口中 SortBufferCopyright © 2014–2022 The Apache Software Foundation. All rights reserved.