Skip to content

fix(txn): preserve snapshot state on cancellation - #26774

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
aptend:fix/txn-snapshot-context-26767
Aug 7, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
aptend:fix/txn-snapshot-context-26767

Conversation

@aptend

@aptend aptend commented Aug 7, 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 #26767

What this PR does / why we need it:

  • Publish a new transaction snapshot only after the timestamp waiter succeeds, so cancellation and waiter errors cannot replace a valid snapshot with 0-0.
  • Propagate the statement context through disttae workspace writes, table lookup, dump, compaction, and duplicate checking instead of detaching catalog lookup with a background context.
  • Return an ordinary invalid-input error when a transaction operation has no context deadline instead of terminating the CN process.
  • Reject canceled delete operations before workspace mutation and cover the cancellation paths with regression tests.

The existing statement rollback contract remains responsible for undoing workspace changes when cancellation arrives after a statement has already started mutating its workspace.

Validation:

  • Full tests for pkg/txn/client, pkg/vm/engine/disttae, pkg/sql/colexec/deletion, and pkg/sql/compile.
  • Full race tests for pkg/txn/client and pkg/vm/engine/disttae.
  • Seven focused race tests, each repeated 100 times.
  • go build and go vet for all affected and dependent packages.

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

@iamlinjunhong iamlinjunhong 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 d68c908 against main@ab49099c0f487255df131f45c3aecf4a4650fed7.\n\nNo P0–P3 findings. I traced the cancellation path through disttae workspace writes, table lookup, dump/compaction, duplicate checking, and the nested internal-SQL/TN-debug path. SnapshotTS is now published only after the waiter succeeds; lookup error paths restore the workspace lock, and copied batches are cleaned on cancellation. The 25 current checks are complete with no failing conclusions.\n\nLocal focused tests could not start in the isolated worktree because the required native cgo/libmo.dylib artifact is not present; the completed PR CI was used as execution evidence.

@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 d68c908 against merge base main@ab49099c0f487255df131f45c3aecf4a4650fed7.

No P0-P3 findings. The change closes the relevant state and failure paths: SnapshotTS is published only after either timestamp-waiter variant succeeds; statement cancellation is retained through Delete/workspace write/table resolution/dump/compaction/duplicate checking; table-resolution unlock/relock ownership remains balanced on errors; and rejected writes clean copied batches without workspace mutation. A missing transaction-operation deadline now returns an ordinary error before any TN RPC instead of terminating the CN.

Compatibility/performance: there is no exported API change. The write path adds only constant-time nil/cancellation checks; the account context attachment replaces the previous context allocation, and no new scan, lock, goroutine, retry, or unbounded work is introduced.

Fresh local validation at this head:

  • focused regressions passed under race, count=20
  • full pkg/txn/client and pkg/vm/engine/disttae tests and race tests passed
  • full pkg/sql/colexec/deletion and pkg/sql/compile tests passed
  • go list/build/vet passed for all four affected/dependent packages
  • PR CI is green and the head is mergeable

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

mergify Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-07 08:14 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-07 08:59 UTC · at e9602424e0a408ca6e99fca2f663204668441586 · squash

This pull request spent 44 minutes 35 seconds in the queue, including 43 minutes 47 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 88cd602 into matrixorigin:main Aug 7, 2026
25 of 26 checks passed
@mergify mergify Bot removed the queued label Aug 7, 2026
mergify Bot pushed a commit that referenced this pull request Aug 10, 2026
Backport #26774 to `4.2-dev`.

- Publish a new transaction snapshot only after the timestamp waiter succeeds, so cancellation and waiter errors cannot replace a valid snapshot with `0-0`.
- Propagate the statement context through disttae workspace writes, table lookup, dump, compaction, and duplicate checking instead of detaching catalog lookup with a background context.
- Return an ordinary invalid-input error when a transaction operation has no context deadline instead of terminating the CN process.
- Reject canceled delete operations before workspace mutation and cover the cancellation paths with regression tests.

The existing statement rollback contract remains responsible for undoing workspace changes when cancellation arrives after a statement has already started mutating its workspace.

This is a clean cherry-pick of commit `d68c9083e9411e55264bc54bc3b88fe1d079396a` from #26774 onto `4.2-dev` at `60283acdd464788cc0a1f91ad3e035dddc9454c4`.

Validation:

- `go list`, `go build`, and `go vet` for `pkg/txn/client`, `pkg/vm/engine/disttae`, `pkg/sql/colexec/deletion`, and `pkg/sql/compile`.
- Full tests for those four packages.
- Full race tests for `pkg/txn/client` and `pkg/vm/engine/disttae`.
- Four focused cancellation/snapshot regressions under the race detector, each repeated 100 times.
- `git diff --check` and pre-push concurrency/unhappy-path self-review.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
- Publish a new transaction snapshot only after the timestamp waiter succeeds, so cancellation and waiter errors cannot replace a valid snapshot with 0-0.
- Propagate the statement context through disttae workspace writes, table lookup, dump, compaction, and duplicate checking instead of detaching catalog lookup with a background context.
- Return an ordinary invalid-input error when a transaction operation has no context deadline instead of terminating the CN process.
- Reject canceled delete operations before workspace mutation and cover the cancellation paths with regression tests.

The existing statement rollback contract remains responsible for undoing workspace changes when cancellation arrives after a statement has already started mutating its workspace.

Validation:

- Full tests for pkg/txn/client, pkg/vm/engine/disttae, pkg/sql/colexec/deletion, and pkg/sql/compile.
- Full race tests for pkg/txn/client and pkg/vm/engine/disttae.
- Seven focused race tests, each repeated 100 times.
- go build and go vet for all affected and dependent packages.

Approved by: @iamlinjunhong, @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
- Publish a new transaction snapshot only after the timestamp waiter succeeds, so cancellation and waiter errors cannot replace a valid snapshot with 0-0.
- Propagate the statement context through disttae workspace writes, table lookup, dump, compaction, and duplicate checking instead of detaching catalog lookup with a background context.
- Return an ordinary invalid-input error when a transaction operation has no context deadline instead of terminating the CN process.
- Reject canceled delete operations before workspace mutation and cover the cancellation paths with regression tests.

The existing statement rollback contract remains responsible for undoing workspace changes when cancellation arrives after a statement has already started mutating its workspace.

Validation:

- Full tests for pkg/txn/client, pkg/vm/engine/disttae, pkg/sql/colexec/deletion, and pkg/sql/compile.
- Full race tests for pkg/txn/client and pkg/vm/engine/disttae.
- Seven focused race tests, each repeated 100 times.
- go build and go vet for all affected and dependent packages.

Approved by: @iamlinjunhong, @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
- Publish a new transaction snapshot only after the timestamp waiter succeeds, so cancellation and waiter errors cannot replace a valid snapshot with 0-0.
- Propagate the statement context through disttae workspace writes, table lookup, dump, compaction, and duplicate checking instead of detaching catalog lookup with a background context.
- Return an ordinary invalid-input error when a transaction operation has no context deadline instead of terminating the CN process.
- Reject canceled delete operations before workspace mutation and cover the cancellation paths with regression tests.

The existing statement rollback contract remains responsible for undoing workspace changes when cancellation arrives after a statement has already started mutating its workspace.

Validation:

- Full tests for pkg/txn/client, pkg/vm/engine/disttae, pkg/sql/colexec/deletion, and pkg/sql/compile.
- Full race tests for pkg/txn/client and pkg/vm/engine/disttae.
- Seven focused race tests, each repeated 100 times.
- go build and go vet for all affected and dependent packages.

Approved by: @iamlinjunhong, @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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] CN FATAL exit: context deadline not set in txnOperator.validate during Delete → loadDatabaseFromStorage

4 participants