Class Execution
- All Implemented Interfaces:
org.apache.flink.api.common.Archiveable<ArchivedExecution>,AccessExecution,LogicalSlot.Payload
ExecutionVertex can be executed multiple times
(for recovery, re-computation, re-configuration), this class tracks the state of a single
execution of that vertex and the resources.
Lock free state transitions
In several points of the code, we need to deal with possible concurrent state changes and actions. For example, while the call to deploy a task (send it to the TaskManager) happens, the task gets cancelled.
We could lock the entire portion of the code (decision to deploy, deploy, set state to running) such that it is guaranteed that any "cancel command" will only pick up after deployment is done and that the "cancel command" call will never overtake the deploying call.
This blocks the threads big time, because the remote calls may take long. Depending of their locking behavior, it may even result in distributed deadlocks (unless carefully avoided). We therefore use atomic state updates and occasional double-checking to ensure that the state after a completed call is as expected, and trigger correcting actions if it is not. Many actions are also idempotent (like canceling).
-
Constructor Summary
ConstructorsConstructorDescriptionExecution(Executor executor, ExecutionVertex vertex, int attemptNumber, long startTimestamp, Duration rpcTimeout) Creates a new Execution attempt. -
Method Summary
Modifier and TypeMethodDescriptionarchive()voidcancel()createResultPartitionDeploymentDescriptor(IntermediateResultPartition partition, ShuffleDescriptor shuffleDescriptor) voiddeploy()Deploys the execution to the previously assigned resource.voidThis method fails the vertex due to an external condition.Returns theTaskManagerLocationfor this execution.Returns theExecutionAttemptIDfor this Execution.intReturns the attempt number for this execution.Returns the exception that caused the job to fail.Gets a future that completes once the task execution reaches one of the statesExecutionState.INITIALIZINGorExecutionState.RUNNING.Optional<org.apache.flink.core.io.InputSplit>intReturns the subtask index of this execution.Gets the release future which is completed once the execution reaches a terminal state and the assigned resource has been released.getState()Returns the currentExecutionStatefor this execution.longReturns the end timestamp for the givenExecutionState.long[]Returns the end timestamps for everyExecutionState.longgetStateTimestamp(ExecutionState state) Returns the timestamp for the givenExecutionState.long[]Returns the timestamps for everyExecutionState.Gets a future that completes once the task execution reaches a terminal state.Returns the user-defined accumulators as strings.booleanvoidThis method marks the task as failed, but will make no attempt to remove task execution from the task manager.voidvoidnotifyCheckpointAborted(long abortCheckpointId, long latestCompletedCheckpointId, long timestamp) Notify the task of this execution about a aborted checkpoint.voidnotifyCheckpointOnComplete(long completedCheckpointId, long completedTimestamp, long lastSubsumedCheckpointId) Notify the task of this execution about a completed checkpoint and the last subsumed checkpoint id if possible.voidrecoverExecution(ExecutionAttemptID attemptId, TaskManagerLocation location, Map<String, org.apache.flink.api.common.accumulators.Accumulator<?, ?>> userAccumulators, IOMetrics metrics) Recover the execution attempt status after JM failover.voidrecoverProducedPartitions(Map<IntermediateResultPartitionID, ResultPartitionDeploymentDescriptor> producedPartitions) sendOperatorEvent(OperatorID operatorId, org.apache.flink.util.SerializedValue<OperatorEvent> event) Sends the operator event to the Task on the Task Executor.voidsetAccumulators(Map<String, org.apache.flink.api.common.accumulators.Accumulator<?, ?>> userAccumulators) Update accumulators (discarded when the Execution has already been terminated).voidsetInitialState(JobManagerTaskRestore taskRestore) Sets the initial state for the execution.suspend()toString()voidtransitionState(ExecutionState targetState) triggerCheckpoint(long checkpointId, long timestamp, CheckpointOptions checkpointOptions) Trigger a new checkpoint on the task of this execution.triggerSynchronousSavepoint(long checkpointId, long timestamp, CheckpointOptions checkpointOptions) Trigger a new checkpoint on the task of this execution.booleantryAssignResource(LogicalSlot logicalSlot) Tries to assign the given slot to the execution.
-
Constructor Details
-
Execution
public Execution(Executor executor, ExecutionVertex vertex, int attemptNumber, long startTimestamp, Duration rpcTimeout) Creates a new Execution attempt.- Parameters:
executor- The executor used to dispatch callbacks from futures and asynchronous RPC calls.vertex- The execution vertex to which this Execution belongsattemptNumber- The execution attempt number.startTimestamp- The timestamp that marks the creation of this ExecutionrpcTimeout- The rpcTimeout for RPC calls like deploy/cancel/stop.
-
-
Method Details
-
getVertex
-
getAttemptId
Description copied from interface:AccessExecutionReturns theExecutionAttemptIDfor this Execution.- Specified by:
getAttemptIdin interfaceAccessExecution- Returns:
- ExecutionAttemptID for this execution
-
getAttemptNumber
public int getAttemptNumber()Description copied from interface:AccessExecutionReturns the attempt number for this execution.- Specified by:
getAttemptNumberin interfaceAccessExecution- Returns:
- attempt number for this execution.
-
getState
Description copied from interface:AccessExecutionReturns the currentExecutionStatefor this execution.- Specified by:
getStatein interfaceAccessExecution- Returns:
- execution state for this execution
-
getAssignedAllocationID
-
getTaskManagerLocationFuture
-
getAssignedResource
-
getResultPartitionDeploymentDescriptor
public Optional<ResultPartitionDeploymentDescriptor> getResultPartitionDeploymentDescriptor(IntermediateResultPartitionID id) -
tryAssignResource
Tries to assign the given slot to the execution. The assignment works only if the Execution is in state SCHEDULED. Returns true, if the resource could be assigned.- Parameters:
logicalSlot- to assign to this execution- Returns:
- true if the slot could be assigned to the execution, otherwise false
-
getNextInputSplit
-
getAssignedResourceLocation
Description copied from interface:AccessExecutionReturns theTaskManagerLocationfor this execution.- Specified by:
getAssignedResourceLocationin interfaceAccessExecution- Returns:
- taskmanager location for this execution.
-
getFailureInfo
Description copied from interface:AccessExecutionReturns the exception that caused the job to fail. This is the first root exception that was not recoverable and triggered job failure.- Specified by:
getFailureInfoin interfaceAccessExecution- Returns:
- an
OptionalofErrorInfocontaining theThrowableand the time it was registered if an error occurred. If no error occurred an emptyOptionalwill be returned.
-
getStateTimestamps
public long[] getStateTimestamps()Description copied from interface:AccessExecutionReturns the timestamps for everyExecutionState.- Specified by:
getStateTimestampsin interfaceAccessExecution- Returns:
- timestamps for each state
-
getStateEndTimestamps
public long[] getStateEndTimestamps()Description copied from interface:AccessExecutionReturns the end timestamps for everyExecutionState.- Specified by:
getStateEndTimestampsin interfaceAccessExecution- Returns:
- timestamps for each state
-
getStateTimestamp
Description copied from interface:AccessExecutionReturns the timestamp for the givenExecutionState.- Specified by:
getStateTimestampin interfaceAccessExecution- Parameters:
state- state for which the timestamp should be returned- Returns:
- timestamp for the given state
-
getStateEndTimestamp
Description copied from interface:AccessExecutionReturns the end timestamp for the givenExecutionState.- Specified by:
getStateEndTimestampin interfaceAccessExecution- Parameters:
state- state for which the timestamp should be returned- Returns:
- timestamp for the given state
-
isFinished
public boolean isFinished() -
getTaskRestore
-
setInitialState
Sets the initial state for the execution. The serialized state is then shipped via theTaskDeploymentDescriptorto the TaskManagers.- Parameters:
taskRestore- information to restore the state
-
getInitializingOrRunningFuture
Gets a future that completes once the task execution reaches one of the statesExecutionState.INITIALIZINGorExecutionState.RUNNING. If this task never reaches these states (for example because the task is cancelled before it was properly deployed and restored), then this future will never complete.The future is completed already in the
ExecutionState.INITIALIZINGstate, because various running actions are already possible in that state (the task already accepts and sends events and network data for task recovery). (Note that in earlier versions, the INITIALIZING state was not separate but part of the RUNNING state).This future is always completed from the job master's main thread.
-
getTerminalStateFuture
Gets a future that completes once the task execution reaches a terminal state. The future will be completed with specific state that the execution reached. This future is always completed from the job master's main thread.- Specified by:
getTerminalStateFuturein interfaceLogicalSlot.Payload- Returns:
- A future which is completed once the execution reaches a terminal state
-
getReleaseFuture
Gets the release future which is completed once the execution reaches a terminal state and the assigned resource has been released. This future is always completed from the job master's main thread.- Returns:
- A future which is completed once the assigned resource has been released
-
registerProducedPartitions
-
recoverExecution
public void recoverExecution(ExecutionAttemptID attemptId, TaskManagerLocation location, Map<String, org.apache.flink.api.common.accumulators.Accumulator<?, ?>> userAccumulators, IOMetrics metrics) Recover the execution attempt status after JM failover. -
recoverProducedPartitions
public void recoverProducedPartitions(Map<IntermediateResultPartitionID, ResultPartitionDeploymentDescriptor> producedPartitions) -
createResultPartitionDeploymentDescriptor
public static ResultPartitionDeploymentDescriptor createResultPartitionDeploymentDescriptor(IntermediateResultPartition partition, ShuffleDescriptor shuffleDescriptor) -
deploy
Deploys the execution to the previously assigned resource.- Throws:
JobException- if the execution cannot be deployed to the assigned resource
-
cancel
public void cancel() -
suspend
-
fail
This method fails the vertex due to an external condition. The task will move to state FAILED. If the task was in state RUNNING or DEPLOYING before, it will send a cancel call to the TaskManager.- Specified by:
failin interfaceLogicalSlot.Payload- Parameters:
t- The exception that caused the task to fail.
-
notifyCheckpointOnComplete
public void notifyCheckpointOnComplete(long completedCheckpointId, long completedTimestamp, long lastSubsumedCheckpointId) Notify the task of this execution about a completed checkpoint and the last subsumed checkpoint id if possible.- Parameters:
completedCheckpointId- of the completed checkpointcompletedTimestamp- of the completed checkpointlastSubsumedCheckpointId- of the last subsumed checkpoint, a value ofCheckpointStoreUtil.INVALID_CHECKPOINT_IDmeans no checkpoint has been subsumed.
-
notifyCheckpointAborted
public void notifyCheckpointAborted(long abortCheckpointId, long latestCompletedCheckpointId, long timestamp) Notify the task of this execution about a aborted checkpoint.- Parameters:
abortCheckpointId- of the subsumed checkpointlatestCompletedCheckpointId- of the latest completed checkpointtimestamp- of the subsumed checkpoint
-
triggerCheckpoint
public CompletableFuture<Acknowledge> triggerCheckpoint(long checkpointId, long timestamp, CheckpointOptions checkpointOptions) Trigger a new checkpoint on the task of this execution.- Parameters:
checkpointId- of th checkpoint to triggertimestamp- of the checkpoint to triggercheckpointOptions- of the checkpoint to trigger- Returns:
- Future acknowledge which is returned once the checkpoint has been triggered
-
triggerSynchronousSavepoint
public CompletableFuture<Acknowledge> triggerSynchronousSavepoint(long checkpointId, long timestamp, CheckpointOptions checkpointOptions) Trigger a new checkpoint on the task of this execution.- Parameters:
checkpointId- of th checkpoint to triggertimestamp- of the checkpoint to triggercheckpointOptions- of the checkpoint to trigger- Returns:
- Future acknowledge which is returned once the checkpoint has been triggered
-
sendOperatorEvent
public CompletableFuture<Acknowledge> sendOperatorEvent(OperatorID operatorId, org.apache.flink.util.SerializedValue<OperatorEvent> event) Sends the operator event to the Task on the Task Executor.- Returns:
- True, of the message was sent, false is the task is currently not running.
-
markFailed
This method marks the task as failed, but will make no attempt to remove task execution from the task manager. It is intended for cases where the task is known not to be running, or then the TaskManager reports failure (in which case it has already removed the task).- Parameters:
t- The exception that caused the task to fail.
-
markFinished
@VisibleForTesting public void markFinished() -
transitionState
-
getVertexWithAttempt
-
setAccumulators
public void setAccumulators(Map<String, org.apache.flink.api.common.accumulators.Accumulator<?, ?>> userAccumulators) Update accumulators (discarded when the Execution has already been terminated).- Parameters:
userAccumulators- the user accumulators
-
getUserAccumulators
-
getUserAccumulatorsStringified
Description copied from interface:AccessExecutionReturns the user-defined accumulators as strings.- Specified by:
getUserAccumulatorsStringifiedin interfaceAccessExecution- Returns:
- user-defined accumulators as strings.
-
getParallelSubtaskIndex
public int getParallelSubtaskIndex()Description copied from interface:AccessExecutionReturns the subtask index of this execution.- Specified by:
getParallelSubtaskIndexin interfaceAccessExecution- Returns:
- subtask index of this execution.
-
getIOMetrics
- Specified by:
getIOMetricsin interfaceAccessExecution
-
toString
-
archive
- Specified by:
archivein interfaceorg.apache.flink.api.common.Archiveable<ArchivedExecution>
-