Skip to content

fix: acknowledge remote batches before early stop - #26751

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
aptend:fix/26746-remote-batch-ack-early-stop
Aug 6, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
aptend:fix/26746-remote-batch-ack-early-stop

Conversation

@aptend

@aptend aptend commented Aug 6, 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:

issue #26746

What this PR does / why we need it:

Remote batch backpressure records a batch as outstanding until the client sends its ACK. The connector, dispatch, and remote-notify receive loops returned before that ACK when downstream had already stopped, leaving the server drain barrier to wait for its 30-second timeout.

This change acknowledges a successfully decoded batch after it is handed off or intentionally discarded, before a graceful early return. Error and cancellation paths still return without a success ACK and rely on stream teardown, preserving the bounded-credit behavior introduced by #26711.

It also adds regression coverage for all three graceful-stop paths.

Tests:

  • go test -race -count=25 for each new/updated regression test
  • go test -race -count=1 ./pkg/sql/compile
  • go test -count=1 ./pkg/sql/compile
  • go test -count=1 ./pkg/sql/colexec/connector ./pkg/sql/colexec/dispatch
  • go list, go build, and go vet for ./pkg/sql/compile

@aptend
aptend requested review from XuPeng-SH and aunjgr as code owners August 6, 2026 07:03
@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.

Reviewed exact head dc8f769f56ff5e314f4e62e53259f8e61d755200.

No blocking findings remain.

The fix restores the remote-batch credit invariant at the correct boundary: once a decoded batch has either been handed to the local pipeline or intentionally discarded because that receiver is terminal, the client must release the corresponding remote credit before a graceful early return. Connector, dispatch, and remote-notify now all do so.

The ownership and termination paths remain separated correctly:

  • Normal forwarding transfers local batch cleanup to the downstream edge, then ACKs the remote serialized-batch credit.
  • A terminal receiver rejects the handoff; forwardRemoteBatchWithContext/dispatch cleans the decoded batch locally, then the new ACK releases the server-side credit before returning.
  • Decode, execution, cancellation, and ACK-send failures still return errors without clearing pendingBatchAck; stream/query teardown remains the failure owner rather than falsely acknowledging success.
  • The ACK is cumulative/idempotent on the server, and the client still prevents receiving another logical batch while one ACK is pending, so this change does not weaken the negotiated count/byte bounds.

Q1/Q2/Q3 audit: every decoded batch has exactly one local cleanup owner; the server drain wait now terminates on graceful early stop while error/cancel retains its independent connection/context termination; outstanding batch count and bytes remain bounded by the negotiated flow-control limits.

Independent differential validation reproduced pendingBatchAck == 7 on exact base ffc16032b7ab79a4fa97dba6e5bb57cf9ef5ed8a; the same receiver-terminal shape sends the matching ACK and clears the credit on this head. I also added temporary adjacent counterexamples proving across 25 race iterations that cancellation sends no success ACK and an ACK transport failure is still returned as an error.

Local exact-head validation passed: the three committed regressions under -race -count=25, full pkg/sql/compile tests, dependent connector/dispatch tests, go build, go vet, and git diff --check. Current GitHub CI is complete with no failures.

@mergify mergify Bot added the queued label Aug 6, 2026
@mergify

mergify Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-06 08:03 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-06 11:38 UTC · at 83b060ac2ecd88ba1337e859a35293a263e70a3b · squash

This pull request spent 3 hours 35 minutes 2 seconds in the queue, including 39 minutes 56 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • 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 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 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 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)
  • 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 UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86

@mergify
mergify Bot merged commit 1308869 into matrixorigin:main Aug 6, 2026
26 of 27 checks passed
@mergify mergify Bot removed the queued label Aug 6, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Remote batch backpressure records a batch as outstanding until the client sends its ACK. The connector, dispatch, and remote-notify receive loops returned before that ACK when downstream had already stopped, leaving the server drain barrier to wait for its 30-second timeout.

This change acknowledges a successfully decoded batch after it is handed off or intentionally discarded, before a graceful early return. Error and cancellation paths still return without a success ACK and rely on stream teardown, preserving the bounded-credit behavior introduced by matrixorigin#26711.

It also adds regression coverage for all three graceful-stop paths.

Tests:

- `go test -race -count=25` for each new/updated regression test
- `go test -race -count=1 ./pkg/sql/compile`
- `go test -count=1 ./pkg/sql/compile`
- `go test -count=1 ./pkg/sql/colexec/connector ./pkg/sql/colexec/dispatch`
- `go list`, `go build`, and `go vet` for `./pkg/sql/compile`

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Remote batch backpressure records a batch as outstanding until the client sends its ACK. The connector, dispatch, and remote-notify receive loops returned before that ACK when downstream had already stopped, leaving the server drain barrier to wait for its 30-second timeout.

This change acknowledges a successfully decoded batch after it is handed off or intentionally discarded, before a graceful early return. Error and cancellation paths still return without a success ACK and rely on stream teardown, preserving the bounded-credit behavior introduced by matrixorigin#26711.

It also adds regression coverage for all three graceful-stop paths.

Tests:

- `go test -race -count=25` for each new/updated regression test
- `go test -race -count=1 ./pkg/sql/compile`
- `go test -count=1 ./pkg/sql/compile`
- `go test -count=1 ./pkg/sql/colexec/connector ./pkg/sql/colexec/dispatch`
- `go list`, `go build`, and `go vet` for `./pkg/sql/compile`

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Remote batch backpressure records a batch as outstanding until the client sends its ACK. The connector, dispatch, and remote-notify receive loops returned before that ACK when downstream had already stopped, leaving the server drain barrier to wait for its 30-second timeout.

This change acknowledges a successfully decoded batch after it is handed off or intentionally discarded, before a graceful early return. Error and cancellation paths still return without a success ACK and rely on stream teardown, preserving the bounded-credit behavior introduced by matrixorigin#26711.

It also adds regression coverage for all three graceful-stop paths.

Tests:

- `go test -race -count=25` for each new/updated regression test
- `go test -race -count=1 ./pkg/sql/compile`
- `go test -count=1 ./pkg/sql/compile`
- `go test -count=1 ./pkg/sql/colexec/connector ./pkg/sql/colexec/dispatch`
- `go list`, `go build`, and `go vet` for `./pkg/sql/compile`

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

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants