Class ResultPartition
- All Implemented Interfaces:
AutoCloseable,AvailabilityProvider,ResultPartitionWriter
- Direct Known Subclasses:
BufferWritingResultPartition,SortMergeResultPartition,TieredResultPartition
This class is the runtime part of a logical IntermediateResultPartition. Essentially,
a result partition is a collection of Buffer instances. The buffers are organized in one
or more ResultSubpartition instances or in a joint structure which further partition the
data depending on the number of consuming tasks and the data DistributionPattern.
Tasks, which consume a result partition have to request one of its subpartitions. The request
happens either remotely (see RemoteInputChannel) or locally (see LocalInputChannel)
Life-cycle
The life-cycle of each result partition has three (possibly overlapping) phases:
- Produce:
- Consume:
- Release:
Buffer management
State management
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
AvailabilityProvider.AvailabilityHelper -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BufferCompressorUsed to compress buffer to reduce IO.protected BufferPoolprotected static final org.slf4j.Loggerprotected org.apache.flink.metrics.Counterprotected org.apache.flink.metrics.Counterprotected final intprotected final ResultPartitionIDprotected final ResultPartitionManagerprotected final ResultPartitionTypeType of this partition.protected ResultPartitionBytesCounterFields inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
AVAILABLE -
Constructor Summary
ConstructorsConstructorDescriptionResultPartition(String owningTaskName, int partitionIndex, ResultPartitionID partitionId, ResultPartitionType partitionType, int numSubpartitions, int numTargetKeyGroups, ResultPartitionManager partitionManager, BufferCompressor bufferCompressor, org.apache.flink.util.function.SupplierWithException<BufferPool, IOException> bufferPoolFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanBeCompressed(Buffer buffer) Whether the buffer can be compressed or not.protected voidvoidclose()Closes the partition writer which releases the allocated resource, for example the buffer pool.protected abstract ResultSubpartitionViewcreateSubpartitionView(int index, BufferAvailabilityListener availabilityListener) Returns a reader for the subpartition with the given index.createSubpartitionView(ResultSubpartitionIndexSet indexSet, BufferAvailabilityListener availabilityListener) Returns a reader for the subpartition with the given index range.voidFail the production of the partition.voidfinish()Finishes the result partition.Gets the future indicating whether all the records has been processed by the downstream tasks.abstract intReturns the total number of queued buffers of all subpartitions.abstract intgetNumberOfQueuedBuffers(int targetSubpartition) Returns the number of queued buffers of the given target subpartition.intintintReturns the type of this result partition.abstract longReturns the total size in bytes of queued buffers of all subpartitions.booleanbooleanvoidisNumberOfPartitionConsumerUndefined(boolean isNumberOfPartitionConsumerUndefined) booleanWhether this partition is released.voidnotifyEndOfData(StopMode mode) Notifies the downstream tasks that thisResultPartitionWriterhave emitted all the user records.voidonSubpartitionAllDataProcessed(int subpartition) The subpartition notifies that the corresponding downstream task have processed all the user records.voidrelease()voidReleases the partition writer which releases the produced data and no reader can consume the partition any more.protected abstract voidReleases all produced data including both those stored in memory and persisted on disk.voidsetMaxOverdraftBuffersPerGate(int maxOverdraftBuffersPerGate) Sets the max overdraft buffer size of per gate.voidsetMetricGroup(TaskIOMetricGroup metrics) Sets the metric group for theResultPartitionWriter.voidsetup()Registers a buffer pool with this result partition.protected abstract voidDo the subclass's own setup operation.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
isApproximatelyAvailable, isAvailableMethods inherited from interface org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter
abortCheckpoint, alignedBarrierTimeout, broadcastEvent, broadcastRecord, emitRecord, flush, flushAll
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
partitionId
-
partitionType
Type of this partition. Defines the concrete subpartition implementation to use. -
partitionManager
-
numSubpartitions
protected final int numSubpartitions -
bufferPool
-
bufferCompressor
Used to compress buffer to reduce IO. -
numBytesOut
protected org.apache.flink.metrics.Counter numBytesOut -
numBuffersOut
protected org.apache.flink.metrics.Counter numBuffersOut -
resultPartitionBytes
-
-
Constructor Details
-
ResultPartition
public ResultPartition(String owningTaskName, int partitionIndex, ResultPartitionID partitionId, ResultPartitionType partitionType, int numSubpartitions, int numTargetKeyGroups, ResultPartitionManager partitionManager, @Nullable BufferCompressor bufferCompressor, org.apache.flink.util.function.SupplierWithException<BufferPool, IOException> bufferPoolFactory)
-
-
Method Details
-
setup
Registers a buffer pool with this result partition.There is one pool for each result partition, which is shared by all its sub partitions.
The pool is registered with the partition *after* it as been constructed in order to conform to the life-cycle of task registrations in the
TaskExecutor.- Specified by:
setupin interfaceResultPartitionWriter- Throws:
IOException
-
setupInternal
Do the subclass's own setup operation.- Throws:
IOException
-
getOwningTaskName
-
getPartitionId
- Specified by:
getPartitionIdin interfaceResultPartitionWriter
-
getPartitionIndex
public int getPartitionIndex() -
getNumberOfSubpartitions
public int getNumberOfSubpartitions()- Specified by:
getNumberOfSubpartitionsin interfaceResultPartitionWriter
-
getBufferPool
-
isNumberOfPartitionConsumerUndefined
public void isNumberOfPartitionConsumerUndefined(boolean isNumberOfPartitionConsumerUndefined) -
isNumberOfPartitionConsumerUndefined
public boolean isNumberOfPartitionConsumerUndefined() -
getNumberOfQueuedBuffers
public abstract int getNumberOfQueuedBuffers()Returns the total number of queued buffers of all subpartitions. -
getSizeOfQueuedBuffersUnsafe
public abstract long getSizeOfQueuedBuffersUnsafe()Returns the total size in bytes of queued buffers of all subpartitions. -
getNumberOfQueuedBuffers
public abstract int getNumberOfQueuedBuffers(int targetSubpartition) Returns the number of queued buffers of the given target subpartition. -
setMaxOverdraftBuffersPerGate
public void setMaxOverdraftBuffersPerGate(int maxOverdraftBuffersPerGate) Description copied from interface:ResultPartitionWriterSets the max overdraft buffer size of per gate.- Specified by:
setMaxOverdraftBuffersPerGatein interfaceResultPartitionWriter
-
getPartitionType
Returns the type of this result partition.- Returns:
- result partition type
-
getResultPartitionBytes
-
notifyEndOfData
Description copied from interface:ResultPartitionWriterNotifies the downstream tasks that thisResultPartitionWriterhave emitted all the user records.- Specified by:
notifyEndOfDatain interfaceResultPartitionWriter- Parameters:
mode- tells if we should flush all records or not (it is false in case of stop-with-savepoint (--no-drain))- Throws:
IOException
-
getAllDataProcessedFuture
Description copied from interface:ResultPartitionWriterGets the future indicating whether all the records has been processed by the downstream tasks.- Specified by:
getAllDataProcessedFuturein interfaceResultPartitionWriter
-
onSubpartitionAllDataProcessed
public void onSubpartitionAllDataProcessed(int subpartition) The subpartition notifies that the corresponding downstream task have processed all the user records.- Parameters:
subpartition- The index of the subpartition sending the notification.- See Also:
-
finish
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:
finishin interfaceResultPartitionWriter- Throws:
IOException
-
isFinished
public boolean isFinished()- Specified by:
isFinishedin interfaceResultPartitionWriter
-
release
public void release() -
release
Description copied from interface:ResultPartitionWriterReleases the partition writer which releases the produced data and no reader can consume the partition any more.- Specified by:
releasein interfaceResultPartitionWriter
-
releaseInternal
protected abstract void releaseInternal()Releases all produced data including both those stored in memory and persisted on disk. -
close
public void close()Description copied from interface:ResultPartitionWriterCloses the partition writer which releases the allocated resource, for example the buffer pool.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceResultPartitionWriter
-
fail
Description copied from interface:ResultPartitionWriterFail the production of the partition.This method propagates non-
nullfailure causes to consumers on a best-effort basis. This call also leads to the release of all resources associated with the partition. Closing of the partition is still needed afterwards if it has not been done before.- Specified by:
failin interfaceResultPartitionWriter- Parameters:
throwable- failure cause
-
getFailureCause
-
getNumTargetKeyGroups
public int getNumTargetKeyGroups()- Specified by:
getNumTargetKeyGroupsin interfaceResultPartitionWriter
-
setMetricGroup
Description copied from interface:ResultPartitionWriterSets the metric group for theResultPartitionWriter.- Specified by:
setMetricGroupin interfaceResultPartitionWriter
-
createSubpartitionView
public ResultSubpartitionView createSubpartitionView(ResultSubpartitionIndexSet indexSet, BufferAvailabilityListener availabilityListener) throws IOException Description copied from interface:ResultPartitionWriterReturns a reader for the subpartition with the given index range.- Specified by:
createSubpartitionViewin interfaceResultPartitionWriter- Throws:
IOException
-
createSubpartitionView
protected abstract ResultSubpartitionView createSubpartitionView(int index, BufferAvailabilityListener availabilityListener) throws IOException 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 ofResultPartitiononly needs to take care of creating subpartition view for a single subpartition.- Throws:
IOException
-
isReleased
public boolean isReleased()Whether this partition is released.A partition is released when each subpartition is either consumed and communication is closed by consumer or failed. A partition is also released if task is cancelled.
- Specified by:
isReleasedin interfaceResultPartitionWriter
-
getAvailableFuture
- Specified by:
getAvailableFuturein interfaceAvailabilityProvider- Returns:
- a future that is completed if the respective provider is available.
-
toString
-
checkInProduceState
- Throws:
IllegalStateException
-
getPartitionManager
-
canBeCompressed
Whether the buffer can be compressed or not. Note that event is not compressed because it is usually small and the size can become even larger after compression.
-