public class ResultPartition extends Object implements ResultPartitionWriter, BufferPoolOwner
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, 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)
The life-cycle of each result partition has three (possibly overlapping) phases:
AvailabilityProvider.AvailabilityHelper| Modifier and Type | Field and Description |
|---|---|
protected BufferCompressor |
bufferCompressor
Used to compress buffer to reduce IO.
|
protected static org.slf4j.Logger |
LOG |
int |
numTargetKeyGroups |
protected ResultPartitionID |
partitionId |
protected ResultPartitionManager |
partitionManager |
protected ResultPartitionType |
partitionType
Type of this partition.
|
protected ResultSubpartition[] |
subpartitions
The subpartitions of this partition.
|
AVAILABLE| Constructor and Description |
|---|
ResultPartition(String owningTaskName,
ResultPartitionID partitionId,
ResultPartitionType partitionType,
ResultSubpartition[] subpartitions,
int numTargetKeyGroups,
ResultPartitionManager partitionManager,
BufferCompressor bufferCompressor,
org.apache.flink.util.function.FunctionWithException<BufferPoolOwner,BufferPool,IOException> bufferPoolFactory) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addBufferConsumer(BufferConsumer bufferConsumer,
int subpartitionIndex)
Adds the bufferConsumer to the subpartition with the given index.
|
void |
close() |
ResultSubpartitionView |
createSubpartitionView(int index,
BufferAvailabilityListener availabilityListener)
Returns the requested subpartition.
|
void |
fail(Throwable throwable)
Fail the production of the partition.
|
void |
finish()
Finishes the result partition.
|
void |
flush(int subpartitionIndex)
Manually trigger consumption from enqueued
BufferConsumers in one specified subpartition. |
void |
flushAll()
Manually trigger consumption from enqueued
BufferConsumers in all subpartitions. |
ResultSubpartition[] |
getAllPartitions() |
CompletableFuture<?> |
getAvailableFuture() |
BufferBuilder |
getBufferBuilder()
Requests a
BufferBuilder from this partition for writing data. |
BufferPool |
getBufferPool() |
Throwable |
getFailureCause() |
int |
getNumberOfQueuedBuffers() |
int |
getNumberOfSubpartitions() |
int |
getNumTargetKeyGroups() |
String |
getOwningTaskName() |
ResultPartitionID |
getPartitionId() |
ResultPartitionType |
getPartitionType()
Returns the type of this result partition.
|
boolean |
isReleased()
Whether this partition is released.
|
void |
release() |
void |
release(Throwable cause)
Releases the result partition.
|
void |
releaseMemory(int toRelease)
Releases buffers held by this result partition.
|
void |
setup()
Registers a buffer pool with this result partition.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisApproximatelyAvailable, isAvailableprotected static final org.slf4j.Logger LOG
protected final ResultPartitionID partitionId
protected final ResultPartitionType partitionType
protected final ResultSubpartition[] subpartitions
protected final ResultPartitionManager partitionManager
public final int numTargetKeyGroups
@Nullable protected final BufferCompressor bufferCompressor
public ResultPartition(String owningTaskName, ResultPartitionID partitionId, ResultPartitionType partitionType, ResultSubpartition[] subpartitions, int numTargetKeyGroups, ResultPartitionManager partitionManager, @Nullable BufferCompressor bufferCompressor, org.apache.flink.util.function.FunctionWithException<BufferPoolOwner,BufferPool,IOException> bufferPoolFactory)
public void setup()
throws IOException
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.
setup in interface ResultPartitionWriterIOExceptionpublic String getOwningTaskName()
public ResultPartitionID getPartitionId()
getPartitionId in interface ResultPartitionWriterpublic int getNumberOfSubpartitions()
getNumberOfSubpartitions in interface ResultPartitionWriterpublic BufferPool getBufferPool()
public int getNumberOfQueuedBuffers()
public ResultPartitionType getPartitionType()
public BufferBuilder getBufferBuilder() throws IOException, InterruptedException
ResultPartitionWriterBufferBuilder from this partition for writing data.getBufferBuilder in interface ResultPartitionWriterIOExceptionInterruptedExceptionpublic boolean addBufferConsumer(BufferConsumer bufferConsumer, int subpartitionIndex) throws IOException
ResultPartitionWriterThis method takes the ownership of the passed bufferConsumer and thus is responsible for releasing
it's resources.
To avoid problems with data re-ordering, before adding new BufferConsumer the previously added one
the given subpartitionIndex must be marked as BufferConsumer.isFinished().
addBufferConsumer in interface ResultPartitionWriterIOExceptionpublic void flushAll()
ResultPartitionWriterBufferConsumers in all subpartitions.flushAll in interface ResultPartitionWriterpublic void flush(int subpartitionIndex)
ResultPartitionWriterBufferConsumers in one specified subpartition.flush in interface ResultPartitionWriterpublic void finish()
throws IOException
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.
finish in interface ResultPartitionWriterIOExceptionpublic void release()
public void release(Throwable cause)
public void close()
close in interface AutoCloseablepublic void fail(@Nullable Throwable throwable)
ResultPartitionWriterThis method propagates non-null failure 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.
fail in interface ResultPartitionWriterthrowable - failure causepublic ResultSubpartitionView createSubpartitionView(int index, BufferAvailabilityListener availabilityListener) throws IOException
IOExceptionpublic Throwable getFailureCause()
public int getNumTargetKeyGroups()
getNumTargetKeyGroups in interface ResultPartitionWriterpublic void releaseMemory(int toRelease)
throws IOException
This is a callback from the buffer pool, which is registered for result partitions, which are back pressure-free.
releaseMemory in interface BufferPoolOwnerIOExceptionpublic boolean isReleased()
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.
public CompletableFuture<?> getAvailableFuture()
getAvailableFuture in interface AvailabilityProviderpublic ResultSubpartition[] getAllPartitions()
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.