Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Dolphinscheduler PhysicalTaskExecutor Lifecycle

From Leeroopedia


Knowledge Sources
Domains Task_Execution, Worker_Architecture
Last Updated 2026-02-10 00:00 GMT

Overview

Concrete tool for executing task plugins on worker nodes using PhysicalTaskExecutor with lifecycle management, state tracking, and RPC-based progress reporting.

Description

PhysicalTaskExecutor extends AbstractTaskExecutor and is built via PhysicalTaskExecutorBuilder which provides WorkerConfig, StorageOperator, and PhysicalTaskPluginFactory. It implements the full task lifecycle: plugin initialization, execution triggering with TaskCallBack for progress reporting, status tracking that maps plugin exit codes to TaskExecutorState enum values (SUCCESS, FAILED, KILLED, PAUSED), and resource cleanup.

Usage

Created by the worker's task dispatch handler when a task is received from the master. Each dispatched task gets its own PhysicalTaskExecutor instance.

Code Reference

Source Location

  • Repository: dolphinscheduler
  • File: dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/executor/PhysicalTaskExecutor.java (L43-145)

Signature

public class PhysicalTaskExecutor extends AbstractTaskExecutor {
    private AbstractTask physicalTask;
    private final PhysicalTaskPluginFactory physicalTaskPluginFactory;
    private final StorageOperator storageOperator;
    private final WorkerConfig workerConfig;

    public PhysicalTaskExecutor(PhysicalTaskExecutorBuilder builder);

    @Override
    protected void initializeTaskPlugin();
    @Override
    protected void doTriggerTaskPlugin();
    @Override
    protected TaskExecutorState doTrackTaskPluginStatus();
    @Override
    public void pause();
    @Override
    public void kill();
    @Override
    protected void finalizeTask();
}

Import

import org.apache.dolphinscheduler.server.worker.executor.PhysicalTaskExecutor;

I/O Contract

Inputs

Name Type Required Description
TaskExecutionContext Context object Yes Task type, parameters, resources, tenant info
PhysicalTaskPluginFactory Factory Yes Creates type-specific task plugin (Shell, SQL, etc.)
StorageOperator Service Yes For resource file access

Outputs

Name Type Description
TaskExecutorState Enum Final state: SUCCESS, FAILED, KILLED, or PAUSED
Lifecycle events RPC callbacks Progress and state change events sent to master

Usage Examples

Task Execution Flow

// Worker receives dispatch request and creates executor
PhysicalTaskExecutor executor = new PhysicalTaskExecutor(
    PhysicalTaskExecutorBuilder.builder()
        .workerConfig(workerConfig)
        .storageOperator(storageOperator)
        .physicalTaskPluginFactory(pluginFactory)
        .build()
);

// Lifecycle execution
executor.initializeTaskPlugin();    // Creates ShellTask, SQLTask, etc.
executor.doTriggerTaskPlugin();     // Calls plugin.handle(callback)
                                     // Reports TaskExecutorStartedLifecycleEvent

// Track completion
TaskExecutorState state = executor.doTrackTaskPluginStatus();
// state = SUCCESS -> reports TaskExecutorSuccessLifecycleEvent
// state = FAILED  -> reports TaskExecutorFailedLifecycleEvent

executor.finalizeTask();            // Cleanup resources

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment