Class OperatorCoordinatorHolder
- All Implemented Interfaces:
AutoCloseable,org.apache.flink.api.common.state.CheckpointListener,OperatorCoordinatorCheckpointContext,OperatorInfo
OperatorCoordinatorHolder holds the OperatorCoordinator and manages all its
interactions with the remaining components. It provides the context and is responsible for
checkpointing and exactly once semantics.
Exactly-one Semantics
The semantics are described under OperatorCoordinator.checkpointCoordinator(long, CompletableFuture).
Exactly-one Mechanism
The mechanism for exactly once semantics is as follows:
- Events pass through a special channel, the
SubtaskGatewayImpl. If we are not currently triggering a checkpoint, then events simply pass through. - With the completion of the checkpoint future for the coordinator, this subtask gateway is closed. Events coming after that are held back (buffered), because they belong to the epoch after the checkpoint.
- Once all coordinators in the job have completed the checkpoint, the barriers to the sources
are injected. If a coordinator receives an
AcknowledgeCheckpointEventfrom one of its subtasks, which denotes that the subtask has received the checkpoint barrier and completed checkpoint, the coordinator reopens the corresponding subtask gateway and sends out buffered events. - If a task fails in the meantime, the events are dropped from the gateways. From the coordinator's perspective, these events are lost, because they were sent to a failed subtask after it's latest complete checkpoint.
IMPORTANT: A critical assumption is that all events from the scheduler to the Tasks are transported strictly in order. Events being sent from the coordinator after the checkpoint barrier was injected must not overtake the checkpoint barrier. This is currently guaranteed by Flink's RPC mechanism.
Concurrency and Threading Model
This component runs strictly in the Scheduler's main-thread-executor. All calls "from the outside" are either already in the main-thread-executor (when coming from Scheduler) or put into the main-thread-executor (when coming from the CheckpointCoordinator). We rely on the executor to preserve strict order of the calls.
Actions from the coordinator to the "outside world" (like completing a checkpoint and sending an event) are also enqueued back into the scheduler main-thread executor, strictly in order.
-
Method Summary
Modifier and TypeMethodDescriptionvoidvoidcheckpointCoordinator(long checkpointId, CompletableFuture<byte[]> result) voidclose()static OperatorCoordinatorHoldercreate(org.apache.flink.util.SerializedValue<OperatorCoordinator.Provider> serializedProvider, ExecutionJobVertex jobVertex, ClassLoader classLoader, CoordinatorStore coordinatorStore, boolean supportsConcurrentExecutionAttempts, TaskInformation taskInformation, JobManagerJobMetricGroup metricGroup) intvoidexecutionAttemptFailed(int subtask, int attemptNumber, Throwable reason) voidhandleEventFromOperator(int subtask, int attemptNumber, OperatorEvent event) voidlazyInitialize(GlobalFailureHandler globalFailureHandler, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor mainThreadExecutor, CheckpointCoordinator checkpointCoordinator) voidlazyInitialize(GlobalFailureHandler globalFailureHandler, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor mainThreadExecutor, CheckpointCoordinator checkpointCoordinator, int operatorParallelism) intvoidnotifyCheckpointAborted(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 checkpoint with the given state.voidsetupSubtaskGatewayForAttempts(int subtask, Set<Integer> attemptNumbers) voidstart()voidsubtaskReset(int subtask, long checkpointId) Called if a task is recovered as part of a partial failover, meaning a failover handled by the scheduler's failover strategy (by default recovering a pipelined region).
-
Method Details
-
lazyInitialize
public void lazyInitialize(GlobalFailureHandler globalFailureHandler, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor mainThreadExecutor, @Nullable CheckpointCoordinator checkpointCoordinator) -
lazyInitialize
public void lazyInitialize(GlobalFailureHandler globalFailureHandler, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor mainThreadExecutor, @Nullable CheckpointCoordinator checkpointCoordinator, int operatorParallelism) -
coordinator
-
operatorId
- Specified by:
operatorIdin interfaceOperatorInfo
-
maxParallelism
public int maxParallelism()- Specified by:
maxParallelismin interfaceOperatorInfo
-
currentParallelism
public int currentParallelism()- Specified by:
currentParallelismin interfaceOperatorInfo
-
start
- Throws:
Exception
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
handleEventFromOperator
public void handleEventFromOperator(int subtask, int attemptNumber, OperatorEvent event) throws Exception - Throws:
Exception
-
executionAttemptFailed
-
subtaskReset
public void subtaskReset(int subtask, long checkpointId) Description copied from interface:OperatorCoordinatorCheckpointContextCalled if a task 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
OperatorCoordinatorCheckpointContext.resetToCheckpoint(long, byte[])method is called in the case of a global failover, which is the case when the coordinator (JobManager) is recovered.- Specified by:
subtaskResetin interfaceOperatorCoordinatorCheckpointContext
-
checkpointCoordinator
- Specified by:
checkpointCoordinatorin interfaceOperatorCoordinatorCheckpointContext
-
notifyCheckpointComplete
public void notifyCheckpointComplete(long checkpointId) Description copied from interface:OperatorCoordinatorCheckpointContextWe 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 interfaceOperatorCoordinatorCheckpointContext
-
notifyCheckpointAborted
public void notifyCheckpointAborted(long checkpointId) Description copied from interface:OperatorCoordinatorCheckpointContextWe 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 interfaceOperatorCoordinatorCheckpointContext
-
resetToCheckpoint
Description copied from interface:OperatorCoordinatorCheckpointContextResets the coordinator to the checkpoint with the given state.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.
- Specified by:
resetToCheckpointin interfaceOperatorCoordinatorCheckpointContext- Throws:
Exception
-
abortCurrentTriggering
public void abortCurrentTriggering()- Specified by:
abortCurrentTriggeringin interfaceOperatorCoordinatorCheckpointContext
-
setupSubtaskGatewayForAttempts
-
create
public static OperatorCoordinatorHolder create(org.apache.flink.util.SerializedValue<OperatorCoordinator.Provider> serializedProvider, ExecutionJobVertex jobVertex, ClassLoader classLoader, CoordinatorStore coordinatorStore, boolean supportsConcurrentExecutionAttempts, TaskInformation taskInformation, JobManagerJobMetricGroup metricGroup) throws Exception - Throws:
Exception
-