Class Task
- java.lang.Object
-
- org.apache.flink.runtime.taskmanager.Task
-
- All Implemented Interfaces:
Runnable,PartitionProducerStateProvider,TaskSlotPayload,TaskActions
public class Task extends Object implements Runnable, TaskSlotPayload, TaskActions, PartitionProducerStateProvider
The Task represents one execution of a parallel subtask on a TaskManager. A Task wraps a Flink operator (which may be a user function) and runs it, providing all services necessary for example to consume input data, produce its results (intermediate result partitions) and communicate with the JobManager.The Flink operators (implemented as subclasses of
TaskInvokablehave only data readers, writers, and certain event callbacks. The task connects those to the network stack and actor messages, and tracks the state of the execution and handles exceptions.Tasks have no knowledge about how they relate to other tasks, or whether they are the first attempt to execute the task, or a repeated attempt. All of that is only known to the JobManager. All the task knows are its own runnable code, the task's configuration, and the IDs of the intermediate results to consume and produce (if any).
Each Task is run by one dedicated thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTask.NotifyCheckpointOperationVarious operation of notify checkpoint.-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.io.network.partition.PartitionProducerStateProvider
PartitionProducerStateProvider.ResponseHandle
-
-
Constructor Summary
Constructors Constructor Description Task(JobInformation jobInformation, TaskInformation taskInformation, ExecutionAttemptID executionAttemptID, AllocationID slotAllocationId, List<ResultPartitionDeploymentDescriptor> resultPartitionDeploymentDescriptors, List<InputGateDeploymentDescriptor> inputGateDeploymentDescriptors, MemoryManager memManager, SharedResources sharedResources, IOManager ioManager, ShuffleEnvironment<?,?> shuffleEnvironment, KvStateService kvStateService, BroadcastVariableManager bcVarManager, TaskEventDispatcher taskEventDispatcher, ExternalResourceInfoProvider externalResourceInfoProvider, TaskStateManager taskStateManager, TaskManagerActions taskManagerActions, InputSplitProvider inputSplitProvider, CheckpointResponder checkpointResponder, TaskOperatorEventGateway operatorCoordinatorEventGateway, GlobalAggregateManager aggregateManager, LibraryCacheManager.ClassLoaderHandle classLoaderHandle, FileCache fileCache, TaskManagerRuntimeInfo taskManagerConfig, TaskMetricGroup metricGroup, PartitionProducerStateChecker partitionProducerStateChecker, Executor executor, ChannelStateWriteRequestExecutorFactory channelStateExecutorFactory)IMPORTANT: This constructor may not start any work that would need to be undone in the case of a failing task deployment.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancelExecution()Cancels the task execution.voiddeliverOperatorEvent(OperatorID operator, org.apache.flink.util.SerializedValue<OperatorEvent> evt)Dispatches an operator event to the invokable task.voidfailExternally(Throwable cause)Marks task execution failed for an external reason (a reason other than the task code itself throwing an exception).AccumulatorRegistrygetAccumulatorRegistry()AllocationIDgetAllocationId()ThreadgetExecutingThread()ExecutionAttemptIDgetExecutionId()ExecutionStategetExecutionState()Returns the current execution state of the task.ThrowablegetFailureCause()If the task has failed, this method gets the exception that caused this task to fail.org.apache.flink.configuration.ConfigurationgetJobConfiguration()org.apache.flink.api.common.JobIDgetJobID()JobVertexIDgetJobVertexId()TaskMetricGroupgetMetricGroup()org.apache.flink.configuration.ConfigurationgetTaskConfiguration()org.apache.flink.api.common.TaskInfogetTaskInfo()CompletableFuture<ExecutionState>getTerminationFuture()booleanisBackPressured()booleanisCanceledOrFailed()Checks whether the task has failed, is canceled, or is being canceled at the moment.static voidlogTaskThreadStackTrace(Thread thread, String taskName, long timeoutMs, String action)voidnotifyCheckpointAborted(long checkpointID, long latestCompletedCheckpointId)voidnotifyCheckpointComplete(long checkpointID)voidnotifyCheckpointSubsumed(long checkpointID)voidrequestPartitionProducerState(IntermediateDataSetID intermediateDataSetId, ResultPartitionID resultPartitionId, Consumer<? super PartitionProducerStateProvider.ResponseHandle> responseConsumer)Trigger the producer execution state request.voidrun()The core work method that bootstraps the task and executes its code.static voidsetupPartitionsAndGates(ResultPartitionWriter[] producedPartitions, InputGate[] inputGates)voidstartTaskThread()Starts the task's thread.StringtoString()voidtriggerCheckpointBarrier(long checkpointID, long checkpointTimestamp, CheckpointOptions checkpointOptions)Calls the invokable to trigger a checkpoint.
-
-
-
Constructor Detail
-
Task
public Task(JobInformation jobInformation, TaskInformation taskInformation, ExecutionAttemptID executionAttemptID, AllocationID slotAllocationId, List<ResultPartitionDeploymentDescriptor> resultPartitionDeploymentDescriptors, List<InputGateDeploymentDescriptor> inputGateDeploymentDescriptors, MemoryManager memManager, SharedResources sharedResources, IOManager ioManager, ShuffleEnvironment<?,?> shuffleEnvironment, KvStateService kvStateService, BroadcastVariableManager bcVarManager, TaskEventDispatcher taskEventDispatcher, ExternalResourceInfoProvider externalResourceInfoProvider, TaskStateManager taskStateManager, TaskManagerActions taskManagerActions, InputSplitProvider inputSplitProvider, CheckpointResponder checkpointResponder, TaskOperatorEventGateway operatorCoordinatorEventGateway, GlobalAggregateManager aggregateManager, LibraryCacheManager.ClassLoaderHandle classLoaderHandle, FileCache fileCache, TaskManagerRuntimeInfo taskManagerConfig, @Nonnull TaskMetricGroup metricGroup, PartitionProducerStateChecker partitionProducerStateChecker, Executor executor, ChannelStateWriteRequestExecutorFactory channelStateExecutorFactory)
IMPORTANT: This constructor may not start any work that would need to be undone in the case of a failing task deployment.
-
-
Method Detail
-
getJobID
public org.apache.flink.api.common.JobID getJobID()
- Specified by:
getJobIDin interfaceTaskSlotPayload
-
getJobVertexId
public JobVertexID getJobVertexId()
-
getExecutionId
public ExecutionAttemptID getExecutionId()
- Specified by:
getExecutionIdin interfaceTaskSlotPayload
-
getAllocationId
public AllocationID getAllocationId()
- Specified by:
getAllocationIdin interfaceTaskSlotPayload
-
getTaskInfo
public org.apache.flink.api.common.TaskInfo getTaskInfo()
-
getJobConfiguration
public org.apache.flink.configuration.Configuration getJobConfiguration()
-
getTaskConfiguration
public org.apache.flink.configuration.Configuration getTaskConfiguration()
-
getAccumulatorRegistry
public AccumulatorRegistry getAccumulatorRegistry()
-
getMetricGroup
public TaskMetricGroup getMetricGroup()
-
getExecutingThread
public Thread getExecutingThread()
-
getTerminationFuture
public CompletableFuture<ExecutionState> getTerminationFuture()
- Specified by:
getTerminationFuturein interfaceTaskSlotPayload
-
isBackPressured
public boolean isBackPressured()
-
getExecutionState
public ExecutionState getExecutionState()
Returns the current execution state of the task.- Returns:
- The current execution state of the task.
-
isCanceledOrFailed
public boolean isCanceledOrFailed()
Checks whether the task has failed, is canceled, or is being canceled at the moment.- Returns:
- True is the task in state FAILED, CANCELING, or CANCELED, false otherwise.
-
getFailureCause
public Throwable getFailureCause()
If the task has failed, this method gets the exception that caused this task to fail. Otherwise this method returns null.- Returns:
- The exception that caused the task to fail, or null, if the task has not failed.
-
startTaskThread
public void startTaskThread()
Starts the task's thread.
-
run
public void run()
The core work method that bootstraps the task and executes its code.
-
setupPartitionsAndGates
@VisibleForTesting public static void setupPartitionsAndGates(ResultPartitionWriter[] producedPartitions, InputGate[] inputGates) throws IOException
- Throws:
IOException
-
cancelExecution
public void cancelExecution()
Cancels the task execution. If the task is already in a terminal state (such as FINISHED, CANCELED, FAILED), or if the task is already canceling this does nothing. Otherwise it sets the state to CANCELING, and, if the invokable code is running, starts an asynchronous thread that aborts that code.This method never blocks.
-
failExternally
public void failExternally(Throwable cause)
Marks task execution failed for an external reason (a reason other than the task code itself throwing an exception). If the task is already in a terminal state (such as FINISHED, CANCELED, FAILED), or if the task is already canceling this does nothing. Otherwise it sets the state to FAILED, and, if the invokable code is running, starts an asynchronous thread that aborts that code.This method never blocks.
- Specified by:
failExternallyin interfaceTaskActions- Specified by:
failExternallyin interfaceTaskSlotPayload- Parameters:
cause- of the failure
-
requestPartitionProducerState
public void requestPartitionProducerState(IntermediateDataSetID intermediateDataSetId, ResultPartitionID resultPartitionId, Consumer<? super PartitionProducerStateProvider.ResponseHandle> responseConsumer)
Description copied from interface:PartitionProducerStateProviderTrigger the producer execution state request.- Specified by:
requestPartitionProducerStatein interfacePartitionProducerStateProvider- Parameters:
intermediateDataSetId- ID of the parent intermediate data set.resultPartitionId- ID of the result partition to check. This identifies the producing execution and partition.responseConsumer- consumer for the response handle.
-
triggerCheckpointBarrier
public void triggerCheckpointBarrier(long checkpointID, long checkpointTimestamp, CheckpointOptions checkpointOptions)Calls the invokable to trigger a checkpoint.- Parameters:
checkpointID- The ID identifying the checkpoint.checkpointTimestamp- The timestamp associated with the checkpoint.checkpointOptions- Options for performing this checkpoint.
-
notifyCheckpointComplete
public void notifyCheckpointComplete(long checkpointID)
-
notifyCheckpointAborted
public void notifyCheckpointAborted(long checkpointID, long latestCompletedCheckpointId)
-
notifyCheckpointSubsumed
public void notifyCheckpointSubsumed(long checkpointID)
-
deliverOperatorEvent
public void deliverOperatorEvent(OperatorID operator, org.apache.flink.util.SerializedValue<OperatorEvent> evt) throws org.apache.flink.util.FlinkException
Dispatches an operator event to the invokable task.If the event delivery did not succeed, this method throws an exception. Callers can use that exception for error reporting, but need not react with failing this task (this method takes care of that).
- Throws:
org.apache.flink.util.FlinkException- This method throws exceptions indicating the reason why delivery did not succeed.
-
-