public abstract class AbstractInvokable extends Object
The TaskManager invokes the invoke()
method when executing a task. All operations of
the task happen in this method (setting up input output stream readers and writers as well as the
task's core operation).
All classes that extend must offer a constructor MyTask(Environment,
TaskStateSnapshot)
. Tasks that are always stateless can, for convenience, also only implement
the constructor MyTask(Environment)
.
Developer note: While constructors cannot be enforced at compile time, we did not yet
venture on the endeavor of introducing factories (it is only an internal API after all, and with
Java 8, one can use Class::new
almost like a factory lambda.
NOTE: There is no constructor that accepts and initial task state snapshot and stores it in a variable. That is on purpose, because the AbstractInvokable itself does not need the state snapshot (only subclasses such as StreamTask do need the state) and we do not want to store a reference indefinitely, thus preventing cleanup of the initial state structure by the Garbage Collector.
Any subclass that supports recoverable state and participates in checkpointing needs to
override #triggerCheckpointAsync(CheckpointMetaData, CheckpointOptions, boolean)
, triggerCheckpointOnBarrier(CheckpointMetaData, CheckpointOptions, CheckpointMetricsBuilder)
,
abortCheckpointOnBarrier(long, Throwable)
and notifyCheckpointCompleteAsync(long)
.
Constructor and Description |
---|
AbstractInvokable(Environment environment)
Create an Invokable task and set its environment.
|
Modifier and Type | Method and Description |
---|---|
void |
abortCheckpointOnBarrier(long checkpointId,
Throwable cause)
Aborts a checkpoint as the result of receiving possibly some checkpoint barriers, but at
least one
CancelCheckpointMarker . |
Future<Void> |
cancel()
This method is called when a task is canceled either as a result of a user abort or an
execution failure.
|
void |
dispatchOperatorEvent(OperatorID operator,
SerializedValue<OperatorEvent> event) |
int |
getCurrentNumberOfSubtasks()
Returns the current number of subtasks the respective task is split into.
|
Environment |
getEnvironment()
Returns the environment of this task.
|
ExecutionConfig |
getExecutionConfig()
Returns the global ExecutionConfig.
|
int |
getIndexInSubtaskGroup()
Returns the index of this subtask in the subtask group.
|
Configuration |
getJobConfiguration()
Returns the job configuration object which was attached to the original
JobGraph . |
Configuration |
getTaskConfiguration()
Returns the task configuration object which was attached to the original
JobVertex . |
ClassLoader |
getUserCodeClassLoader()
Returns the user code class loader of this invokable.
|
abstract void |
invoke()
Starts the execution.
|
Future<Void> |
notifyCheckpointAbortAsync(long checkpointId)
Invoked when a checkpoint has been aborted, i.e., when the checkpoint coordinator has
received a decline message from one task and try to abort the targeted checkpoint by
notification.
|
Future<Void> |
notifyCheckpointCompleteAsync(long checkpointId)
Invoked when a checkpoint has been completed, i.e., when the checkpoint coordinator has
received the notification from all participating tasks.
|
void |
setShouldInterruptOnCancel(boolean shouldInterruptOnCancel)
Sets whether the thread that executes the
invoke() method should be interrupted
during cancellation. |
boolean |
shouldInterruptOnCancel()
Checks whether the task should be interrupted during cancellation.
|
Future<Boolean> |
triggerCheckpointAsync(CheckpointMetaData checkpointMetaData,
CheckpointOptions checkpointOptions)
This method is called to trigger a checkpoint, asynchronously by the checkpoint coordinator.
|
void |
triggerCheckpointOnBarrier(CheckpointMetaData checkpointMetaData,
CheckpointOptions checkpointOptions,
CheckpointMetricsBuilder checkpointMetrics)
This method is called when a checkpoint is triggered as a result of receiving checkpoint
barriers on all input streams.
|
public AbstractInvokable(Environment environment)
environment
- The environment assigned to this invokable.public abstract void invoke() throws Exception
Must be overwritten by the concrete task implementation. This method is called by the task manager when the actual execution of the task starts.
All resources should be cleaned up when the method returns. Make sure to guard the code
with try-finally
blocks where necessary.
Exception
- Tasks may forward their exceptions for the TaskManager to handle through
failure/recovery.public Future<Void> cancel() throws Exception
AbstractInvokable
is fully terminated.
Note that it may never complete if the invokable is stuck.Exception
- thrown if any exception occurs during the execution of the user codepublic void setShouldInterruptOnCancel(boolean shouldInterruptOnCancel)
invoke()
method should be interrupted
during cancellation. This method sets the flag for both the initial interrupt, as well as for
the repeated interrupt. Setting the interruption to false at some point during the
cancellation procedure is a way to stop further interrupts from happening.public boolean shouldInterruptOnCancel()
setShouldInterruptOnCancel(boolean)
is a way to stop further interrupts
from happening.public final Environment getEnvironment()
public final ClassLoader getUserCodeClassLoader()
public int getCurrentNumberOfSubtasks()
public int getIndexInSubtaskGroup()
public final Configuration getTaskConfiguration()
JobVertex
.JobVertex
public Configuration getJobConfiguration()
JobGraph
.JobGraph
public ExecutionConfig getExecutionConfig()
public Future<Boolean> triggerCheckpointAsync(CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions)
This method is called for tasks that start the checkpoints by injecting the initial
barriers, i.e., the source tasks. In contrast, checkpoints on downstream operators, which are
the result of receiving checkpoint barriers, invoke the triggerCheckpointOnBarrier(CheckpointMetaData, CheckpointOptions, CheckpointMetricsBuilder)
method.
checkpointMetaData
- Meta data for about this checkpointcheckpointOptions
- Options for performing this checkpointfalse
if the checkpoint was not carried out, true
otherwisepublic void triggerCheckpointOnBarrier(CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions, CheckpointMetricsBuilder checkpointMetrics) throws IOException
checkpointMetaData
- Meta data for about this checkpointcheckpointOptions
- Options for performing this checkpointcheckpointMetrics
- Metrics about this checkpointException
- Exceptions thrown as the result of triggering a checkpoint are forwarded.IOException
public void abortCheckpointOnBarrier(long checkpointId, Throwable cause) throws IOException
CancelCheckpointMarker
.
This requires implementing tasks to forward a CancelCheckpointMarker
to their outputs.
checkpointId
- The ID of the checkpoint to be aborted.cause
- The reason why the checkpoint was aborted during alignmentIOException
public Future<Void> notifyCheckpointCompleteAsync(long checkpointId)
checkpointId
- The ID of the checkpoint that is complete.public Future<Void> notifyCheckpointAbortAsync(long checkpointId)
checkpointId
- The ID of the checkpoint that is aborted.public void dispatchOperatorEvent(OperatorID operator, SerializedValue<OperatorEvent> event) throws FlinkException
FlinkException
Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.