Repository navigation
fix: prevent recursion failure in data branch DAG cycles - #26139
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
5ae8e19 to
8723647
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed the complete DAG construction and query closure. The iterative parent walk terminates for cycles and deep chains, deterministically detaches exactly the cycle members, preserves non-cyclic descendant edges, and leaves FindLCA invariants valid. Focused cycle/deep-chain tests, race tests, and an additional randomized functional-graph invariant test passed. No correctness, performance, compatibility, or lifecycle blocker found.
Merge Queue Status
This pull request spent 2 hours 37 minutes 26 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review completed on 8723647b against the latest main integration state.
Additional verification beyond the existing PR tests:
- Exhaustively enumerated all 126,125 functional parent graphs with 1-6 nodes, including every combination of roots, self-cycles, multi-node cycles, multiple disconnected cycles, and acyclic prefixes/descendants.
- For every graph, verified that exactly the cycle members are detached, every retained edge preserves its original parent, all depths satisfy
child.Depth == parent.Depth + 1, every parent walk terminates, andFindLCAplusPathFromAncestormatch independent reference implementations for every node pair. - Merged the latest
mainin a detached worktree and reran the focused tests 10x plus race; all passed. - Benchmarked the defensive implementation against the base: a 4,096-node chain rises from about 0.20 ms to 0.31 ms and uses one additional O(N) visited map, while a 4,096-root forest remains at the same allocation count. This is the expected bounded-memory tradeoff for cycle detection and is not material on the branch-DAG construction path. An optional root/known-parent fast path could reduce constant CPU cost but is not a merge blocker.
No correctness, liveness, compatibility, or practical performance blocker found. Approval remains valid.
…n#26139) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#26083 ## What this PR does / why we need it: Replace recursive Data Branch DAG depth calculation with a bounded iterative parent walk. When corrupted branch metadata contains a parent cycle, all nodes in that cycle are deterministically detached and treated as roots, while non-cyclic descendants retain their valid parent edges. This prevents cyclic `mo_branch_metadata` from exhausting the process stack and also removes recursive stack growth for deep acyclic chains. The existing `NewDAG` API and ordinary LCA behavior remain unchanged. Adds a bounded child-process regression covering a two-node cycle, self-cycle, non-cyclic descendant, and a 4,096-node acyclic chain. Validation: - `go test ./pkg/frontend/databranchutils -run '^(TestNewDAGCycle|TestDAGFunctionality)$' -count=10` - `go test ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=50` - `go test -race ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=1` - `go test ./pkg/frontend/databranchutils -count=1` - `go test ./pkg/frontend -run '^$' -count=1` - `git diff --check` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…n#26139) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#26083 ## What this PR does / why we need it: Replace recursive Data Branch DAG depth calculation with a bounded iterative parent walk. When corrupted branch metadata contains a parent cycle, all nodes in that cycle are deterministically detached and treated as roots, while non-cyclic descendants retain their valid parent edges. This prevents cyclic `mo_branch_metadata` from exhausting the process stack and also removes recursive stack growth for deep acyclic chains. The existing `NewDAG` API and ordinary LCA behavior remain unchanged. Adds a bounded child-process regression covering a two-node cycle, self-cycle, non-cyclic descendant, and a 4,096-node acyclic chain. Validation: - `go test ./pkg/frontend/databranchutils -run '^(TestNewDAGCycle|TestDAGFunctionality)$' -count=10` - `go test ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=50` - `go test -race ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=1` - `go test ./pkg/frontend/databranchutils -count=1` - `go test ./pkg/frontend -run '^$' -count=1` - `git diff --check` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…n#26139) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#26083 ## What this PR does / why we need it: Replace recursive Data Branch DAG depth calculation with a bounded iterative parent walk. When corrupted branch metadata contains a parent cycle, all nodes in that cycle are deterministically detached and treated as roots, while non-cyclic descendants retain their valid parent edges. This prevents cyclic `mo_branch_metadata` from exhausting the process stack and also removes recursive stack growth for deep acyclic chains. The existing `NewDAG` API and ordinary LCA behavior remain unchanged. Adds a bounded child-process regression covering a two-node cycle, self-cycle, non-cyclic descendant, and a 4,096-node acyclic chain. Validation: - `go test ./pkg/frontend/databranchutils -run '^(TestNewDAGCycle|TestDAGFunctionality)$' -count=10` - `go test ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=50` - `go test -race ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=1` - `go test ./pkg/frontend/databranchutils -count=1` - `go test ./pkg/frontend -run '^$' -count=1` - `git diff --check` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
issue #26083
What this PR does / why we need it:
Replace recursive Data Branch DAG depth calculation with a bounded iterative
parent walk. When corrupted branch metadata contains a parent cycle, all nodes
in that cycle are deterministically detached and treated as roots, while
non-cyclic descendants retain their valid parent edges.
This prevents cyclic
mo_branch_metadatafrom exhausting the process stack andalso removes recursive stack growth for deep acyclic chains. The existing
NewDAGAPI and ordinary LCA behavior remain unchanged.Adds a bounded child-process regression covering a two-node cycle, self-cycle,
non-cyclic descendant, and a 4,096-node acyclic chain.
Validation:
go test ./pkg/frontend/databranchutils -run '^(TestNewDAGCycle|TestDAGFunctionality)$' -count=10go test ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=50go test -race ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=1go test ./pkg/frontend/databranchutils -count=1go test ./pkg/frontend -run '^$' -count=1git diff --check