Repository navigation
fix: make internal SQL logtail waits cancelable - #27168
Conversation
61ebdf1 to
06acb63
Compare
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Merge Queue Status
This pull request spent 19 minutes 21 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe pull request can't be updated
Failing checks:
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
## 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>
## 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>
## 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>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27073
What this PR does / why we need it:
Root cause
pkg/incrserviceasks 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.ExecTxndiscarded that context and calledTxnClient.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,TestBasicClusterremained insqlStore.Allocate -> SyncLatestCommitTSuntil 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
ClosedEventcallback. The missing property was a cancelable visibility barrier, not another timestamp update.Changes
WaitLogTailAppliedAtAPI with the transaction executor's caller-owned context.ExecTxnafter commit instead of entering the fatal background wait.No retry, fallback, timeout tuning, public API, or unrelated embedded-cluster behavior is changed.
Issue-to-test proof
TestInternalExecutorCommittedLogWaitHonorsCallerCancellationdeterministically enters the exact post-commit barrier, cancels its caller context, and proves the wait returnscontext.Canceledwithout relying on scheduler timing.TestInternalExecutorCommittedLogWaitContractcovers the neighboring contract: disabled and empty-timestamp no-op paths, success, and error propagation.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
TestBasicClustercovers the real embedded-cluster path.Validation
mainat11981033c588d3fe7e6fcc50ead874dfcd88d8f8; 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/compileCGO_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-race -count=100: passTestBasicClusterrace measurement:T=20.06s; withB=30s,N=1TestBasicClusteragain on the final rebased head with-race -count=1: pass in 25.421spkg/sql/compileand dependentpkg/incrservice, normal and race: pass on the final rebased headgit diff --check origin/main...HEAD: passResidual 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
ExecTxnerror contract. Auto-increment callers may retry and skip committed values, which is already permitted for auto-increment allocation failures.