Skip to content

[Improvement-17057][Master] Check if the WorkflowGraph is a DAG at constructor#18385

Open
shangeyao wants to merge 4 commits into
apache:devfrom
shangeyao:improvement-17057-workflow-graph-dag-check
Open

[Improvement-17057][Master] Check if the WorkflowGraph is a DAG at constructor#18385
shangeyao wants to merge 4 commits into
apache:devfrom
shangeyao:improvement-17057-workflow-graph-dag-check

Conversation

@shangeyao

Copy link
Copy Markdown
Contributor

Was this PR generated or assisted by AI?

YES. Use AI to implement the DAG validation logic and unit tests, then verify locally with Maven.

Purpose of the pull request

close #17057

Brief change log

  • Add Kahn topological sort validation in WorkflowGraph constructor on the master server
  • Throw IllegalArgumentException when workflow task relations contain a cycle
  • Add WorkflowGraphCheckIfDAGTest covering single task, valid DAG, and cyclic graph cases

Verify this pull request

This change added tests and can be verified as follows:

  • Added WorkflowGraphCheckIfDAGTest to verify DAG validation in WorkflowGraph constructor
  • Ran ./mvnw -pl dolphinscheduler-master -am test -Dtest=WorkflowGraphCheckIfDAGTest -Dsurefire.failIfNoSpecifiedTests=false -Djacoco.skip=true

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

Made with Cursor

…nstructor

Validate workflow task relations with Kahn topological sort when building
WorkflowGraph on the master, so cyclic graphs fail fast before execution.

Co-authored-by: Cursor <cursoragent@cursor.com>
…r return value

Use Deque.addLast/pollFirst instead of Queue.offer/poll in DAG validation.

Co-authored-by: Cursor <cursoragent@cursor.com>
@shangeyao

Copy link
Copy Markdown
Contributor Author

Addressed CodeQL review comments in 7cbfb43: replaced Queue.offer/poll with Deque.addLast/pollFirst to avoid ignored return value warnings.

Note: dead-link CI failure is due to .github/workflows/lychee.toml parse error on include_fragments = false (unrelated to this PR). E2E job failures appear to be aggregate status from multiple unrelated E2E tests, not caused by WorkflowGraph changes.

}

if (sortedTaskCodes.size() < taskDefinitions.size()) {
throw new IllegalArgumentException("The workflow task relation is not a DAG");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Include details about the relevant tasks in the suggestion error to facilitate quick identification.

…tion error

Co-authored-by: Cursor <cursoragent@cursor.com>
@shangeyao

Copy link
Copy Markdown
Contributor Author

Addressed @det101's review in 8af98c0: the DAG validation error now includes cyclic task identifiers, e.g. The workflow task relation is not a DAG, cyclic tasks: task2(2), task3(3).

@ruanwenjun ruanwenjun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bit concerned that this implementation adds quite a bit of complexity for relatively limited benefit. It also needs to account for several edge cases, such as duplicate and invalid edges, which may increase the maintenance burden.

@shangeyao

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @ruanwenjun.

On complexity: checkIfDAG() is a standard Kahn topological sort (~50 lines), with no new edge-case rules — it reuses the same edge filter already used in addTaskEdge(). The rest of the constructor is unchanged.

Happy to extract it into a small utility class if that would be easier to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend improvement make more easy to user or prompt friendly test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][Master] Check if the WorkflowGrapth is a dag at constructor

5 participants