Skip to content

fix(compile): prevent distributed delete dispatch hang - #26533

Merged
XuPeng-SH merged 1 commit into
4.2-devfrom
fix/4.2-remote-dispatch-placement-hang
Aug 1, 2026
Merged

XuPeng-SH merged 1 commit into
4.2-devfrom
fix/4.2-remote-dispatch-placement-hang

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Jul 31, 2026 •

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:

Fixes #26526

What this PR does / why we need it:

Root cause

newDeleteMergeScope created one receiver scope per delete bucket and attached only source i beneath receiver i. However, every source Dispatch.LocalRegs targeted all same-CN delete receivers. Each receiver tree therefore owned only one of the local channels used by its source dispatch and was not independently executable on its planned CN.

RemoteRun silently converted such a remote tree to local MergeRun on the coordinator. The dispatch UUID was then registered and executed on the coordinator while RemoteReceivRegInfo.FromAddr still named the planned worker CN. Receivers notified a CN that would never publish that UUID and waited indefinitely in GetProcByUuid.

The generated topology reproduces the incident exactly: two distributed-delete steps, three CNs with DOP 16, 64 misplaced remote source dispatches, 32 remote UUID routes per source, 2048 coordinator-side waits, and 1024 lookups on each remote CN.

Incident correlation (sanitized)

The request-changes review correctly noted that the original issue discussion did not publish enough evidence to connect the nightly hang to this path. Rechecking the real CI Loki data and archived raw goroutine snapshots closes that gap:

  • At 03:10:10.363181 UTC, the target restore connection completed authentication and received the OK packet. At 03:10:10.567937, the planner logged the sanitized query shape LOAD DATA URL (...) ... PARALLEL=true.
  • At 03:10:10.590517–03:10:10.601298, statement 019fb626-984b-7eda-bb4f-aac9e7d65773, trace c8489d33-8079-91e3-8f0b-56321c81ac0d emitted 128 remoterunClient.go:155 fallback messages: 64 unique pipeline pointers, each checked twice, explicitly converted to local execution because its dispatch referenced another local pipeline tree.
  • In the 03:13:18 coordinator snapshot, the authenticated frontend goroutine is inside executeStatusStmt -> Compile.Run -> runOnce. The same compile execution contains 2 MergeDelete.Call stacks and 96 Deletion.remoteDelete stacks; every remote-delete stack passes through Scope.RemoteRun -> Scope.MergeRun. All 64 fallback pipeline pointers from Loki match those raw remote-delete stacks. The remaining 32 are the coordinator-local sources: 2 steps * 3 CNs * DOP 16 = 96, of which 2 steps * 2 remote CNs * DOP 16 = 64 were misplaced.
  • The wait-for graph is exact and stable from the 03:13 snapshots to the 14:50 snapshots: 2048 coordinator sendNotifyMessageWithFactoryAndWait waits and 1024 GetProcByUuid waits on each of the two remote CNs. The same stacks remained blocked for about 700 minutes.
  • The earlier "zero Exec.Run" observation does not mean no statement executed. status_stmt.go calls runner.Run(0) first and emits time of Exec.Run only after it returns; the archived frontend stack shows that call still blocked. The cited salt timeout belongs to a different connection, was already occurring before restore started, and does not appear on the target restore session.

This directly ties the reported restore hang to the distributed compileDelete -> newDeleteMergeScope -> RemoteRun -> MergeRun fallback. A literal DELETE statement is not required: the physical Deletion and MergeDelete operators are present in the LOAD DATA execution stacks.

Fix

  • Group distributed-delete receiver buckets into one RemoteRun envelope per execution CN. Every envelope now owns all same-CN LocalRegs referenced by its source dispatches while preserving all delete buckets, UUIDs, and remote routes.
  • Validate standalone execution against the complete operator tree that will actually be encoded, including dispatches or connectors wrapped by DML operators.
  • Reject any remaining non-standalone remote tree before RPC or operator start, cancel the query context, and do not pre-register phantom dispatch owners on the coordinator.
  • Update the RemoteRun guide to document the fail-fast contract.

The success path fixes the compiler topology. The runtime checks are a liveness backstop so a future invalid topology returns an error instead of changing placement and hanging.

Validation

Based on latest origin/4.2-dev at 890270f4e6.

  • Focused topology and fail-fast regressions, count=50
  • Focused race regressions, count=3
  • Full pkg/sql/compile test package
  • Full pkg/sql/compile test package with race detector
  • go build -mod=readonly ./pkg/sql/compile
  • go vet -mod=readonly ./pkg/sql/compile
  • git diff --check

Regression coverage verifies per-CN standalone execution for multi-CN and single-remote-CN DOP, all IBucket/Nbucket values, UUID-to-receiver route bijection, the observed 2048/1024/1024 topology, pre-registration ownership, nested operators, direct fail-fast cancellation, and bounded MergeRun sibling shutdown.

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner July 31, 2026 17:06
@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 →

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

Requesting changes on issue targeting; I did not find a code-side blocker in the topology or lifecycle changes.

The published evidence for #26526 does not currently establish that this code path was reached:

The structural regression does demonstrate a real latent distributed-delete topology defect, but it does not yet connect that defect to #26526. Merging this as Fixes #26526 would close the reported Proxy/authentication incident without showing it is fixed. Please either link/create the correct issue for this distributed-delete defect and stop auto-closing #26526, or add concrete evidence from that run (affected SQL/statement or trace ID, query plan, and/or goroutine stack) proving the two distributed-delete steps ran, and reconcile it with the existing zero-Exec/authentication diagnosis.

For the code itself, I checked bucket/UUID/FromAddr preservation, per-CN ownership, full encoded-tree validation, pre-registration, cancellation/cleanup, bounded waits, and compile-time cost. Seventeen focused topology, encoding, registration, and unhappy-path tests pass at head 93bd29c.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Thanks — this was a valid evidence gap in the original issue discussion. I re-queried the real CI Loki data and correlated it with the archived raw goroutine snapshots. I kept Fixes #26526 and added a sanitized, reproducible incident-correlation section to the PR body because the new evidence directly reaches this code path:

  • 03:10:10.363181 UTC: the target restore connection completed authentication and received OK.
  • 03:10:10.567937: the planner logged the sanitized shape LOAD DATA URL (...) ... PARALLEL=true.
  • 03:10:10.590517–.601298: statement 019fb626-984b-7eda-bb4f-aac9e7d65773, trace c8489d33-8079-91e3-8f0b-56321c81ac0d emitted 128 fallback logs: 64 unique pipeline pointers, each checked twice, explicitly converted locally because its dispatch referenced another local pipeline tree.
  • The 03:13:18 raw coordinator dump shows the authenticated frontend blocked in executeStatusStmt -> Compile.Run -> runOnce, plus 2 MergeDelete.Call and 96 Deletion.remoteDelete stacks in the same compile execution. Every remote-delete stack contains Scope.RemoteRun -> Scope.MergeRun, and all 64 Loki fallback pointers match those raw stacks. The arithmetic closes as 2 steps * 3 CNs * DOP 16 = 96 delete sources, with 2 steps * 2 remote CNs * DOP 16 = 64 misplaced sources.
  • The same snapshots show 2048 coordinator notify/receive waits and 1024 GetProcByUuid waits on each remote CN. Counts and stacks are unchanged at 14:50, after about 700 minutes.

This also reconciles the two conflicting observations:

  • time of Exec.Run is logged only after runner.Run(0) returns; the raw frontend stack shows that call still blocked, so zero completion-timing logs are expected and do not mean zero execution.
  • The cited salt timeout belongs to another connection, was already recurring before restore started, and is absent from the target restore session.

I also posted the sanitized correction on #26526. No code change was needed for this review because your code-side review found no blocker; the requested change was addressed by completing the incident evidence chain. Please re-review when convenient.

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

Re-reviewed the code at head 93bd29c. I found no production-reachable blocker in the per-CN distributed-delete grouping, bucket and UUID routing preservation, encoded-tree standalone validation, dispatch pre-registration, cancellation/cleanup paths, or compile-time performance. Seventeen focused topology, encoding, registration, and unhappy-path tests passed with bounded local concurrency. My earlier issue-attribution concern is non-blocking for this code review and should not gate this patch.

@LeftHandCold
LeftHandCold dismissed their stale review July 31, 2026 17:50

Superseded by the code-focused re-review and approval at head 93bd29c; issue attribution is non-blocking for this patch.

@XuPeng-SH
XuPeng-SH merged commit a72b5a1 into 4.2-dev Aug 1, 2026
44 of 45 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/4.2-remote-dispatch-placement-hang branch August 1, 2026 00:06

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