Skip to content

fix: distribute sink scan shuffle hashbuild - #26284

Merged
mergify[bot] merged 2 commits into
matrixorigin:4.2-devfrom
jiangxinmeng1:fix/4.2-distribute-sinkscan-shuffle-hashbuild
Jul 28, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:4.2-devfrom
jiangxinmeng1:fix/4.2-distribute-sinkscan-shuffle-hashbuild

Conversation

@jiangxinmeng1

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25114

What this PR does / why we need it:

Keep the in-process SINK_SCAN producer on its owning CN.

Distribute shuffle hash-build receivers across all query worker CNs instead of
concentrating them on the coordinator.

Ensure the local SINK_SCAN scope is attached to exactly one local receiver tree
and is never serialized to a remote CN.

Preserve mixed local/remote shuffle dispatch and standalone remote execution.

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

Blocking: the SINK_SCAN owner added to the receiver stage is not preserved by the later per-CN grouping.

shuffleJoinStageNodes now appends the SINK_SCAN owner when it is absent from queryWorkerStageNodes() (compile.go:5258-5272). However, every affected INSERT/MULTI_UPDATE path later calls groupShuffleBucketsByCNIfNeeded, which independently recomputes only queryWorkerStageNodes() (compile.go:5469-5484). mergeScopesByStageNodes then iterates only that scheduled-worker list (compile.go:5487-5503).

I reproduced this deterministically on the exact head through the real compileJoin path with DOP=2 and a SINK_SCAN owner outside c.cnList:

  • With one scheduled worker, compileJoin creates 4 buckets over 2 CNs, but grouping returns all 4 unchanged because len(stageNodes) <= 1. The remote send trees are still non-standalone: their dispatch local receivers point to sibling bucket trees, which is the wrong-CN/hang condition this grouping helper is intended to prevent.
  • With two scheduled workers, compileJoin creates 6 buckets over 3 CNs, but grouping returns only 2 trees. All buckets owned by the SINK_SCAN CN are silently dropped because that owner is not in the recomputed worker list.

Please carry the actual join stage-node set into grouping, or derive and preserve all unique execution nodes from ss, and add closure tests for an owner outside both one- and two-worker scheduled sets through compileJoin plus grouping.

The new TestCompileShuffleJoinDistributesSinkScanHashbuild does not exercise this boundary: it calls compileShuffleJoin directly, which uses queryWorkerStageNodes() and bypasses shuffleJoinStageNodes (compile.go:3701-3703), and its owner is already in cnList.

Validation on this exact head: all five directly affected tests passed independently with -race -count=100; the full pkg/sql/compile race suite, build, and vet also passed. The missing composition case is why current CI remains green.

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

Re-reviewed exact head 3cb335d against exact base 4.2-dev@1c48a13971bdfb63ae13fe53c3485e8decc1e079.

The previous blocker is resolved. groupShuffleBucketsByCNIfNeeded now derives the grouping boundary from the actual receiver buckets instead of recomputing only the scheduled query-worker set. Therefore an external SINK_SCAN owner survives both cases that previously failed: 1 worker now groups 4 buckets into 2 complete CN trees, and 2 workers group 6 buckets into 3 without dropping the owner's 2 buckets. The new compileJoin composition test covers both cases and verifies that every remote group is standalone-executable and exactly one owner tree retains the in-process SINK_SCAN.

The full topology is consistent: stage nodes are deduplicated once; probe/build shuffle operators use the resulting len(stageNodes) * dop bucket count; the SINK_SCAN source attaches to the receiver on its owner CN; each bucket keeps a unique ShuffleIdx; and later per-CN merging partitions the same bucket set with the same execution-node identity relation. Ordinary shuffle and single-CN paths keep their existing gating. This is compile-time topology work only and adds no per-row execution overhead; hashbuild state is distributed instead of concentrated on the coordinator.

Local verification:

  • all seven directly affected topology tests passed independently under -race for 31-35 repetitions;
  • the complete pkg/sql/compile package passed under -race;
  • vet, build-only test, diff checks, and the current 4.2-dev merge tree passed;
  • all current substantive GitHub checks are successful.

Non-blocking follow-ups:

  • shuffleJoinStageNodes materializes an empty owner address, but the original source scope remains empty and attachShuffleDispatchSource falls back to receiver 0. Production compileSinkScanNode assigns the current CN address, so this is not currently reachable there; if the empty-address branch is intended as a supported contract, normalize the source or make the owner receiver first and add that case.
  • This is a plausible second-stage #25114 improvement on top of merged #26252, which already bounds vector LOAD buffers/hashbuild spill. Keep #25114 open until the original 10M wiki-vector nightly reproduction confirms both successful import and the expected per-CN memory distribution; topology UTs alone do not prove the 41 GB incident is closed.

@mergify mergify Bot added the queued label Jul 28, 2026
@mergify

mergify Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-28 07:29 UTC · Rule: release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-07-28 07:29 UTC · at 3cb335d08ba2591782ae842d61c215e8bb81bc97 · squash

This pull request spent 16 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection] (documentation)
  • github-review-decision = APPROVED [🛡 GitHub branch protection] (documentation)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)

@mergify
mergify Bot merged commit 36cae2e into matrixorigin:4.2-dev Jul 28, 2026
25 of 26 checks passed
@mergify mergify Bot removed the queued label Jul 28, 2026

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

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants