Skip to content

Conversation

@GaneshPatil7517
Copy link

Purpose of the pull request

This PR moves the initialization of WorkflowGraph and WorkflowExecutionGraph from command handling to when the WorkflowStartLifecycleEvent is fired, as requested in #17751.

Brief description of changes

New Components

  • IWorkflowExecutionGraphAssembler: A functional interface for deferred WorkflowExecutionGraph assembly

Modified Components

  • WorkflowExecuteContext: Added workflowExecutionGraphAssembler field and lazy initialization support with initializeWorkflowExecutionGraph() and isWorkflowExecutionGraphInitialized() methods
  • IWorkflowExecuteContext: Added interface methods for graph initialization
  • AbstractCommandHandler: Changed to use assembler pattern - now calls createWorkflowExecutionGraphAssembler() instead of assembleWorkflowExecutionGraph()
  • Command Handlers: All handlers now return assembler lambdas instead of immediate graph creation:
    • RunWorkflowCommandHandler
    • RecoverFailureTaskCommandHandler
    • WorkflowFailoverCommandHandler
    • RecoverSerialWaitCommandHandler (returns null - no graph needed)
    • ReRunWorkflowCommandHandler (wraps parent assembler)
  • WorkflowRunningStateAction: Added graph initialization in onStartEvent() with proper exception handling that publishes WorkflowFailedLifecycleEvent on failure

Benefits

  • Reduces transaction time during command processing
  • Enables proper workflow failure handling if graph initialization fails
  • Workflow can be properly marked as failed with WorkflowFailedLifecycleEvent

Verification

  • Code compiles successfully
  • Spotless formatting applied
  • Build passes

Closes #17751
Screenshot 2026-02-05 123742

Copilot AI review requested due to automatic review settings February 5, 2026 07:08
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 5, 2026

Thanks for opening this pull request! Please check out our contributing guidelines. (https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the initialization of WorkflowGraph and WorkflowExecutionGraph to be deferred until WorkflowStartLifecycleEvent is fired, rather than during command handling. This is achieved through a new assembler pattern using the IWorkflowExecutionGraphAssembler functional interface.

Changes:

  • Introduced IWorkflowExecutionGraphAssembler interface for deferred graph assembly
  • Modified WorkflowExecuteContext to support lazy initialization of the execution graph with thread-safe double-checked locking
  • Updated all command handlers to return assembler lambdas instead of immediately creating execution graphs
  • Added graph initialization call in WorkflowRunningStateAction.onStartEvent()

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
IWorkflowExecutionGraphAssembler.java New functional interface for deferred execution graph assembly
WorkflowExecuteContext.java Added volatile field, assembler support, and lazy initialization logic with thread safety
IWorkflowExecuteContext.java Added interface methods for graph initialization
AbstractCommandHandler.java Changed to use assembler pattern, calling createWorkflowExecutionGraphAssembler instead of direct assembly
RunWorkflowCommandHandler.java Returns assembler lambda that captures necessary context and defers graph creation
RecoverFailureTaskCommandHandler.java Returns assembler lambda for failure recovery scenarios
WorkflowFailoverCommandHandler.java Returns assembler lambda for failover scenarios
RecoverSerialWaitCommandHandler.java Returns null assembler as no graph needed for serial wait recovery
ReRunWorkflowCommandHandler.java Wraps parent assembler with task instance invalidation logic
WorkflowRunningStateAction.java Calls initializeWorkflowExecutionGraph() and handles null graph case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GaneshPatil7517 GaneshPatil7517 changed the title [Improvement][Master] Initialize WorkflowGraph/WorkflowExecutionGraph when WorkflowStartLifecycleEvent fired [Improvement-17751][Master] Initialize WorkflowGraph/WorkflowExecutionGraph when WorkflowStartLifecycleEvent fired Feb 5, 2026
@ruanwenjun
Copy link
Member

It is best not to use this approach, as the command handler should not be concerned with how instances are initialized.

… when WorkflowStartLifecycleEvent fired

This commit moves the initialization of WorkflowGraph and WorkflowExecutionGraph
from command handling to when the WorkflowStartLifecycleEvent is fired.

Changes:
- Created IWorkflowExecutionGraphAssembler interface for deferred graph assembly
- Modified WorkflowExecuteContext to support lazy initialization with assembler
- Updated AbstractCommandHandler to use assembler pattern instead of direct initialization
- Modified all command handlers to create assemblers instead of immediate graphs
- Updated WorkflowRunningStateAction.onStartEvent to initialize the graph and handle failures

Benefits:
- Reduces transaction time during command processing
- Enables proper workflow failure handling if graph initialization fails
- Workflow can be properly marked as failed with WorkflowFailedLifecycleEvent

Closes apache#17751
Address reviewer feedback: command handlers should not be concerned with
how instances are initialized. Changes:

- Add WorkflowExecutionGraphFactory to centralize all graph creation logic
- Remove IWorkflowExecutionGraphAssembler interface (no longer needed)
- Remove assembleWorkflowExecutionGraphAssembler() from AbstractCommandHandler
- Remove createWorkflowExecutionGraphAssembler() from all command handlers
- Update WorkflowRunningStateAction to use factory for graph initialization
- Update IWorkflowExecuteContext: add getProject(), change to setWorkflowExecutionGraph()
- Update WorkflowExecuteContext to remove assembler, add setter

The factory handles all command-type-specific graph creation strategies:
- START_PROCESS: Fresh start with configured start nodes
- REPEAT_RUNNING: Rerun entire workflow
- START_FAILURE_TASK_PROCESS: Recover failed/paused tasks
- RECOVER_TOLERANCE_FAULT_PROCESS: Failover with existing task instances
- RECOVER_SERIAL_WAIT: Serial wait recovery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][Master] Initialize WorkflowGraph/WorkflowExecutionGraph when WorkflowStartLifecycleEvent fired.

2 participants