Skip to content

fix: make internal SQL logtail waits cancelable - #27168

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27073-ea25f12c
Aug 14, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27073-ea25f12c

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Aug 14, 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 #27073

What this PR does / why we need it:

Root cause

pkg/incrservice asks the internal SQL executor to wait until a committed auto-increment update is visible in the local logtail. After committing with the caller-owned allocation context, sqlExecutor.ExecTxn discarded that context and called TxnClient.SyncLatestCommitTS. That API creates an independent five-minute background timeout and handles a failed wait with a fatal log. Consequently, allocator cancellation, its three-minute deadline, and CN shutdown could not release the post-commit wait. Under the race-UT load captured in #27073, TestBasicCluster remained in sqlStore.Allocate -> SyncLatestCommitTS until that independent timeout, and earlier runs outlived the whole UT job deadline.

The local transaction commit already advances the transaction client's latest commit timestamp through its ClosedEvent callback. The missing property was a cancelable visibility barrier, not another timestamp update.

Changes

  • Route the internal executor's post-commit visibility barrier through the existing WaitLogTailAppliedAt API with the transaction executor's caller-owned context.
  • Return visibility-wait errors from ExecTxn after commit instead of entering the fatal background wait.
  • Add deterministic unit coverage for caller cancellation, disabled waits, empty commit timestamps, successful waits, and wait-error propagation.

No retry, fallback, timeout tuning, public API, or unrelated embedded-cluster behavior is changed.

Issue-to-test proof

  • TestInternalExecutorCommittedLogWaitHonorsCallerCancellation deterministically enters the exact post-commit barrier, cancels its caller context, and proves the wait returns context.Canceled without relying on scheduler timing.
  • TestInternalExecutorCommittedLogWaitContract covers the neighboring contract: disabled and empty-timestamp no-op paths, success, and error propagation.
  • The issue's exact integration reproducer, pkg/embed.TestBasicCluster, passes under the race detector after the change.

BVT is not appropriate for this lifecycle defect because SQL cannot deterministically hold the internal timestamp waiter at the cancellation boundary; the focused unit test provides that synchronization with channel barriers, while TestBasicCluster covers the real embedded-cluster path.

Validation

  • Rebased cleanly onto main at 11981033c588d3fe7e6fcc50ead874dfcd88d8f8; the upstream delta did not touch either changed file.
  • CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" GOWORK=off go build -mod=readonly ./pkg/sql/compile
  • CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" GOWORK=off go vet -mod=readonly ./pkg/sql/compile
  • Focused new unit tests with -race -count=100: pass
  • TestBasicCluster race measurement: T=20.06s; with B=30s, N=1
  • TestBasicCluster again on the final rebased head with -race -count=1: pass in 25.421s
  • Full pkg/sql/compile and dependent pkg/incrservice, normal and race: pass on the final rebased head
  • git diff --check origin/main...HEAD: pass

Residual risk

The CI resource-pressure condition that delayed logtail application is intermittent and was not forced locally. The invalid wait-for edge is independently proven by the preserved CI stack and deterministic cancellation regression; the exact embedded-cluster case also completes under race. The behavior after a visibility-wait failure changes from a process-fatal path to an error returned after commit, matching the existing ExecTxn error contract. Auto-increment callers may retry and skip committed values, which is already permitted for auto-increment allocation failures.

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

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

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-14 12:32 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-14 12:52 UTC · at 06acb6369ac72a408727932788b34019c4d87323

This pull request spent 19 minutes 21 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • 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)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • 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)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

The pull request can't be updated

This pull request seems to come from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request, or update the branch manually.

Failing checks:

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 7e03000 into matrixorigin:main Aug 14, 2026
23 of 25 checks passed
@mergify mergify Bot removed the queued label Aug 14, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27073

## What this PR does / why we need it:

### Root cause

`pkg/incrservice` asks the internal SQL executor to wait until a
committed auto-increment update is visible in the local logtail. After
committing with the caller-owned allocation context,
`sqlExecutor.ExecTxn` discarded that context and called
`TxnClient.SyncLatestCommitTS`. That API creates an independent
five-minute background timeout and handles a failed wait with a fatal
log. Consequently, allocator cancellation, its three-minute deadline,
and CN shutdown could not release the post-commit wait. Under the
race-UT load captured in matrixorigin#27073, `TestBasicCluster` remained in
`sqlStore.Allocate -> SyncLatestCommitTS` until that independent
timeout, and earlier runs outlived the whole UT job deadline.

The local transaction commit already advances the transaction client's
latest commit timestamp through its `ClosedEvent` callback. The missing
property was a cancelable visibility barrier, not another timestamp
update.

### Changes

- Route the internal executor's post-commit visibility barrier through
the existing `WaitLogTailAppliedAt` API with the transaction executor's
caller-owned context.
- Return visibility-wait errors from `ExecTxn` after commit instead of
entering the fatal background wait.
- Add deterministic unit coverage for caller cancellation, disabled
waits, empty commit timestamps, successful waits, and wait-error
propagation.

No retry, fallback, timeout tuning, public API, or unrelated
embedded-cluster behavior is changed.

### Issue-to-test proof

- `TestInternalExecutorCommittedLogWaitHonorsCallerCancellation`
deterministically enters the exact post-commit barrier, cancels its
caller context, and proves the wait returns `context.Canceled` without
relying on scheduler timing.
- `TestInternalExecutorCommittedLogWaitContract` covers the neighboring
contract: disabled and empty-timestamp no-op paths, success, and error
propagation.
- The issue's exact integration reproducer,
`pkg/embed.TestBasicCluster`, passes under the race detector after the
change.

BVT is not appropriate for this lifecycle defect because SQL cannot
deterministically hold the internal timestamp waiter at the cancellation
boundary; the focused unit test provides that synchronization with
channel barriers, while `TestBasicCluster` covers the real
embedded-cluster path.

### Validation

- Rebased cleanly onto `main` at
`11981033c588d3fe7e6fcc50ead874dfcd88d8f8`; the upstream delta did not
touch either changed file.
- `CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include"
CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" GOWORK=off go build
-mod=readonly ./pkg/sql/compile`
- `CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include"
CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" GOWORK=off go vet
-mod=readonly ./pkg/sql/compile`
- Focused new unit tests with `-race -count=100`: pass
- `TestBasicCluster` race measurement: `T=20.06s`; with `B=30s`, `N=1`
- `TestBasicCluster` again on the final rebased head with `-race
-count=1`: pass in 25.421s
- Full `pkg/sql/compile` and dependent `pkg/incrservice`, normal and
race: pass on the final rebased head
- `git diff --check origin/main...HEAD`: pass

### Residual risk

The CI resource-pressure condition that delayed logtail application is
intermittent and was not forced locally. The invalid wait-for edge is
independently proven by the preserved CI stack and deterministic
cancellation regression; the exact embedded-cluster case also completes
under race. The behavior after a visibility-wait failure changes from a
process-fatal path to an error returned after commit, matching the
existing `ExecTxn` error contract. Auto-increment callers may retry and
skip committed values, which is already permitted for auto-increment
allocation failures.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27073

## What this PR does / why we need it:

### Root cause

`pkg/incrservice` asks the internal SQL executor to wait until a
committed auto-increment update is visible in the local logtail. After
committing with the caller-owned allocation context,
`sqlExecutor.ExecTxn` discarded that context and called
`TxnClient.SyncLatestCommitTS`. That API creates an independent
five-minute background timeout and handles a failed wait with a fatal
log. Consequently, allocator cancellation, its three-minute deadline,
and CN shutdown could not release the post-commit wait. Under the
race-UT load captured in matrixorigin#27073, `TestBasicCluster` remained in
`sqlStore.Allocate -> SyncLatestCommitTS` until that independent
timeout, and earlier runs outlived the whole UT job deadline.

The local transaction commit already advances the transaction client's
latest commit timestamp through its `ClosedEvent` callback. The missing
property was a cancelable visibility barrier, not another timestamp
update.

### Changes

- Route the internal executor's post-commit visibility barrier through
the existing `WaitLogTailAppliedAt` API with the transaction executor's
caller-owned context.
- Return visibility-wait errors from `ExecTxn` after commit instead of
entering the fatal background wait.
- Add deterministic unit coverage for caller cancellation, disabled
waits, empty commit timestamps, successful waits, and wait-error
propagation.

No retry, fallback, timeout tuning, public API, or unrelated
embedded-cluster behavior is changed.

### Issue-to-test proof

- `TestInternalExecutorCommittedLogWaitHonorsCallerCancellation`
deterministically enters the exact post-commit barrier, cancels its
caller context, and proves the wait returns `context.Canceled` without
relying on scheduler timing.
- `TestInternalExecutorCommittedLogWaitContract` covers the neighboring
contract: disabled and empty-timestamp no-op paths, success, and error
propagation.
- The issue's exact integration reproducer,
`pkg/embed.TestBasicCluster`, passes under the race detector after the
change.

BVT is not appropriate for this lifecycle defect because SQL cannot
deterministically hold the internal timestamp waiter at the cancellation
boundary; the focused unit test provides that synchronization with
channel barriers, while `TestBasicCluster` covers the real
embedded-cluster path.

### Validation

- Rebased cleanly onto `main` at
`11981033c588d3fe7e6fcc50ead874dfcd88d8f8`; the upstream delta did not
touch either changed file.
- `CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include"
CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" GOWORK=off go build
-mod=readonly ./pkg/sql/compile`
- `CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include"
CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" GOWORK=off go vet
-mod=readonly ./pkg/sql/compile`
- Focused new unit tests with `-race -count=100`: pass
- `TestBasicCluster` race measurement: `T=20.06s`; with `B=30s`, `N=1`
- `TestBasicCluster` again on the final rebased head with `-race
-count=1`: pass in 25.421s
- Full `pkg/sql/compile` and dependent `pkg/incrservice`, normal and
race: pass on the final rebased head
- `git diff --check origin/main...HEAD`: pass

### Residual risk

The CI resource-pressure condition that delayed logtail application is
intermittent and was not forced locally. The invalid wait-for edge is
independently proven by the preserved CI stack and deterministic
cancellation regression; the exact embedded-cluster case also completes
under race. The behavior after a visibility-wait failure changes from a
process-fatal path to an error returned after commit, matching the
existing `ExecTxn` error contract. Auto-increment callers may retry and
skip committed values, which is already permitted for auto-increment
allocation failures.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27073

## What this PR does / why we need it:

### Root cause

`pkg/incrservice` asks the internal SQL executor to wait until a
committed auto-increment update is visible in the local logtail. After
committing with the caller-owned allocation context,
`sqlExecutor.ExecTxn` discarded that context and called
`TxnClient.SyncLatestCommitTS`. That API creates an independent
five-minute background timeout and handles a failed wait with a fatal
log. Consequently, allocator cancellation, its three-minute deadline,
and CN shutdown could not release the post-commit wait. Under the
race-UT load captured in matrixorigin#27073, `TestBasicCluster` remained in
`sqlStore.Allocate -> SyncLatestCommitTS` until that independent
timeout, and earlier runs outlived the whole UT job deadline.

The local transaction commit already advances the transaction client's
latest commit timestamp through its `ClosedEvent` callback. The missing
property was a cancelable visibility barrier, not another timestamp
update.

### Changes

- Route the internal executor's post-commit visibility barrier through
the existing `WaitLogTailAppliedAt` API with the transaction executor's
caller-owned context.
- Return visibility-wait errors from `ExecTxn` after commit instead of
entering the fatal background wait.
- Add deterministic unit coverage for caller cancellation, disabled
waits, empty commit timestamps, successful waits, and wait-error
propagation.

No retry, fallback, timeout tuning, public API, or unrelated
embedded-cluster behavior is changed.

### Issue-to-test proof

- `TestInternalExecutorCommittedLogWaitHonorsCallerCancellation`
deterministically enters the exact post-commit barrier, cancels its
caller context, and proves the wait returns `context.Canceled` without
relying on scheduler timing.
- `TestInternalExecutorCommittedLogWaitContract` covers the neighboring
contract: disabled and empty-timestamp no-op paths, success, and error
propagation.
- The issue's exact integration reproducer,
`pkg/embed.TestBasicCluster`, passes under the race detector after the
change.

BVT is not appropriate for this lifecycle defect because SQL cannot
deterministically hold the internal timestamp waiter at the cancellation
boundary; the focused unit test provides that synchronization with
channel barriers, while `TestBasicCluster` covers the real
embedded-cluster path.

### Validation

- Rebased cleanly onto `main` at
`11981033c588d3fe7e6fcc50ead874dfcd88d8f8`; the upstream delta did not
touch either changed file.
- `CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include"
CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" GOWORK=off go build
-mod=readonly ./pkg/sql/compile`
- `CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include"
CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" GOWORK=off go vet
-mod=readonly ./pkg/sql/compile`
- Focused new unit tests with `-race -count=100`: pass
- `TestBasicCluster` race measurement: `T=20.06s`; with `B=30s`, `N=1`
- `TestBasicCluster` again on the final rebased head with `-race
-count=1`: pass in 25.421s
- Full `pkg/sql/compile` and dependent `pkg/incrservice`, normal and
race: pass on the final rebased head
- `git diff --check origin/main...HEAD`: pass

### Residual risk

The CI resource-pressure condition that delayed logtail application is
intermittent and was not forced locally. The invalid wait-for edge is
independently proven by the preserved CI stack and deterministic
cancellation regression; the exact embedded-cluster case also completes
under race. The behavior after a visibility-wait failure changes from a
process-fatal path to an error returned after commit, matching the
existing `ExecTxn` error contract. Auto-increment callers may retry and
skip committed values, which is already permitted for auto-increment
allocation failures.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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.

[Bug]: pkg/embed TestBasicCluster can hang until the Ubuntu race UT deadline

3 participants