[Fix-18409][Common] Fix DAG.addEdge accepting an edge that creates a cycle when paths converge#18410
Open
nkuprins wants to merge 1 commit into
Open
[Fix-18409][Common] Fix DAG.addEdge accepting an edge that creates a cycle when paths converge#18410nkuprins wants to merge 1 commit into
nkuprins wants to merge 1 commit into
Conversation
…cycle when paths converge
|
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Was this PR generated or assisted by AI?
YES - the bug was found using AI-assisted static analysis, and the fix and regression test were AI-assisted. I verified everything myself: I confirmed the failure by running the new test against unmodified
dev(fails), reviewed the logic, and confirmed the fix (passes) with the fulldolphinscheduler-commonsuite green.Purpose of the pull request
Closes #18409.
DAG.isLegalAddEdgebounds its cycle-check BFS with a node-count budget (--verticesCount > 0) instead of tracking visited nodes. On graphs where paths converge, a node is enqueued once per incoming edge, exhausting the budget before the BFS reachesfromNode, so a cycle-creating edge is wrongly judged legal and inserted. This replaces the budget with a visited-set - the correct BFS termination condition - which cannot be defeated by path convergence and also avoids redundant re-enqueueing on dense graphs.Brief change log
common/graph/DAG.java: track visited nodes inisLegalAddEdgeinstead of a decrementingverticesCountbudget; addHashSetimport.common/graph/DAGTest.java: addtestCycleWithConvergingPaths, a fan-shaped graph asserting the cycle-creating back-edge is rejected and no cycle is introduced.Verify this pull request
This change added tests and can be verified as follows:
testCycleWithConvergingPathsfails on currentdev(addEdgereturnstruefor a cycle-creating edge) and passes with the fix.dolphinscheduler-commonsuite passes (139 tests, 0 failures) on JDK 8.