Class SourceCoordinator<SplitT extends org.apache.flink.api.connector.source.SourceSplit,EnumChkT>
- All Implemented Interfaces:
AutoCloseable,org.apache.flink.api.common.state.CheckpointListener,OperatorCoordinator
OperatorCoordinator for the Source.
The SourceCoordinator provides an event loop style thread model to interact with
the Flink runtime. The coordinator ensures that all the state manipulations are made by its event
loop thread. It also helps keep track of the necessary split assignments history per subtask to
simplify the SplitEnumerator implementation.
The coordinator maintains a SplitEnumeratorContxt and shares it
with the enumerator. When the coordinator receives an action request from the Flink runtime, it
sets up the context, and calls corresponding method of the SplitEnumerator to take actions.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.apache.flink.runtime.operators.coordination.OperatorCoordinator
OperatorCoordinator.Context, OperatorCoordinator.Provider, OperatorCoordinator.SubtaskGateway -
Field Summary
Fields inherited from interface org.apache.flink.runtime.operators.coordination.OperatorCoordinator
BATCH_CHECKPOINT_ID, NO_CHECKPOINT -
Constructor Summary
ConstructorsConstructorDescriptionSourceCoordinator(String operatorName, org.apache.flink.api.connector.source.Source<?, SplitT, EnumChkT> source, SourceCoordinatorContext<SplitT> context, CoordinatorStore coordinatorStore) SourceCoordinator(org.apache.flink.api.common.JobID jobID, String operatorName, org.apache.flink.api.connector.source.Source<?, SplitT, EnumChkT> source, SourceCoordinatorContext<SplitT> context, CoordinatorStore coordinatorStore, org.apache.flink.api.common.eventtime.WatermarkAlignmentParams watermarkAlignmentParams, String coordinatorListeningID) -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckpointCoordinator(long checkpointId, CompletableFuture<byte[]> result) Takes a checkpoint of the coordinator.voidclose()This method is called when the coordinator is disposed.voidexecutionAttemptFailed(int subtaskId, int attemptNumber, Throwable reason) Called when any subtask execution attempt of the task running the coordinated operator is failed/canceled.voidexecutionAttemptReady(int subtask, int attemptNumber, OperatorCoordinator.SubtaskGateway gateway) This is called when a subtask execution attempt of the Operator becomes ready to receive events.voidhandleEventFromOperator(int subtask, int attemptNumber, OperatorEvent event) Hands an OperatorEvent coming from a parallel Operator instance (one attempt of the parallel subtasks).inferSourceParallelismAsync(int parallelismInferenceUpperBound, long dataVolumePerTask) voidnotifyCheckpointAborted(long checkpointId) We override the method here to remove the checked exception.voidnotifyCheckpointComplete(long checkpointId) We override the method here to remove the checked exception.voidresetToCheckpoint(long checkpointId, byte[] checkpointData) Resets the coordinator to the given checkpoint.voidstart()Starts the coordinator.voidsubtaskReset(int subtaskId, long checkpointId) Called if a subtask is recovered as part of a partial failover, meaning a failover handled by the scheduler's failover strategy (by default recovering a pipelined region).booleanWhether the enumerator supports batch snapshot.
-
Constructor Details
-
SourceCoordinator
public SourceCoordinator(String operatorName, org.apache.flink.api.connector.source.Source<?, SplitT, EnumChkT> source, SourceCoordinatorContext<SplitT> context, CoordinatorStore coordinatorStore) -
SourceCoordinator
public SourceCoordinator(org.apache.flink.api.common.JobID jobID, String operatorName, org.apache.flink.api.connector.source.Source<?, SplitT, EnumChkT> source, SourceCoordinatorContext<SplitT> context, CoordinatorStore coordinatorStore, org.apache.flink.api.common.eventtime.WatermarkAlignmentParams watermarkAlignmentParams, @Nullable String coordinatorListeningID)
-
-
Method Details
-
start
Description copied from interface:OperatorCoordinatorStarts the coordinator. This method is called once at the beginning, before any other methods.- Specified by:
startin interfaceOperatorCoordinator- Throws:
Exception- Any exception thrown from this method causes a full job failure.
-
close
Description copied from interface:OperatorCoordinatorThis method is called when the coordinator is disposed. This method should release currently held resources. Exceptions in this method do not cause the job to fail.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceOperatorCoordinator- Throws:
Exception
-
handleEventFromOperator
Description copied from interface:OperatorCoordinatorHands an OperatorEvent coming from a parallel Operator instance (one attempt of the parallel subtasks).- Specified by:
handleEventFromOperatorin interfaceOperatorCoordinator
-
executionAttemptFailed
Description copied from interface:OperatorCoordinatorCalled when any subtask execution attempt of the task running the coordinated operator is failed/canceled.This method is called every time an execution attempt is failed/canceled, regardless of whether there it is caused by a partial failover or a global failover.
- Specified by:
executionAttemptFailedin interfaceOperatorCoordinator
-
subtaskReset
public void subtaskReset(int subtaskId, long checkpointId) Description copied from interface:OperatorCoordinatorCalled if a subtask is recovered as part of a partial failover, meaning a failover handled by the scheduler's failover strategy (by default recovering a pipelined region). The method is invoked for each subtask involved in that partial failover.In contrast to this method, the
OperatorCoordinator.resetToCheckpoint(long, byte[])method is called in the case of a global failover, which is the case when the coordinator (JobManager) is recovered.Note that this method will not be called if an execution attempt of a subtask failed, if the subtask is not entirely failed, i.e. if the subtask has other execution attempts that are not failed/canceled.
- Specified by:
subtaskResetin interfaceOperatorCoordinator
-
executionAttemptReady
public void executionAttemptReady(int subtask, int attemptNumber, OperatorCoordinator.SubtaskGateway gateway) Description copied from interface:OperatorCoordinatorThis is called when a subtask execution attempt of the Operator becomes ready to receive events. The givenSubtaskGatewaycan be used to send events to the execution attempt.The given
SubtaskGatewayis bound to that specific execution attempt that became ready. All events sent through the gateway target that execution attempt; if the attempt is no longer running by the time the event is sent, then the events are failed.- Specified by:
executionAttemptReadyin interfaceOperatorCoordinator
-
supportsBatchSnapshot
public boolean supportsBatchSnapshot()Whether the enumerator supports batch snapshot. Note the enumerator is created either during resetting the coordinator to a checkpoint, or when the coordinator is started.- Specified by:
supportsBatchSnapshotin interfaceOperatorCoordinator
-
checkpointCoordinator
Description copied from interface:OperatorCoordinatorTakes a checkpoint of the coordinator. The checkpoint is identified by the given ID.To confirm the checkpoint and store state in it, the given
CompletableFuturemust be completed with the state. To abort or dis-confirm the checkpoint, the givenCompletableFuturemust be completed exceptionally. In any case, the givenCompletableFuturemust be completed in some way, otherwise the checkpoint will not progress.Exactly-once Semantics
The semantics are defined as follows:
- The point in time when the checkpoint future is completed is considered the point in time when the coordinator's checkpoint takes place.
- The OperatorCoordinator implementation must have a way of strictly ordering the sending of events and the completion of the checkpoint future (for example the same thread does both actions, or both actions are guarded by a mutex).
- Every event sent before the checkpoint future is completed is considered before the checkpoint.
- Every event sent after the checkpoint future is completed is considered to be after the checkpoint.
- Specified by:
checkpointCoordinatorin interfaceOperatorCoordinator
-
notifyCheckpointComplete
public void notifyCheckpointComplete(long checkpointId) Description copied from interface:OperatorCoordinatorWe override the method here to remove the checked exception. Please check the Java docs ofCheckpointListener.notifyCheckpointComplete(long)for more detail semantic of the method.- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.api.common.state.CheckpointListener- Specified by:
notifyCheckpointCompletein interfaceOperatorCoordinator
-
notifyCheckpointAborted
public void notifyCheckpointAborted(long checkpointId) Description copied from interface:OperatorCoordinatorWe override the method here to remove the checked exception. Please check the Java docs ofCheckpointListener.notifyCheckpointAborted(long)for more detail semantic of the method.- Specified by:
notifyCheckpointAbortedin interfaceorg.apache.flink.api.common.state.CheckpointListener- Specified by:
notifyCheckpointAbortedin interfaceOperatorCoordinator
-
resetToCheckpoint
Description copied from interface:OperatorCoordinatorResets the coordinator to the given checkpoint. When this method is called, the coordinator can discard all other in-flight working state. All subtasks will also have been reset to the same checkpoint.This method is called in the case of a global failover of the system, which means a failover of the coordinator (JobManager). This method is not invoked on a partial failover; partial failovers call the
OperatorCoordinator.subtaskReset(int, long)method for the involved subtasks.This method is expected to behave synchronously with respect to other method calls and calls to
Contextmethods. For example, Events being sent by the Coordinator after this method returns are assumed to take place after the checkpoint that was restored.This method is called with a null state argument in the following situations:
- There is a recovery and there was no completed checkpoint yet.
- There is a recovery from a completed checkpoint/savepoint but it contained no state for the coordinator.
In both cases, the coordinator should reset to an empty (new) state.
Restoring implicitly notifies of Checkpoint Completion
Restoring to a checkpoint is a way of confirming that the checkpoint is complete. It is safe to commit side-effects that are predicated on checkpoint completion after this call.
Even if no call to
OperatorCoordinator.notifyCheckpointComplete(long)happened, the checkpoint can still be complete (for example when a system failure happened directly after committing the checkpoint, before calling theOperatorCoordinator.notifyCheckpointComplete(long)method).- Specified by:
resetToCheckpointin interfaceOperatorCoordinator- Throws:
Exception
-
getEnumerator
-
getCoordinatorExecutor
-
inferSourceParallelismAsync
public CompletableFuture<Integer> inferSourceParallelismAsync(int parallelismInferenceUpperBound, long dataVolumePerTask)
-