Repository navigation
fix data branch worker pool leak - #26369
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 22c687e4ac456a444658b637b670a4306151a740 after reading the author's response. The response matches the implementation: prepareDataBranchWorker now performs invalid DIFF projection and no-primary-key PICK validation before allocating the ants pool, and diffMergeAgency registers Release immediately after successful preparation. getTableStuff no longer owns allocation, and it has no other production call sites that expect a worker. This closes both early-return leaks from the previous review while preserving the producer/consumer shutdown order.
The added regressions verify no allocation on both rejected statements and a releasable worker on the valid path. Complete frontend tests pass locally, as do the DataBranch/HashDiff focused suite and the ownership/projection tests under -race -count=100; exact-head CI is green and the PR is mergeable.
|
Queued — the merge queue status continues in this comment ↓. |
|
@Mergifyio refresh |
✅ Pull request refreshed |
Merge Queue Status
This pull request spent 56 minutes 14 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #26369 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
Failing checks:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
# What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring # Which issue(s) this PR fixes: Related to #25244 # What this PR does / why we need it: ## Root cause When `DATA BRANCH DIFF` used `COLUMNS`, `resolveProjectedIdxes` returned only the requested visible columns. The row path temporarily extracted primary-key values for `OUTPUT LIMIT` sorting, but final row compaction and result-schema construction still used the requested-only list. Composite primary-key values were therefore absent from both the result rows and their metadata. `OUTPUT AS` reused the same incomplete list. The older worker-pool leak finding recorded in #25244 is already addressed on current `main` by #26369 (`09855ae9b1`) and is not changed here. ## Changes - Make the shared projection resolver emit explicit primary-key columns first in primary-key definition order, then requested non-PK visible columns in request order, with deduplication. - Reuse that effective projection for ordinary diff result rows, result metadata, and `OUTPUT AS` table schemas. - Preserve existing fake-PK/no-PK behavior and leave `COUNT`, `SUMMARY`, and `OUTPUT FILE` behavior unchanged. - Add focused unit coverage, an exact composite-PK regression BVT, related boundary assertions, and update the documented `OUTPUT AS` contract. ## Issue-to-test proof - `TestDataBranchOutputColumnsIncludeCompositePrimaryKey` asserts the exact five-column metadata (`diff`, `flag`, both PK columns, and `val`) and the exact update row values. - `TestDataBranchOutputResolveProjectedIdxes` covers normal and composite PKs, definition order different from physical order, duplicate/case-insensitive requests, unknown columns, and the fake-PK control case. Table-schema tests cover ordinary output and `OUTPUT AS` ordering. - `diff_composite_pk_columns.sql` covers the issue reproduction, partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projected `OUTPUT LIMIT`, unrelated tables, and `OUTPUT AS` metadata plus rows. - Existing `diff_11`, `diff_13`, `diff_17`, `branch_output_limit_order`, and `merge_generated_column` cases cover the broader data types, lineage depth, materialized schema, limit ordering, and generated-column interactions affected by the shared resolver. ## Tests run - `make build` - Full `pkg/frontend` CGo test package: passed. - Focused frontend regression tests: passed. - New composite-PK BVT twice with metadata comparison enabled: `28/28` each run. - Existing related BVTs: `diff_11` `158/158`; `diff_13` `137/137`; `diff_17` `154/154`; `branch_output_limit_order` `21/21`; `merge_generated_column` `80/80`; remaining branch edge cases `314/314`. The existing `diff_13`, `diff_17`, and edge/merge result files use historical metadata-width encodings that do not compare cleanly with the current tester. Those runs used `-n`, which still compared all SQL output, column names/order, and row values. The new regression result was checked twice with metadata comparison enabled. ## Residual risks For explicit-PK tables, callers using `COLUMNS` will now receive additional PK columns, in PK definition order, as required for row identity. Fake-PK/no-PK tables and non-row output modes retain their prior behavior. This change does not alter concurrency, storage, or resource-lifecycle code; #25244 remains open for manual validation. ## CI follow-up - Updated the existing `pkg/tests/dml` output-limit regression assertion to expect the retained primary-key column introduced by this fix; focused `TestDataBranchDiffAsFile` passes locally. ## Rebase follow-up - Rebased the issue branch onto origin/main at fa829e5 without conflicts or scope changes. - Re-ran the focused frontend regression tests and TestDataBranchDiffAsFile after the rebase; both passed locally.
## 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#26060 ## What this PR does / why we need it: `getTableStuff` created a per-statement ants worker pool, but the production Data Branch DIFF, MERGE, and PICK path did not originally release it. Each statement therefore retained the pool's purge and ticktock maintenance goroutines. The first fix registered pool release after the normal producer/consumer shutdown path. Review then identified two earlier exits: invalid DIFF projections and PICK statements on tables without a primary key returned before release was registered. This PR now: - validates DIFF projections and PICK primary-key requirements before allocating the pool; - creates the pool in a single preparation function; - registers `Release` immediately after successful preparation; - preserves the existing shutdown order so producers and consumers finish before release; - covers both rejected-statement paths and the valid allocation/release path. Validation: - `go test ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1` - `go test -race ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1` - `go test ./pkg/frontend -count=1` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s -run 'TestDataBranch|TestHashDiff|TestPrepareDataBranchWorker' ./pkg/frontend` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s -run 'TestPrepareDataBranchWorkerValidatesBeforeAllocation|TestDataBranchOutputValidateProjectedColumns' ./pkg/frontend` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…origin#28133) # What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring # Which issue(s) this PR fixes: Related to matrixorigin#25244 # What this PR does / why we need it: ## Root cause When `DATA BRANCH DIFF` used `COLUMNS`, `resolveProjectedIdxes` returned only the requested visible columns. The row path temporarily extracted primary-key values for `OUTPUT LIMIT` sorting, but final row compaction and result-schema construction still used the requested-only list. Composite primary-key values were therefore absent from both the result rows and their metadata. `OUTPUT AS` reused the same incomplete list. The older worker-pool leak finding recorded in matrixorigin#25244 is already addressed on current `main` by matrixorigin#26369 (`09855ae9b1`) and is not changed here. ## Changes - Make the shared projection resolver emit explicit primary-key columns first in primary-key definition order, then requested non-PK visible columns in request order, with deduplication. - Reuse that effective projection for ordinary diff result rows, result metadata, and `OUTPUT AS` table schemas. - Preserve existing fake-PK/no-PK behavior and leave `COUNT`, `SUMMARY`, and `OUTPUT FILE` behavior unchanged. - Add focused unit coverage, an exact composite-PK regression BVT, related boundary assertions, and update the documented `OUTPUT AS` contract. ## Issue-to-test proof - `TestDataBranchOutputColumnsIncludeCompositePrimaryKey` asserts the exact five-column metadata (`diff`, `flag`, both PK columns, and `val`) and the exact update row values. - `TestDataBranchOutputResolveProjectedIdxes` covers normal and composite PKs, definition order different from physical order, duplicate/case-insensitive requests, unknown columns, and the fake-PK control case. Table-schema tests cover ordinary output and `OUTPUT AS` ordering. - `diff_composite_pk_columns.sql` covers the issue reproduction, partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projected `OUTPUT LIMIT`, unrelated tables, and `OUTPUT AS` metadata plus rows. - Existing `diff_11`, `diff_13`, `diff_17`, `branch_output_limit_order`, and `merge_generated_column` cases cover the broader data types, lineage depth, materialized schema, limit ordering, and generated-column interactions affected by the shared resolver. ## Tests run - `make build` - Full `pkg/frontend` CGo test package: passed. - Focused frontend regression tests: passed. - New composite-PK BVT twice with metadata comparison enabled: `28/28` each run. - Existing related BVTs: `diff_11` `158/158`; `diff_13` `137/137`; `diff_17` `154/154`; `branch_output_limit_order` `21/21`; `merge_generated_column` `80/80`; remaining branch edge cases `314/314`. The existing `diff_13`, `diff_17`, and edge/merge result files use historical metadata-width encodings that do not compare cleanly with the current tester. Those runs used `-n`, which still compared all SQL output, column names/order, and row values. The new regression result was checked twice with metadata comparison enabled. ## Residual risks For explicit-PK tables, callers using `COLUMNS` will now receive additional PK columns, in PK definition order, as required for row identity. Fake-PK/no-PK tables and non-row output modes retain their prior behavior. This change does not alter concurrency, storage, or resource-lifecycle code; matrixorigin#25244 remains open for manual validation. ## CI follow-up - Updated the existing `pkg/tests/dml` output-limit regression assertion to expect the retained primary-key column introduced by this fix; focused `TestDataBranchDiffAsFile` passes locally. ## Rebase follow-up - Rebased the issue branch onto origin/main at fa829e5 without conflicts or scope changes. - Re-ran the focused frontend regression tests and TestDataBranchDiffAsFile after the rebase; both passed locally.
## 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#26060 ## What this PR does / why we need it: `getTableStuff` created a per-statement ants worker pool, but the production Data Branch DIFF, MERGE, and PICK path did not originally release it. Each statement therefore retained the pool's purge and ticktock maintenance goroutines. The first fix registered pool release after the normal producer/consumer shutdown path. Review then identified two earlier exits: invalid DIFF projections and PICK statements on tables without a primary key returned before release was registered. This PR now: - validates DIFF projections and PICK primary-key requirements before allocating the pool; - creates the pool in a single preparation function; - registers `Release` immediately after successful preparation; - preserves the existing shutdown order so producers and consumers finish before release; - covers both rejected-statement paths and the valid allocation/release path. Validation: - `go test ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1` - `go test -race ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1` - `go test ./pkg/frontend -count=1` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s -run 'TestDataBranch|TestHashDiff|TestPrepareDataBranchWorker' ./pkg/frontend` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s -run 'TestPrepareDataBranchWorkerValidatesBeforeAllocation|TestDataBranchOutputValidateProjectedColumns' ./pkg/frontend` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…origin#28133) # What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring # Which issue(s) this PR fixes: Related to matrixorigin#25244 # What this PR does / why we need it: ## Root cause When `DATA BRANCH DIFF` used `COLUMNS`, `resolveProjectedIdxes` returned only the requested visible columns. The row path temporarily extracted primary-key values for `OUTPUT LIMIT` sorting, but final row compaction and result-schema construction still used the requested-only list. Composite primary-key values were therefore absent from both the result rows and their metadata. `OUTPUT AS` reused the same incomplete list. The older worker-pool leak finding recorded in matrixorigin#25244 is already addressed on current `main` by matrixorigin#26369 (`09855ae9b1`) and is not changed here. ## Changes - Make the shared projection resolver emit explicit primary-key columns first in primary-key definition order, then requested non-PK visible columns in request order, with deduplication. - Reuse that effective projection for ordinary diff result rows, result metadata, and `OUTPUT AS` table schemas. - Preserve existing fake-PK/no-PK behavior and leave `COUNT`, `SUMMARY`, and `OUTPUT FILE` behavior unchanged. - Add focused unit coverage, an exact composite-PK regression BVT, related boundary assertions, and update the documented `OUTPUT AS` contract. ## Issue-to-test proof - `TestDataBranchOutputColumnsIncludeCompositePrimaryKey` asserts the exact five-column metadata (`diff`, `flag`, both PK columns, and `val`) and the exact update row values. - `TestDataBranchOutputResolveProjectedIdxes` covers normal and composite PKs, definition order different from physical order, duplicate/case-insensitive requests, unknown columns, and the fake-PK control case. Table-schema tests cover ordinary output and `OUTPUT AS` ordering. - `diff_composite_pk_columns.sql` covers the issue reproduction, partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projected `OUTPUT LIMIT`, unrelated tables, and `OUTPUT AS` metadata plus rows. - Existing `diff_11`, `diff_13`, `diff_17`, `branch_output_limit_order`, and `merge_generated_column` cases cover the broader data types, lineage depth, materialized schema, limit ordering, and generated-column interactions affected by the shared resolver. ## Tests run - `make build` - Full `pkg/frontend` CGo test package: passed. - Focused frontend regression tests: passed. - New composite-PK BVT twice with metadata comparison enabled: `28/28` each run. - Existing related BVTs: `diff_11` `158/158`; `diff_13` `137/137`; `diff_17` `154/154`; `branch_output_limit_order` `21/21`; `merge_generated_column` `80/80`; remaining branch edge cases `314/314`. The existing `diff_13`, `diff_17`, and edge/merge result files use historical metadata-width encodings that do not compare cleanly with the current tester. Those runs used `-n`, which still compared all SQL output, column names/order, and row values. The new regression result was checked twice with metadata comparison enabled. ## Residual risks For explicit-PK tables, callers using `COLUMNS` will now receive additional PK columns, in PK definition order, as required for row identity. Fake-PK/no-PK tables and non-row output modes retain their prior behavior. This change does not alter concurrency, storage, or resource-lifecycle code; matrixorigin#25244 remains open for manual validation. ## CI follow-up - Updated the existing `pkg/tests/dml` output-limit regression assertion to expect the retained primary-key column introduced by this fix; focused `TestDataBranchDiffAsFile` passes locally. ## Rebase follow-up - Rebased the issue branch onto origin/main at fa829e5 without conflicts or scope changes. - Re-ran the focused frontend regression tests and TestDataBranchDiffAsFile after the rebase; both passed locally.
## 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#26060 ## What this PR does / why we need it: `getTableStuff` created a per-statement ants worker pool, but the production Data Branch DIFF, MERGE, and PICK path did not originally release it. Each statement therefore retained the pool's purge and ticktock maintenance goroutines. The first fix registered pool release after the normal producer/consumer shutdown path. Review then identified two earlier exits: invalid DIFF projections and PICK statements on tables without a primary key returned before release was registered. This PR now: - validates DIFF projections and PICK primary-key requirements before allocating the pool; - creates the pool in a single preparation function; - registers `Release` immediately after successful preparation; - preserves the existing shutdown order so producers and consumers finish before release; - covers both rejected-statement paths and the valid allocation/release path. Validation: - `go test ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1` - `go test -race ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1` - `go test ./pkg/frontend -count=1` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s -run 'TestDataBranch|TestHashDiff|TestPrepareDataBranchWorker' ./pkg/frontend` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s -run 'TestPrepareDataBranchWorkerValidatesBeforeAllocation|TestDataBranchOutputValidateProjectedColumns' ./pkg/frontend` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…origin#28133) # What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring # Which issue(s) this PR fixes: Related to matrixorigin#25244 # What this PR does / why we need it: ## Root cause When `DATA BRANCH DIFF` used `COLUMNS`, `resolveProjectedIdxes` returned only the requested visible columns. The row path temporarily extracted primary-key values for `OUTPUT LIMIT` sorting, but final row compaction and result-schema construction still used the requested-only list. Composite primary-key values were therefore absent from both the result rows and their metadata. `OUTPUT AS` reused the same incomplete list. The older worker-pool leak finding recorded in matrixorigin#25244 is already addressed on current `main` by matrixorigin#26369 (`09855ae9b1`) and is not changed here. ## Changes - Make the shared projection resolver emit explicit primary-key columns first in primary-key definition order, then requested non-PK visible columns in request order, with deduplication. - Reuse that effective projection for ordinary diff result rows, result metadata, and `OUTPUT AS` table schemas. - Preserve existing fake-PK/no-PK behavior and leave `COUNT`, `SUMMARY`, and `OUTPUT FILE` behavior unchanged. - Add focused unit coverage, an exact composite-PK regression BVT, related boundary assertions, and update the documented `OUTPUT AS` contract. ## Issue-to-test proof - `TestDataBranchOutputColumnsIncludeCompositePrimaryKey` asserts the exact five-column metadata (`diff`, `flag`, both PK columns, and `val`) and the exact update row values. - `TestDataBranchOutputResolveProjectedIdxes` covers normal and composite PKs, definition order different from physical order, duplicate/case-insensitive requests, unknown columns, and the fake-PK control case. Table-schema tests cover ordinary output and `OUTPUT AS` ordering. - `diff_composite_pk_columns.sql` covers the issue reproduction, partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projected `OUTPUT LIMIT`, unrelated tables, and `OUTPUT AS` metadata plus rows. - Existing `diff_11`, `diff_13`, `diff_17`, `branch_output_limit_order`, and `merge_generated_column` cases cover the broader data types, lineage depth, materialized schema, limit ordering, and generated-column interactions affected by the shared resolver. ## Tests run - `make build` - Full `pkg/frontend` CGo test package: passed. - Focused frontend regression tests: passed. - New composite-PK BVT twice with metadata comparison enabled: `28/28` each run. - Existing related BVTs: `diff_11` `158/158`; `diff_13` `137/137`; `diff_17` `154/154`; `branch_output_limit_order` `21/21`; `merge_generated_column` `80/80`; remaining branch edge cases `314/314`. The existing `diff_13`, `diff_17`, and edge/merge result files use historical metadata-width encodings that do not compare cleanly with the current tester. Those runs used `-n`, which still compared all SQL output, column names/order, and row values. The new regression result was checked twice with metadata comparison enabled. ## Residual risks For explicit-PK tables, callers using `COLUMNS` will now receive additional PK columns, in PK definition order, as required for row identity. Fake-PK/no-PK tables and non-row output modes retain their prior behavior. This change does not alter concurrency, storage, or resource-lifecycle code; matrixorigin#25244 remains open for manual validation. ## CI follow-up - Updated the existing `pkg/tests/dml` output-limit regression assertion to expect the retained primary-key column introduced by this fix; focused `TestDataBranchDiffAsFile` passes locally. ## Rebase follow-up - Rebased the issue branch onto origin/main at fa829e5 without conflicts or scope changes. - Re-ran the focused frontend regression tests and TestDataBranchDiffAsFile after the rebase; both passed locally.
What type of PR is this?
Which issue(s) this PR fixes:
issue #26060
What this PR does / why we need it:
getTableStuffcreated a per-statement ants worker pool, but the production Data Branch DIFF, MERGE, and PICK path did not originally release it. Each statement therefore retained the pool's purge and ticktock maintenance goroutines.The first fix registered pool release after the normal producer/consumer shutdown path. Review then identified two earlier exits: invalid DIFF projections and PICK statements on tables without a primary key returned before release was registered.
This PR now:
Releaseimmediately after successful preparation;Validation:
go test ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1go test -race ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1go test ./pkg/frontend -count=1.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s -run 'TestDataBranch|TestHashDiff|TestPrepareDataBranchWorker' ./pkg/frontend.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s -run 'TestPrepareDataBranchWorkerValidatesBeforeAllocation|TestDataBranchOutputValidateProjectedColumns' ./pkg/frontend