Skip to content

fix(compile): retain shared broadcast producers across consumer retirement - #29666

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/metadata-join-producer-owner-20261007
Oct 8, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/metadata-join-producer-owner-20261007

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

Summary

This is a small follow-up to the shared broadcast producer ownership work.
When several independent broadcast probe scopes share one CN, a HashBuild/map
and its build source must be owned by their common result region, not by the
first consumer. That consumer may end normally without calling its child while
a peer still needs the shared build.

Reuse the existing producer-region protocol for repeated-CN HashJoin/LoopJoin
probe groups. Keep single/packed scopes, unique-CN non-Product scopes,
IndexJoin, ProductL2, DedupJoin and RightDedupJoin unchanged. Do not change JOIN
semantics, probe placement, result receiver order, scan count, cancellation
normalization, or add global
serialization. Existing Product ownership remains unchanged; the already
computed groups are reused rather than calculated twice.

The extension is deliberately limited to HashJoin/LoopJoin. Other HashBuild
operators also have related structure, but their repeated-CN lifecycle has
not been reproduced and is not changed by this PR. HashJoin's JOIN-type
variants use the same ownership protocol; their algorithms are unchanged.
The new runtime RED/GREEN is specifically
equi INNER HashJoin and non-equi INNER LoopJoin, not a claim that every
operator/type was reproduced in this topology
. Existing owning-package
tests validate the unchanged operator/compiler contracts separately.

The existing producer-region helper runs Dispatch at the coordinator. An
eligible remote build source may therefore acquire one additional coordinator
Merge relay. Scan count and probe placement are preserved, but this PR does
not claim that every source/network placement is identical or that public
SQL performance in this remote-source domain has been A/B validated.

Deterministic contract evidence

The regression fixture uses real compiler probe/build assembly, finalized
producer ownership, pipeline context initialization and MergeRun. Two
independent colocated HashJoin/LoopJoin probes consume the same build. A real
outer broadcast INNER join with an empty map normally skips one consumer,
while the peer still requires three build rows. The first consumer's cause is
asserted to be ErrPipelineStopped, and the query parent remains live.

On the untouched base, normal consumer cleanup cancels the still-required
shared source. With the fix, the peer returns the exact expected result.
Additional cases cover first/last skipped consumers, empty peer, all consumers
skipped, empty build, original build error, partial output then panic, query
cancel/deadline, ancestor normal stop, and normal/cancelled execution followed
by Scope.Reset with a fresh allocation-account/pipeline generation.
The reuse test retains internal operator templates; it does not assert that AP
prepared SQL is supported.

Every scenario joins workers and drains board/spool ownership before asserting
allocation-account usage is zero. A structural regression explicitly excludes
IndexJoin and checks final worker reference counts, including downstream DOP
changes and existing remote groups. Existing Product remote retirement and
independent result-root contracts remain enabled.

Important scope boundary

This proves a supported internal compiler/runtime scope ownership contract.
It does not prove an actual SQL planner currently creates the asymmetric probe
placement in this fixture. It does not establish the first cancellation owner
or the root cause of Nightly Run 37484909730's information_schema metadata JOIN
failure. Natural three-CN and DOP=2 incident probes passed without reaching the
repeated-CN independent-probe domain. Do not interpret this PR as fully fixing
or closing that incident/Issue #29642. PR #29643 is the already-deployed Product
ownership fix; it is not the original incident's Issue number.

Validation

Go 1.27.0; exact-base verified CGo artifacts; CPU 0/1, GOMAXPROCS=2 and 4GiB Go
memory budget. No production cluster or foreign service was touched.

These were run from the MatrixOne worktree with verified native prerequisites.
The commands below are directly executable with the same Go/native setup:

GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \
  .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -count=1 -timeout=180s ./pkg/sql/compile
GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \
  .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -race -count=1 -timeout=180s ./pkg/sql/compile
GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \
  .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -race \
  -run '^TestBroadcastHashJoinSharedProducerOwnership$' -count=2 -timeout=120s ./pkg/sql/compile
GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \
  .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -race \
  -run '^TestBroadcastLoopJoinSharedProducerOwnership$' -count=2 -timeout=120s ./pkg/sql/compile

Final narrowed production guard: normal compile package PASS 7.224s;
full compile package under -race PASS 9.606s; exact HashJoin/LoopJoin
two repetitions PASS 3.211s / 3.195s. Before the guard was narrowed to
these same Hash/Loop paths, each exact test was also adaptively stressed 29
times under race (1.02s measured test, 30s budget): PASS 30.887s / 31.333s.

Related runtime package checks were also run:

GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \
  .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -race -count=1 -timeout=180s \
  ./pkg/sql/colexec/hashbuild ./pkg/sql/colexec/hashjoin ./pkg/sql/colexec/loopjoin \
  ./pkg/sql/colexec/dispatch ./pkg/vm/message ./pkg/vm/pipeline ./pkg/vm/process

All seven packages PASS (1.973s, 11.624s, 1.676s, 1.316s, 1.219s,
1.188s and 2.262s respectively). This is supporting dependency evidence,
not a public remote-source performance test.

Official Main linter v2.14.0, built with Go1.27.0 was run with matching
Go1.27 PATH/GOROOT and repository CGo include/library paths:

GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB GOWORK=off \
  CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" \
  CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" \
  golangci-lint run --concurrency=2 --timeout=5m -c .golangci.yml ./pkg/sql/compile
git diff --check

Final narrowed version: linter PASS, exit 0, 0 issues;
git diff --check PASS. No older Go1.21 or golangci v2.6 tooling was used
as a final gate. Detailed terminal evidence is retained locally.

Root additionally combined this patch with the independent minimal vector
and catalogue patches (#29664 and #29662) in a temporary exact-base worktree.
Full vector/mergeutil/compile/frontend package tests passed; the authenticated
two-CN TestIssue29414PublicationWaitsForPhysicalDatabaseDrop public SQL
consumer passed rollback, commit, replacement and cancellation (9.660s).
This checks composition and ordinary public SQL behavior; it is not a
natural reproduction or a performance A/B of the special repeated-CN domain.

@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 XuPeng-SH 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.

Deep review of 1d3e8bdbd630fe1f2aa61fa7e02926b9fa8bf759 against 15cc6232efd2d1b048e9474f7d4aa692539fc1cc: REQUEST_CHANGES — one P2 validation/performance gate remains for the newly enabled remote-source domain.

The ownership direction is sound. An independently retiring probe cannot own the source/map still required by its peers. Reusing the existing producer-region machinery keeps one scheduling, cancellation and error-arbitration implementation. This is a focused bug fix using an existing protocol; it does not require a new architecture or another lifecycle state machine.

The remaining gate is described inline at the new HashJoin/LoopJoin selection. The guard includes remote build sources, and the reused helper changes their data route through the coordinator. Existing local-source runtime evidence does not validate that added route or quantify its cost.

Reviewed closures:

  • Deferred compile ownership -> final worker counts -> common result/auxiliary owner -> pipeline context initialization -> MergeRun/runOnce -> cancellation, original-error arbitration and cleanup.
  • HashBuild publication -> shared MessageBoard -> HashJoin/LoopJoin consumption -> residual map release. Remote fragment counts and statement-group board lifetime were also traced.
  • Reset/reuse and compilation failure cleanup; result receivers stay separate from auxiliary-job terminals. The force-one-CN policy keeps the relevant right/full-join placements on the existing single-probe path.
Lifecycle dimension Assessment
Ownership Existing pending-producer transfer and terminal board/account cleanup are reused; no second resource owner introduced.
Termination Common-owner cancellation occurs before worker joins; original producer failure remains eligible for error arbitration. The added remote-source composition still needs execution evidence.
Bounds No new cache or unbounded queue; extra coordinator relay and per-group job stages add transport/buffering work whose remote-source cost is not measured.

All four changed files were read. Production changes are +15/-9 lines (including comments), tests +273/-61, docs unchanged. The tests reuse the Product fixture and preserve its cases. New HashJoin/LoopJoin cases distinguish result rows, normal consumer retirement with a live parent, first/last/all skipped consumers, build error/panic, cancellation/deadline and fresh-generation reuse. The stronger cleanup placement is useful. Internal scope evidence is appropriately distinguished from an actual SQL planner/incident reproduction.

Validation:

  • CI run 37614611335 reports this exact head and completed successfully. The UT checkpoint includes compile, hashbuild/hashjoin/loopjoin, dispatch, message, pipeline and process under -race -short -tags matrixone_test; the containing stage finishes with status 0. SCA and proxy/pessimistic BVT passed.
  • Author-reported normal package runs and focused race stress support the local-source closure; those local terminal artifacts were not independently reproduced here.
  • Local git diff --check passed. The attempted focused local race command stopped before execution because matching CGo artifacts were unavailable and the repository wrapper rejected primary-worktree reuse.
  • There were no substantive previous review comments or inline threads to resolve.

No other confirmed blocking finding from this review. Keep #29642 open: original incident attribution and natural SQL reachability of the special asymmetric topology remain unproved.

Comment thread pkg/sql/compile/compile.go Resolved
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 7, 2026

@XuPeng-SH XuPeng-SH 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.

Deep re-review of 12f8bedb664778a39aa52b6fdbd0575fa02e2323 against merge-base f20f5ca147c44b012343d0f48dfcd84b6a5986a1. Latest main was freshly fetched (8929ab4946fbc7d44b6757fe5b12de6c74118c21). Reviewed independently, without subagents.

APPROVE. The previous P2 remote-source placement finding is resolved; no additional blocking finding was confirmed. This approves the bounded internal compiler/runtime ownership repair, not the attribution or complete resolution of the Nightly incident in #29642.

Previous finding and design

The fix takes the placement-preserving alternative requested in the previous review. HashJoin/LoopJoin no longer wrap a remote source in a coordinator Merge. Instead, the source belongs to an independent HashBuild scope on the matching CN, falling back to a build owner when there is no matching probe CN. The same-CN Dispatch receiver remains inside the same remotely encoded scope tree. The source is not a child of a probe that may retire without consuming it.

I checked the old route, current construction, final worker reference counts, receiver identity after encode/decode, remote fragment counting, receiver-address normalization, and the existing RemoteRun/root-output boundary. The problematic extra coordinator full-payload round trip is removed. It would not be useful to keep blocking on an A/B of that now-removed route. This does not establish an overall SQL latency improvement: the producer job still adds bounded scheduling/terminal bookkeeping, and no fresh end-to-end latency benchmark was run in this review.

The implementation reuses the existing pending-producer region, scheduler, MessageBoard, error arbitration and allocation-account owners. Product retains its existing placement; single/packed and unique-CN non-Product paths, IndexJoin, ProductL2 and dedup operators retain their prior selection. The Product/non-Product placement distinction is necessary, not a second lifecycle protocol. This remains an ordinary focused fix, exempt from a new architectural design document.

Ownership and unhappy-path audit

Contract Verified closure
Q1: one effective destruction owner Source ownership moves from the pending record into its build subtree; finalization transfers that subtree to the producer job. Compilation failure releases the pending tree. Runtime joins precede terminal board/account cleanup; skipped consumers' unclaimed maps are drained by the existing board owner.
Q2: waits terminate A retiring probe cannot cancel the independent build/source. Common result-owner/query cancellation reaches producer contexts before joins. Source errors/panics remain available to error arbitration. Receiver registration and typed terminal/abort cleanup retain their existing owners.
Q3: retained state is bounded One build per participating CN group, final probe-worker refcounts, existing bounded edges/spools and execution allocation accounts; no new cache, queue, retry loop or background service. Reset creates fresh execution/account/context generations.

No disk/catalog/wire field is added; data-format compatibility is unchanged. The change does not introduce a mixed-upgrade requirement. Existing right/full-join placement constraints and unchanged operator algorithms were traced rather than inferred from the INNER reproducer.

Validation

  • Rebuilt matching native dependencies in an isolated exact-head worktree; Go 1.27.0, darwin/arm64, GOMAXPROCS=4.
  • Normal focused run: TestBroadcast{HashJoin,LoopJoin}{SharedProducerOwnership,RemoteSourceOwnership} and TestBroadcastSharedJoinPreservesSourcePlacement all PASS, package 7.010s. This covers real compiler/codec/executor ownership, first/last/all skipped probes, empty inputs, original build failure, partial-output panic, cancellation/deadline and fresh-generation reuse.
  • Measured each remote-source test under race at approximately 1.04s; with a 30s focused budget selected 28 repetitions. Exact HashJoin test PASS 32.099s, exact LoopJoin test PASS 33.128s (package elapsed, including startup/race teardown). No blanket repeated-package run.
  • Independent review-only adjacent challenge: under the same remote-codec/sibling-retirement topology, an empty build must discard INNER rows but preserve the three unmatched LEFT probe rows. Both HashJoin and LoopJoin passed the four semantic cells; 100 repetitions under race PASS, 3.517s. These temporary fixture extensions do not change PR production code.
  • Reused exact-head CI run 37709447247: all required checks green, including SCA, Coverage, proxy BVT and pessimistic multi-CN BVT. The downloaded UT checkpoint explicitly selects compile, hashbuild/hashjoin/loopjoin, dispatch, message, pipeline and process under -race -short -tags matrixone_test; the stage terminates with status 0.
  • git diff --check passed. The codec/runtime tests are not represented as a real MORPC-cluster or natural SQL reproduction of the asymmetric domain.

Test/code/documentation quality and remaining note

All four changed files and their consumers were reviewed. Production delta is +38/-13 including comments; tests are +464/-63; no tracked documentation changes. Tests reuse the existing Product fixture and preserve its controls; the extra remote codec, ownership/refcount and INNER-vs-LEFT result oracles prove distinct contracts. No new cluster, large dataset, production test hook or scheduler sleep is introduced.

Non-blocking documentation correction: the PR description still says the helper runs Dispatch at the coordinator and can add a coordinator Merge for an eligible remote source. That is stale for the new HashJoin/LoopJoin implementation; it should distinguish preserved Product behavior from the corrected Hash/Loop placement. The description should also list the new remote-source tests. Do not remove the valid limitation that natural SQL reachability and the original #29642 incident root cause remain unproved.

There was one substantive prior review thread; its implementation concern is closed by the placement change and validation above. No other human review requests were present.

@mergify

mergify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

This branch was previously deployed

1 inactive deployment
ci — ec7dbdd9 Deployed Oct 8, 2026 by XuPeng-SH
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.

3 participants