Class OperatorChain<OUT,OP extends StreamOperator<OUT>>
- Type Parameters:
OUT- The type of elements accepted by the chain, i.e., the input type of the chain's main operator.
- All Implemented Interfaces:
Closeable,AutoCloseable,BoundedMultiInput
- Direct Known Subclasses:
FinishedOperatorChain,RegularOperatorChain
OperatorChain contains all operators that are executed as one chain within a single
StreamTask.
The main entry point to the chain is it's mainOperator. mainOperator is
driving the execution of the StreamTask, by pulling the records from network inputs
and/or source inputs and pushing produced records to the remaining chained operators.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classWrapper class to access the chained sources and their's outputs. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<StreamConfig.SourceInputConfig,OperatorChain.ChainedSource> protected final org.apache.flink.shaded.guava32.com.google.common.io.Closerprotected final FinishedOnRestoreInputprotected final StreamOperatorWrapper<?,?> protected booleanprotected final WatermarkGaugeExposingOutput<StreamRecord<OUT>>protected final StreamOperatorWrapper<OUT,OP> For iteration,StreamIterationHeadandStreamIterationTailused for executing feedback edges do not contain any operators, in which case,mainOperatorWrapperandtailOperatorWrapperare null.protected final intprotected final OperatorEventDispatcherImplprotected final RecordWriterOutput<?>[]protected final StreamOperatorWrapper<?,?> -
Constructor Summary
ConstructorsConstructorDescriptionOperatorChain(StreamTask<OUT, OP> containingTask, RecordWriterDelegate<SerializationDelegate<StreamRecord<OUT>>> recordWriterDelegate) -
Method Summary
Modifier and TypeMethodDescriptionvoidabortCheckpoint(long checkpointId, CheckpointException cause) voidalignedBarrierTimeout(long checkpointId) voidbroadcastEvent(AbstractEvent event) voidbroadcastEvent(AbstractEvent event, boolean isPriorityEvent) voidclose()This method releases all resources of the record writer output.voidExecuteStreamOperator.close()of each operator in the chain of thisStreamTask.abstract voiddispatchOperatorEvent(OperatorID operator, org.apache.flink.util.SerializedValue<OperatorEvent> event) abstract voidendInput(int inputId) Ends the main operator input specified byinputId).abstract voidfinishOperators(StreamTaskActionExecutor actionExecutor, StopMode stopMode) Closes all operators in a chain effect way.voidThis method should be called before finishing the record emission, to make sure any data that is still buffered will be sent.Returns anIterablewhich traverses all operators in forward topological order.protected Iterable<StreamOperatorWrapper<?,?>> getAllOperators(boolean reverse) Returns anIterablewhich traverses all operators in forward or reverse topological order.getChainedSource(StreamConfig.SourceInputConfig sourceInput) List<Output<StreamRecord<?>>>getFinishedOnRestoreInputOrDefault(Input defaultInput) intgetSourceTaskInput(StreamConfig.SourceInputConfig sourceInput) RecordWriterOutput<?>[]protected StreamOperator<?>abstract voidinitializeStateAndOpenOperators(StreamTaskStateInitializer streamTaskStateInitializer) Initialize state and open all operators in the chain from tail to heads, contrary toStreamOperator.close()which happens heads to tail (seefinishOperators(StreamTaskActionExecutor, StopMode)).booleanisClosed()abstract booleanabstract voidnotifyCheckpointAborted(long checkpointId) abstract voidnotifyCheckpointComplete(long checkpointId) abstract voidnotifyCheckpointSubsumed(long checkpointId) abstract voidprepareSnapshotPreBarrier(long checkpointId) protected voidsendAcknowledgeCheckpointEvent(long checkpointId) protected voidsnapshotChannelStates(StreamOperator<?> op, ChannelStateWriter.ChannelStateWriteResult channelStateWriteResult, OperatorSnapshotFutures snapshotInProgress) abstract voidsnapshotState(Map<OperatorID, OperatorSnapshotFutures> operatorSnapshotsInProgress, CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions, Supplier<Boolean> isRunning, ChannelStateWriter.ChannelStateWriteResult channelStateWriteResult, CheckpointStreamFactory storage)
-
Field Details
-
streamOutputs
-
mainOperatorOutput
-
mainOperatorWrapper
@Nullable protected final StreamOperatorWrapper<OUT,OP extends StreamOperator<OUT>> mainOperatorWrapperFor iteration,StreamIterationHeadandStreamIterationTailused for executing feedback edges do not contain any operators, in which case,mainOperatorWrapperandtailOperatorWrapperare null.Usually first operator in the chain is the same as
mainOperatorWrapper, but that's not the case if there are chained source inputs. In this case, one of the source inputs will be the first operator. For example the following operator chain is possible:first \ main (multi-input) -> ... -> tail / secondWhere "first" and "second" (there can be more) are chained source operators. When it comes to things like closing, stat initialisation or state snapshotting, the operator chain is traversed: first, second, main, ..., tail or in reversed order: tail, ..., main, second, first
-
firstOperatorWrapper
-
tailOperatorWrapper
-
chainedSources
-
numOperators
protected final int numOperators -
operatorEventDispatcher
-
closer
protected final org.apache.flink.shaded.guava32.com.google.common.io.Closer closer -
finishedOnRestoreInput
-
isClosed
protected boolean isClosed
-
-
Constructor Details
-
OperatorChain
public OperatorChain(StreamTask<OUT, OP> containingTask, RecordWriterDelegate<SerializationDelegate<StreamRecord<OUT>>> recordWriterDelegate)
-
-
Method Details
-
isTaskDeployedAsFinished
public abstract boolean isTaskDeployedAsFinished() -
dispatchOperatorEvent
public abstract void dispatchOperatorEvent(OperatorID operator, org.apache.flink.util.SerializedValue<OperatorEvent> event) throws org.apache.flink.util.FlinkException - Throws:
org.apache.flink.util.FlinkException
-
prepareSnapshotPreBarrier
- Throws:
Exception
-
endInput
Ends the main operator input specified byinputId).- Specified by:
endInputin interfaceBoundedMultiInput- Parameters:
inputId- the input ID starts from 1 which indicates the first input.- Throws:
Exception
-
initializeStateAndOpenOperators
public abstract void initializeStateAndOpenOperators(StreamTaskStateInitializer streamTaskStateInitializer) throws Exception Initialize state and open all operators in the chain from tail to heads, contrary toStreamOperator.close()which happens heads to tail (seefinishOperators(StreamTaskActionExecutor, StopMode)).- Throws:
Exception
-
finishOperators
public abstract void finishOperators(StreamTaskActionExecutor actionExecutor, StopMode stopMode) throws Exception Closes all operators in a chain effect way. Closing happens from heads to tail operator in the chain, contrary toStreamOperator.open()which happens tail to heads (seeinitializeStateAndOpenOperators(StreamTaskStateInitializer)).- Throws:
Exception
-
notifyCheckpointComplete
- Throws:
Exception
-
notifyCheckpointAborted
- Throws:
Exception
-
notifyCheckpointSubsumed
- Throws:
Exception
-
snapshotState
public abstract void snapshotState(Map<OperatorID, OperatorSnapshotFutures> operatorSnapshotsInProgress, CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions, Supplier<Boolean> isRunning, ChannelStateWriter.ChannelStateWriteResult channelStateWriteResult, CheckpointStreamFactory storage) throws Exception- Throws:
Exception
-
getOperatorEventDispatcher
-
broadcastEvent
- Throws:
IOException
-
broadcastEvent
- Throws:
IOException
-
alignedBarrierTimeout
- Throws:
IOException
-
abortCheckpoint
-
closeAllOperators
ExecuteStreamOperator.close()of each operator in the chain of thisStreamTask. Closing happens from tail to head operator in the chain.- Throws:
Exception
-
getStreamOutputs
-
getAllOperators
Returns anIterablewhich traverses all operators in forward topological order. -
getAllOperators
Returns anIterablewhich traverses all operators in forward or reverse topological order. -
getFinishedOnRestoreInputOrDefault
-
getNumberOfOperators
public int getNumberOfOperators() -
getMainOperatorOutput
-
getChainedSource
-
getChainedSourceOutputs
-
getSourceTaskInput
-
getSourceTaskInputs
-
flushOutputs
This method should be called before finishing the record emission, to make sure any data that is still buffered will be sent. It also ensures that all data sending related exceptions are recognized.- Throws:
IOException- Thrown, if the buffered data cannot be pushed into the output streams.
-
close
This method releases all resources of the record writer output. It stops the output flushing thread (if there is one) and releases all buffers currently held by the output serializers.This method should never fail.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getMainOperator
-
getTailOperator
-
snapshotChannelStates
protected void snapshotChannelStates(StreamOperator<?> op, ChannelStateWriter.ChannelStateWriteResult channelStateWriteResult, OperatorSnapshotFutures snapshotInProgress) -
isClosed
public boolean isClosed() -
sendAcknowledgeCheckpointEvent
protected void sendAcknowledgeCheckpointEvent(long checkpointId)
-