Class BufferWritingResultPartition
- java.lang.Object
-
- org.apache.flink.runtime.io.network.partition.ResultPartition
-
- org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition
-
- All Implemented Interfaces:
AutoCloseable
,AvailabilityProvider
,ResultPartitionWriter
- Direct Known Subclasses:
BoundedBlockingResultPartition
,PipelinedResultPartition
public abstract class BufferWritingResultPartition extends ResultPartition
AResultPartition
which writes buffers directly toResultSubpartition
s. This is in contrast to implementations where records are written to a joint structure, from which the subpartitions draw the data after the write phase is finished, for example the sort-based partitioning.To avoid confusion: On the read side, all subpartitions return buffers (and backlog) to be transported through the network.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
AvailabilityProvider.AvailabilityHelper
-
-
Field Summary
Fields Modifier and Type Field Description protected ResultSubpartition[]
subpartitions
The subpartitions of this partition.-
Fields inherited from class org.apache.flink.runtime.io.network.partition.ResultPartition
bufferCompressor, bufferPool, LOG, numBuffersOut, numBytesOut, numSubpartitions, partitionId, partitionManager, partitionType, resultPartitionBytes
-
Fields inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
AVAILABLE
-
-
Constructor Summary
Constructors Constructor Description BufferWritingResultPartition(String owningTaskName, int partitionIndex, ResultPartitionID partitionId, ResultPartitionType partitionType, ResultSubpartition[] subpartitions, int numTargetKeyGroups, ResultPartitionManager partitionManager, BufferCompressor bufferCompressor, SupplierWithException<BufferPool,IOException> bufferPoolFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abortCheckpoint(long checkpointId, CheckpointException cause)
Abort the checkpoint.protected int
addToSubpartition(int targetSubpartition, BufferConsumer bufferConsumer, int partialRecordLength)
void
alignedBarrierTimeout(long checkpointId)
Timeout the aligned barrier to unaligned barrier.void
broadcastEvent(AbstractEvent event, boolean isPriorityEvent)
Writes the givenAbstractEvent
to all subpartitions.void
broadcastRecord(ByteBuffer record)
Writes the given serialized record to all subpartitions.void
close()
Closes the partition writer which releases the allocated resource, for example the buffer pool.protected ResultSubpartitionView
createSubpartitionView(int subpartitionIndex, BufferAvailabilityListener availabilityListener)
Returns a reader for the subpartition with the given index.void
emitRecord(ByteBuffer record, int targetSubpartition)
Writes the given serialized record to the target subpartition.void
finish()
Finishes the result partition.protected void
flushAllSubpartitions(boolean finishProducers)
protected void
flushSubpartition(int targetSubpartition, boolean finishProducers)
ResultSubpartition[]
getAllPartitions()
TimerGauge
getHardBackPressuredTimeMsPerSecond()
int
getNumberOfQueuedBuffers()
Returns the total number of queued buffers of all subpartitions.int
getNumberOfQueuedBuffers(int targetSubpartition)
Returns the number of queued buffers of the given target subpartition.long
getSizeOfQueuedBuffersUnsafe()
Returns the total size in bytes of queued buffers of all subpartitions.protected void
releaseInternal()
Releases all produced data including both those stored in memory and persisted on disk.void
setMetricGroup(TaskIOMetricGroup metrics)
Sets the metric group for theResultPartitionWriter
.protected void
setupInternal()
Do the subclass's own setup operation.-
Methods inherited from class org.apache.flink.runtime.io.network.partition.ResultPartition
canBeCompressed, checkInProduceState, createSubpartitionView, fail, getAllDataProcessedFuture, getAvailableFuture, getBufferPool, getFailureCause, getNumberOfSubpartitions, getNumTargetKeyGroups, getOwningTaskName, getPartitionId, getPartitionIndex, getPartitionManager, getPartitionType, getResultPartitionBytes, isFinished, isNumberOfPartitionConsumerUndefined, isNumberOfPartitionConsumerUndefined, isReleased, notifyEndOfData, onSubpartitionAllDataProcessed, release, release, setMaxOverdraftBuffersPerGate, setup, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
isApproximatelyAvailable, isAvailable
-
Methods inherited from interface org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter
flush, flushAll
-
-
-
-
Field Detail
-
subpartitions
protected final ResultSubpartition[] subpartitions
The subpartitions of this partition. At least one.
-
-
Constructor Detail
-
BufferWritingResultPartition
public BufferWritingResultPartition(String owningTaskName, int partitionIndex, ResultPartitionID partitionId, ResultPartitionType partitionType, ResultSubpartition[] subpartitions, int numTargetKeyGroups, ResultPartitionManager partitionManager, @Nullable BufferCompressor bufferCompressor, SupplierWithException<BufferPool,IOException> bufferPoolFactory)
-
-
Method Detail
-
setupInternal
protected void setupInternal() throws IOException
Description copied from class:ResultPartition
Do the subclass's own setup operation.- Specified by:
setupInternal
in classResultPartition
- Throws:
IOException
-
getNumberOfQueuedBuffers
public int getNumberOfQueuedBuffers()
Description copied from class:ResultPartition
Returns the total number of queued buffers of all subpartitions.- Specified by:
getNumberOfQueuedBuffers
in classResultPartition
-
getSizeOfQueuedBuffersUnsafe
public long getSizeOfQueuedBuffersUnsafe()
Description copied from class:ResultPartition
Returns the total size in bytes of queued buffers of all subpartitions.- Specified by:
getSizeOfQueuedBuffersUnsafe
in classResultPartition
-
getNumberOfQueuedBuffers
public int getNumberOfQueuedBuffers(int targetSubpartition)
Description copied from class:ResultPartition
Returns the number of queued buffers of the given target subpartition.- Specified by:
getNumberOfQueuedBuffers
in classResultPartition
-
flushSubpartition
protected void flushSubpartition(int targetSubpartition, boolean finishProducers)
-
flushAllSubpartitions
protected void flushAllSubpartitions(boolean finishProducers)
-
emitRecord
public void emitRecord(ByteBuffer record, int targetSubpartition) throws IOException
Description copied from interface:ResultPartitionWriter
Writes the given serialized record to the target subpartition.- Throws:
IOException
-
broadcastRecord
public void broadcastRecord(ByteBuffer record) throws IOException
Description copied from interface:ResultPartitionWriter
Writes the given serialized record to all subpartitions. One can also achieve the same effect by emitting the same record to all subpartitions one by one, however, this method can have better performance for the underlying implementation can do some optimizations, for example coping the given serialized record only once to a shared channel which can be consumed by all subpartitions.- Throws:
IOException
-
broadcastEvent
public void broadcastEvent(AbstractEvent event, boolean isPriorityEvent) throws IOException
Description copied from interface:ResultPartitionWriter
Writes the givenAbstractEvent
to all subpartitions.- Throws:
IOException
-
alignedBarrierTimeout
public void alignedBarrierTimeout(long checkpointId) throws IOException
Description copied from interface:ResultPartitionWriter
Timeout the aligned barrier to unaligned barrier.- Throws:
IOException
-
abortCheckpoint
public void abortCheckpoint(long checkpointId, CheckpointException cause)
Description copied from interface:ResultPartitionWriter
Abort the checkpoint.
-
setMetricGroup
public void setMetricGroup(TaskIOMetricGroup metrics)
Description copied from interface:ResultPartitionWriter
Sets the metric group for theResultPartitionWriter
.- Specified by:
setMetricGroup
in interfaceResultPartitionWriter
- Overrides:
setMetricGroup
in classResultPartition
-
createSubpartitionView
protected ResultSubpartitionView createSubpartitionView(int subpartitionIndex, BufferAvailabilityListener availabilityListener) throws IOException
Description copied from class:ResultPartition
Returns a reader for the subpartition with the given index.Given that the function to merge outputs from multiple subpartition views is supported uniformly in
UnionResultSubpartitionView
, subclasses ofResultPartition
only needs to take care of creating subpartition view for a single subpartition.- Specified by:
createSubpartitionView
in classResultPartition
- Throws:
IOException
-
finish
public void finish() throws IOException
Description copied from class:ResultPartition
Finishes the result partition.After this operation, it is not possible to add further data to the result partition.
For BLOCKING results, this will trigger the deployment of consuming tasks.
- Specified by:
finish
in interfaceResultPartitionWriter
- Overrides:
finish
in classResultPartition
- Throws:
IOException
-
releaseInternal
protected void releaseInternal()
Description copied from class:ResultPartition
Releases all produced data including both those stored in memory and persisted on disk.- Specified by:
releaseInternal
in classResultPartition
-
close
public void close()
Description copied from interface:ResultPartitionWriter
Closes the partition writer which releases the allocated resource, for example the buffer pool.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceResultPartitionWriter
- Overrides:
close
in classResultPartition
-
addToSubpartition
protected int addToSubpartition(int targetSubpartition, BufferConsumer bufferConsumer, int partialRecordLength) throws IOException
- Throws:
IOException
-
getHardBackPressuredTimeMsPerSecond
@VisibleForTesting public TimerGauge getHardBackPressuredTimeMsPerSecond()
-
getAllPartitions
@VisibleForTesting public ResultSubpartition[] getAllPartitions()
-
-