Skip to content

fix(dedupjoin): preserve parallel finalize failures - #26393

Merged
XuPeng-SH merged 6 commits into
mainfrom
fix/issue-26375-dedupjoin-cancellation
Jul 29, 2026
Merged

XuPeng-SH merged 6 commits into
mainfrom
fix/issue-26375-dedupjoin-cancellation

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What changed

  • preserve context cancellation and explicit worker failures during parallel dedupjoin finalization instead of reporting a successful end-of-stream
  • distinguish normal early aborts from errors and prevent incomplete unmatched-build output from escaping
  • make worker publication non-blocking and linearize it with merger shutdown so captured vectors always have exactly one owner
  • drain transferred capture state on every terminal path and retain local ownership when publication is rejected
  • keep the mailbox reusable across spill buckets and prepared executions with an all-participant Reset generation barrier
  • scope shared mailboxes to one parallel operator-duplication generation instead of mutating the reusable template

Why

The old nil message protocol represented context cancellation, channel close, and normal abort with the same value. The merger consequently swallowed cancellation and could silently omit finalize output. It also made failure cleanup and capture ownership ambiguous.

The new protocol carries an explicit abort/error status. Sender publication never waits, merger receive remains context-cancellable, and abort/error paths stop immediately without waiting for missing workers.

Tests

  • full pkg/sql/colexec/dedupjoin package
  • full pkg/sql/colexec/dedupjoin package under -race
  • focused cancellation, ownership, generation-reuse, and data-correctness tests under -race -count=100
  • pkg/sql/compile mailbox-generation duplication test
  • go vet for pkg/sql/colexec/dedupjoin and pkg/sql/compile

All new unhappy-path tests complete in milliseconds; no sleeps, retries, external services, or full-suite stress loops are used.

Fixes #26375

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner July 29, 2026 10:25
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Self-review completed on exact head e18795a763729432e1a47ee3bbbe7f34895670b3.

Found and fixed a production concurrency blocker in the original head: parallel finalize workers shared one mailbox but had no per-spill-bucket round barrier, so a fast worker could publish bucket N+1 before a slow worker published N and the merger could combine bitmaps from different buckets. The fix adds a mailbox-owned round completion channel: publication transfers ownership once, every worker waits for the merger to collect the complete round, cancellation unblocks the wait, and reset creates a fresh round. This is protocol-level synchronization, not a worker-count/test special case.

Unhappy paths covered: delayed worker, cancellation after publication, repeated Reset/Free, and abort draining. No steady-state row-processing cost was added; the extra channel synchronization happens only once per spill bucket during finalize. pkg/sql/colexec/dedupjoin and pkg/sql/compile full tests passed, plus 20x targeted -race stress. CI is running on this head.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Follow-up test-only head e039e9518bb9061e6b387f51392c24f5b92433cc strengthens the same invariant with 1 merger + 2 workers across two spill buckets: the fast worker is proven blocked until the slow worker publishes, both remain blocked until the complete round is acknowledged, then both may advance. This passed 50x under -race; production code is unchanged from the reviewed barrier fix.

@gouhongshen gouhongshen left a comment

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.

Codex automated review

No findings. The explicit mailbox protocol preserves cancellation and worker errors, prevents partial finalize output after abort, linearizes capture ownership with shutdown, bounds waits through cancellation/stop, separates spill rounds, and isolates prepared-execution generations. Local tests and vet could not run because the checkout lacks required CGo libraries and headers; the worktree remains clean.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deep-reviewed exact head 6d90f3e. No merge-blocking correctness, concurrency/lifecycle, compatibility, or normal-business regression issue was found in this diff.

The mailbox protocol has a clear ownership linearization point under the stop/send lock; all capture states retain exactly one cleanup owner. Worker waits terminate through round completion, cancellation, or merger stop, and the all-participant Reset barrier prevents a stopped generation from reopening while an old participant remains active. Dynamic error/cancellation paths stop without emitting partial unmatched-build output.

Verified all 20 added/modified focused tests individually under adaptive race stress (T below timer resolution, B=30s, N=100), full dedupjoin and compile packages under normal and race builds, plus build, vet, and diff checks. Current GitHub checks are green.

@XuPeng-SH
XuPeng-SH merged commit de42504 into main Jul 29, 2026
29 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/issue-26375-dedupjoin-cancellation branch July 29, 2026 16:10
mergify Bot pushed a commit that referenced this pull request Jul 30, 2026
…6418)

This reverts squash commit `538a45b37d7162182734c943c59bbbd723da3508` from #26331 at the author request.

The revert removes the multi-reference CTE reuse planner, query-scoped materialized source and spill path, and the associated compile/Dispatch/Merge wiring as one complete unit. Multi-reference CTEs return to independent inline planning, and sink scans use the existing streaming pipeline path.

The revert is synchronized with current `upstream/main` (`2c9608dd45960126ff3a91fc3bbb0addd53d816d`). Later overlapping fixes #26357 and #26393 remain present.

There is no SQL syntax, protobuf, public API, or persistence-format change.

### Validation

Exact head `fb1b16f27b9665203197678f385815755b143b06`:

- previous head `d693b810af44d4d9f0ae22ad3b18d68e78e6dc06`: all major functional CI jobs passed; Matrixone Utils Coverage alone failed because modified-line coverage was exactly 75%, while the gate requires strictly greater than 75%
- added `TestDispatchResetSkipsInvalidRemoteReceiversAndNotifiesHealthyPeer`, covering both nil receiver and nil error-channel guards while proving that a later healthy receiver still receives the original terminal error
- focused coverprofile: `pkg/sql/colexec/dispatch/types.go:227.33,234.14` changed from count 0 in CI to count 1 locally
- exact-head remote Coverage: PASS with 4/4 modified lines covered (`pr_coverage=1.0`, threshold `>0.75`)
- affected planner/compile/dispatch/merge package tests: PASS
- complete affected owning packages under `-race -count=1`: PASS
- focused dispatch terminal and compile sink-scan tests under `-race -count=20`: PASS
- affected package build and vet: PASS
- `git diff --check`: PASS
- exact reverse/overlap audit: only later #26357 and #26393 edits remain relative to the #26331 parent
- schema-v4 preflight: `PASS review=PASS validation=PASS`

BVT: the previous exact-head Proxy multi-CN and pessimistic BVT jobs passed. This follow-up adds package-internal unit coverage only and does not change product behavior.

### QA decision

QA required: yes. This rolls back optimizer selection and the materialized fan-out execution path. CI and environment-level analytical-query regression coverage should complete before merge.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What changed

- preserve context cancellation and explicit worker failures during
parallel `dedupjoin` finalization instead of reporting a successful
end-of-stream
- distinguish normal early aborts from errors and prevent incomplete
unmatched-build output from escaping
- make worker publication non-blocking and linearize it with merger
shutdown so captured vectors always have exactly one owner
- drain transferred capture state on every terminal path and retain
local ownership when publication is rejected
- keep the mailbox reusable across spill buckets and prepared executions
with an all-participant Reset generation barrier
- scope shared mailboxes to one parallel operator-duplication generation
instead of mutating the reusable template

## Why

The old `nil` message protocol represented context cancellation, channel
close, and normal abort with the same value. The merger consequently
swallowed cancellation and could silently omit finalize output. It also
made failure cleanup and capture ownership ambiguous.

The new protocol carries an explicit abort/error status. Sender
publication never waits, merger receive remains context-cancellable, and
abort/error paths stop immediately without waiting for missing workers.

## Tests

- full `pkg/sql/colexec/dedupjoin` package
- full `pkg/sql/colexec/dedupjoin` package under `-race`
- focused cancellation, ownership, generation-reuse, and
data-correctness tests under `-race -count=100`
- `pkg/sql/compile` mailbox-generation duplication test
- `go vet` for `pkg/sql/colexec/dedupjoin` and `pkg/sql/compile`

All new unhappy-path tests complete in milliseconds; no sleeps, retries,
external services, or full-suite stress loops are used.

Fixes matrixorigin#26375
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26331)" (matrixorigin#26418)

This reverts squash commit `538a45b37d7162182734c943c59bbbd723da3508` from matrixorigin#26331 at the author request.

The revert removes the multi-reference CTE reuse planner, query-scoped materialized source and spill path, and the associated compile/Dispatch/Merge wiring as one complete unit. Multi-reference CTEs return to independent inline planning, and sink scans use the existing streaming pipeline path.

The revert is synchronized with current `upstream/main` (`2c9608dd45960126ff3a91fc3bbb0addd53d816d`). Later overlapping fixes matrixorigin#26357 and matrixorigin#26393 remain present.

There is no SQL syntax, protobuf, public API, or persistence-format change.

### Validation

Exact head `fb1b16f27b9665203197678f385815755b143b06`:

- previous head `d693b810af44d4d9f0ae22ad3b18d68e78e6dc06`: all major functional CI jobs passed; Matrixone Utils Coverage alone failed because modified-line coverage was exactly 75%, while the gate requires strictly greater than 75%
- added `TestDispatchResetSkipsInvalidRemoteReceiversAndNotifiesHealthyPeer`, covering both nil receiver and nil error-channel guards while proving that a later healthy receiver still receives the original terminal error
- focused coverprofile: `pkg/sql/colexec/dispatch/types.go:227.33,234.14` changed from count 0 in CI to count 1 locally
- exact-head remote Coverage: PASS with 4/4 modified lines covered (`pr_coverage=1.0`, threshold `>0.75`)
- affected planner/compile/dispatch/merge package tests: PASS
- complete affected owning packages under `-race -count=1`: PASS
- focused dispatch terminal and compile sink-scan tests under `-race -count=20`: PASS
- affected package build and vet: PASS
- `git diff --check`: PASS
- exact reverse/overlap audit: only later matrixorigin#26357 and matrixorigin#26393 edits remain relative to the matrixorigin#26331 parent
- schema-v4 preflight: `PASS review=PASS validation=PASS`

BVT: the previous exact-head Proxy multi-CN and pessimistic BVT jobs passed. This follow-up adds package-internal unit coverage only and does not change product behavior.

### QA decision

QA required: yes. This rolls back optimizer selection and the materialized fan-out execution path. CI and environment-level analytical-query regression coverage should complete before merge.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What changed

- preserve context cancellation and explicit worker failures during
parallel `dedupjoin` finalization instead of reporting a successful
end-of-stream
- distinguish normal early aborts from errors and prevent incomplete
unmatched-build output from escaping
- make worker publication non-blocking and linearize it with merger
shutdown so captured vectors always have exactly one owner
- drain transferred capture state on every terminal path and retain
local ownership when publication is rejected
- keep the mailbox reusable across spill buckets and prepared executions
with an all-participant Reset generation barrier
- scope shared mailboxes to one parallel operator-duplication generation
instead of mutating the reusable template

## Why

The old `nil` message protocol represented context cancellation, channel
close, and normal abort with the same value. The merger consequently
swallowed cancellation and could silently omit finalize output. It also
made failure cleanup and capture ownership ambiguous.

The new protocol carries an explicit abort/error status. Sender
publication never waits, merger receive remains context-cancellable, and
abort/error paths stop immediately without waiting for missing workers.

## Tests

- full `pkg/sql/colexec/dedupjoin` package
- full `pkg/sql/colexec/dedupjoin` package under `-race`
- focused cancellation, ownership, generation-reuse, and
data-correctness tests under `-race -count=100`
- `pkg/sql/compile` mailbox-generation duplication test
- `go vet` for `pkg/sql/colexec/dedupjoin` and `pkg/sql/compile`

All new unhappy-path tests complete in milliseconds; no sleeps, retries,
external services, or full-suite stress loops are used.

Fixes matrixorigin#26375
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26331)" (matrixorigin#26418)

This reverts squash commit `538a45b37d7162182734c943c59bbbd723da3508` from matrixorigin#26331 at the author request.

The revert removes the multi-reference CTE reuse planner, query-scoped materialized source and spill path, and the associated compile/Dispatch/Merge wiring as one complete unit. Multi-reference CTEs return to independent inline planning, and sink scans use the existing streaming pipeline path.

The revert is synchronized with current `upstream/main` (`2c9608dd45960126ff3a91fc3bbb0addd53d816d`). Later overlapping fixes matrixorigin#26357 and matrixorigin#26393 remain present.

There is no SQL syntax, protobuf, public API, or persistence-format change.

### Validation

Exact head `fb1b16f27b9665203197678f385815755b143b06`:

- previous head `d693b810af44d4d9f0ae22ad3b18d68e78e6dc06`: all major functional CI jobs passed; Matrixone Utils Coverage alone failed because modified-line coverage was exactly 75%, while the gate requires strictly greater than 75%
- added `TestDispatchResetSkipsInvalidRemoteReceiversAndNotifiesHealthyPeer`, covering both nil receiver and nil error-channel guards while proving that a later healthy receiver still receives the original terminal error
- focused coverprofile: `pkg/sql/colexec/dispatch/types.go:227.33,234.14` changed from count 0 in CI to count 1 locally
- exact-head remote Coverage: PASS with 4/4 modified lines covered (`pr_coverage=1.0`, threshold `>0.75`)
- affected planner/compile/dispatch/merge package tests: PASS
- complete affected owning packages under `-race -count=1`: PASS
- focused dispatch terminal and compile sink-scan tests under `-race -count=20`: PASS
- affected package build and vet: PASS
- `git diff --check`: PASS
- exact reverse/overlap audit: only later matrixorigin#26357 and matrixorigin#26393 edits remain relative to the matrixorigin#26331 parent
- schema-v4 preflight: `PASS review=PASS validation=PASS`

BVT: the previous exact-head Proxy multi-CN and pessimistic BVT jobs passed. This follow-up adds package-internal unit coverage only and does not change product behavior.

### QA decision

QA required: yes. This rolls back optimizer selection and the materialized fan-out execution path. CI and environment-level analytical-query regression coverage should complete before merge.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What changed

- preserve context cancellation and explicit worker failures during
parallel `dedupjoin` finalization instead of reporting a successful
end-of-stream
- distinguish normal early aborts from errors and prevent incomplete
unmatched-build output from escaping
- make worker publication non-blocking and linearize it with merger
shutdown so captured vectors always have exactly one owner
- drain transferred capture state on every terminal path and retain
local ownership when publication is rejected
- keep the mailbox reusable across spill buckets and prepared executions
with an all-participant Reset generation barrier
- scope shared mailboxes to one parallel operator-duplication generation
instead of mutating the reusable template

## Why

The old `nil` message protocol represented context cancellation, channel
close, and normal abort with the same value. The merger consequently
swallowed cancellation and could silently omit finalize output. It also
made failure cleanup and capture ownership ambiguous.

The new protocol carries an explicit abort/error status. Sender
publication never waits, merger receive remains context-cancellable, and
abort/error paths stop immediately without waiting for missing workers.

## Tests

- full `pkg/sql/colexec/dedupjoin` package
- full `pkg/sql/colexec/dedupjoin` package under `-race`
- focused cancellation, ownership, generation-reuse, and
data-correctness tests under `-race -count=100`
- `pkg/sql/compile` mailbox-generation duplication test
- `go vet` for `pkg/sql/colexec/dedupjoin` and `pkg/sql/compile`

All new unhappy-path tests complete in milliseconds; no sleeps, retries,
external services, or full-suite stress loops are used.

Fixes matrixorigin#26375
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26331)" (matrixorigin#26418)

This reverts squash commit `538a45b37d7162182734c943c59bbbd723da3508` from matrixorigin#26331 at the author request.

The revert removes the multi-reference CTE reuse planner, query-scoped materialized source and spill path, and the associated compile/Dispatch/Merge wiring as one complete unit. Multi-reference CTEs return to independent inline planning, and sink scans use the existing streaming pipeline path.

The revert is synchronized with current `upstream/main` (`2c9608dd45960126ff3a91fc3bbb0addd53d816d`). Later overlapping fixes matrixorigin#26357 and matrixorigin#26393 remain present.

There is no SQL syntax, protobuf, public API, or persistence-format change.

### Validation

Exact head `fb1b16f27b9665203197678f385815755b143b06`:

- previous head `d693b810af44d4d9f0ae22ad3b18d68e78e6dc06`: all major functional CI jobs passed; Matrixone Utils Coverage alone failed because modified-line coverage was exactly 75%, while the gate requires strictly greater than 75%
- added `TestDispatchResetSkipsInvalidRemoteReceiversAndNotifiesHealthyPeer`, covering both nil receiver and nil error-channel guards while proving that a later healthy receiver still receives the original terminal error
- focused coverprofile: `pkg/sql/colexec/dispatch/types.go:227.33,234.14` changed from count 0 in CI to count 1 locally
- exact-head remote Coverage: PASS with 4/4 modified lines covered (`pr_coverage=1.0`, threshold `>0.75`)
- affected planner/compile/dispatch/merge package tests: PASS
- complete affected owning packages under `-race -count=1`: PASS
- focused dispatch terminal and compile sink-scan tests under `-race -count=20`: PASS
- affected package build and vet: PASS
- `git diff --check`: PASS
- exact reverse/overlap audit: only later matrixorigin#26357 and matrixorigin#26393 edits remain relative to the matrixorigin#26331 parent
- schema-v4 preflight: `PASS review=PASS validation=PASS`

BVT: the previous exact-head Proxy multi-CN and pessimistic BVT jobs passed. This follow-up adds package-internal unit coverage only and does not change product behavior.

### QA decision

QA required: yes. This rolls back optimizer selection and the materialized fan-out execution path. CI and environment-level analytical-query regression coverage should complete before merge.

Approved by: @XuPeng-SH

This branch was previously deployed

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

Labels

size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: dedupjoin finalize swallows context cancellation when a worker result is missing

4 participants