Class HashBufferAccumulator
java.lang.Object
org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage.HashBufferAccumulator
- All Implemented Interfaces:
AutoCloseable,BufferAccumulator,HashSubpartitionBufferAccumulatorContext
public class HashBufferAccumulator
extends Object
implements BufferAccumulator, HashSubpartitionBufferAccumulatorContext
The hash implementation of the
BufferAccumulator. The BufferAccumulator receives
the records from TieredStorageProducerClient and the records will accumulate and
transform to finished buffers. The accumulated buffers will be transferred to the corresponding
tier dynamically.
To avoid the buffer waiting deadlock between the subpartitions, the HashBufferAccumulator requires at least n buffers (n is the number of subpartitions) to make
sure that each subpartition has at least one buffer to accumulate the receiving data. Once an
accumulated buffer is finished, the buffer will be flushed immediately.
Note that this class need not be thread-safe, because it should only be accessed from the main thread.
-
Constructor Summary
ConstructorsConstructorDescriptionHashBufferAccumulator(int numSubpartitions, int bufferSize, TieredStorageMemoryManager memoryManager, boolean isPartialRecordAllowed) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the accumulator.voidflushAccumulatedBuffers(TieredStorageSubpartitionId subpartitionId, Buffer accumulatedBuffer, int numRemainingConsecutiveBuffers) Flush the accumulatedBuffers of the subpartition.voidreceive(ByteBuffer record, TieredStorageSubpartitionId subpartitionId, Buffer.DataType dataType, boolean isBroadcast) Receives the records from tiered store producer, these records will be accumulated and transformed into finished buffers.RequestBufferBuilderfrom theBufferPool.voidsetup(org.apache.flink.util.function.TriConsumer<TieredStorageSubpartitionId, Buffer, Integer> accumulatedBufferFlusher) Setup the accumulator.
-
Constructor Details
-
HashBufferAccumulator
public HashBufferAccumulator(int numSubpartitions, int bufferSize, TieredStorageMemoryManager memoryManager, boolean isPartialRecordAllowed)
-
-
Method Details
-
setup
public void setup(org.apache.flink.util.function.TriConsumer<TieredStorageSubpartitionId, Buffer, Integer> accumulatedBufferFlusher) Description copied from interface:BufferAccumulatorSetup the accumulator.- Specified by:
setupin interfaceBufferAccumulator- Parameters:
accumulatedBufferFlusher- accepts the accumulated buffers. The first field is the subpartition id, the second is the accumulated buffer to flush, and the third is the number of remaining buffers to be written consecutively to the same segment.
-
receive
public void receive(ByteBuffer record, TieredStorageSubpartitionId subpartitionId, Buffer.DataType dataType, boolean isBroadcast) throws IOException Description copied from interface:BufferAccumulatorReceives the records from tiered store producer, these records will be accumulated and transformed into finished buffers.Note that when isBroadcast is true, for a broadcast-only partition, the subpartitionId value will always be 0. Conversely, for a non-broadcast-only partition, the subpartitionId value will range from 0 to the number of subpartitions.
- Specified by:
receivein interfaceBufferAccumulator- Parameters:
record- the received recordsubpartitionId- the subpartition id of the recorddataType- the data type of the recordisBroadcast- whether the record is a broadcast record- Throws:
IOException
-
close
public void close()Description copied from interface:BufferAccumulatorClose the accumulator. This will flush all the remaining data and release all the resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBufferAccumulator
-
requestBufferBlocking
Description copied from interface:HashSubpartitionBufferAccumulatorContextRequestBufferBuilderfrom theBufferPool.- Specified by:
requestBufferBlockingin interfaceHashSubpartitionBufferAccumulatorContext- Returns:
- the requested buffer
-
flushAccumulatedBuffers
public void flushAccumulatedBuffers(TieredStorageSubpartitionId subpartitionId, Buffer accumulatedBuffer, int numRemainingConsecutiveBuffers) Description copied from interface:HashSubpartitionBufferAccumulatorContextFlush the accumulatedBuffers of the subpartition.- Specified by:
flushAccumulatedBuffersin interfaceHashSubpartitionBufferAccumulatorContext- Parameters:
subpartitionId- the subpartition idaccumulatedBuffer- the accumulated buffernumRemainingConsecutiveBuffers- number of buffers that would be passed in the following invocations and should be written to the same segment as this one
-