@NotThreadSafe public class SortBasedDataBuffer extends Object implements DataBuffer
DataBuffer 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 DataBuffer. 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.
| Constructor and Description |
|---|
SortBasedDataBuffer(BufferPool bufferPool,
int numSubpartitions,
int bufferSize,
int numGuaranteedBuffers,
int[] customReadOrder) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
append(ByteBuffer source,
int targetChannel,
Buffer.DataType dataType)
No partial record will be written to this
SortBasedDataBuffer, which means that
either all data of target record will be written or nothing will be written. |
void |
finish()
Finishes this
DataBuffer which means no record can be appended any more. |
BufferWithChannel |
getNextBuffer(org.apache.flink.core.memory.MemorySegment transitBuffer)
Copies data in this
DataBuffer to the target MemorySegment in channel index
order and returns BufferWithChannel which contains the copied data and the
corresponding channel index. |
boolean |
hasRemaining()
Returns true if not all data appended to this
DataBuffer is consumed. |
boolean |
isFinished()
Whether this
DataBuffer is finished or not. |
boolean |
isReleased()
Whether this
DataBuffer is released or not. |
long |
numTotalBytes()
Returns the total number of bytes written to this
DataBuffer. |
long |
numTotalRecords()
Returns the total number of records written to this
DataBuffer. |
void |
release()
Releases this
DataBuffer which releases all resources. |
void |
reset()
Resets this
DataBuffer to be reused for data appending. |
public SortBasedDataBuffer(BufferPool bufferPool, int numSubpartitions, int bufferSize, int numGuaranteedBuffers, @Nullable int[] customReadOrder)
public boolean append(ByteBuffer source, int targetChannel, Buffer.DataType dataType) throws IOException
SortBasedDataBuffer, which means that
either all data of target record will be written or nothing will be written.append in interface DataBufferIOExceptionpublic BufferWithChannel getNextBuffer(org.apache.flink.core.memory.MemorySegment transitBuffer)
DataBufferDataBuffer to the target MemorySegment in channel index
order and returns BufferWithChannel which contains the copied data and the
corresponding channel index.getNextBuffer in interface DataBufferpublic long numTotalRecords()
DataBufferDataBuffer.numTotalRecords in interface DataBufferpublic long numTotalBytes()
DataBufferDataBuffer.numTotalBytes in interface DataBufferpublic boolean hasRemaining()
DataBufferDataBuffer is consumed.hasRemaining in interface DataBufferpublic void reset()
DataBufferDataBuffer to be reused for data appending.reset in interface DataBufferpublic void finish()
DataBufferDataBuffer which means no record can be appended any more.finish in interface DataBufferpublic boolean isFinished()
DataBufferDataBuffer is finished or not.isFinished in interface DataBufferpublic void release()
DataBufferDataBuffer which releases all resources.release in interface DataBufferpublic boolean isReleased()
DataBufferDataBuffer is released or not.isReleased in interface DataBufferCopyright © 2014–2023 The Apache Software Foundation. All rights reserved.