Skip to content

fix(snapshot): avoid MVCC version in pessimistic lifecycle gate - #28262

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-28259-688a4881
Sep 5, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-28259-688a4881

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Sep 5, 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:

Related to #28259

What this PR does / why we need it:

Root cause

TestIssue23861FulltextSnapshotRestore intermittently failed at the first create snapshot ... for account sys with query feature registry for SNAPSHOT failed. The lifecycle gate used a no-op UPDATE on the bootstrap-created SNAPSHOT feature-registry row before the quota lookup. In a pessimistic RC transaction, that update creates an MVCC version; the subsequent strict registry query can observe both row versions and return the internal error.

The first mode-aware implementation replaced that write with SELECT ... FOR UPDATE on every pessimistic path. That removed the extra version for #28259, but it also removed the write dependency used by explicit data-branch transactions at commit. The coverage run then exposed the regression in TestIssue26087ConcurrentDataBranchQuota: a branch transaction could commit after a completed snapshot owner writer instead of being rejected.

Changes

  • Add shared lifecycle-gate SQL for pessimistic row locking and transaction-mode selection in pkg/frontend/databranchutils.
  • Use SELECT feature_code ... FOR UPDATE only while admitting feature-limited owner mutations, so the pessimistic quota/registry reads do not create an extra feature-registry MVCC version.
  • After feature admission succeeds, materialize the existing no-op UPDATE write barrier before the owner mutation. Failed admission does not materialize it and follows the existing rollback path.
  • Keep the existing write barrier for optimistic owner publication, direct non-quota lifecycle paths, and explicit-transaction commit validation. The commit path uses fast-fail validation so a stale data-branch transaction cannot commit after a completed owner writer.
  • Keep the gate, quota checks, and owner publication in the same transaction and clear/reset the pending lifecycle state on result cleanup and session close.
  • Add focused unit coverage for the pessimistic row-lock SQL and preserve the stable write-barrier/commit-validation assertions.

Issue-to-test proof

  • Related to test(issues): SNAPSHOT feature-registry gate flakes under UT coverage #28259: TestIssue23861FulltextSnapshotRestore exercises the exact snapshot creation, fulltext table, feature-registry quota lookup, concurrent restore rounds, and final row assertion. The final code passed the exact CGo/tag test and the same test under race detection for two iterations.
  • The coverage regression is directly covered by TestIssue26087ConcurrentDataBranchQuota, including the stale explicit-transaction commit and replacement-begin terminal paths. It passed after the two-phase pessimistic admission protocol and under race detection for two iterations.
  • Unit tests assert the pessimistic row-lock SQL, stable write-barrier SQL, fast-fail commit-validation options, and lifecycle admission ordering.

Tests run

  • make -j8 cgo
  • .agents/skills/mo-dev/scripts/mo-cgo-test -short -v -count=1 -timeout=300s -tags matrixone_test -run '^TestIssue23861FulltextSnapshotRestore$' ./pkg/tests/issues
  • .agents/skills/mo-dev/scripts/mo-cgo-test -short -v -count=1 -timeout=300s -tags matrixone_test -run '^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -short -v -count=2 -timeout=600s -tags matrixone_test -run '^TestIssue23861FulltextSnapshotRestore$' ./pkg/tests/issues
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -short -v -count=2 -timeout=600s -tags matrixone_test -run '^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues
  • Focused frontend unit tests for TestLineageOwnerLifecycleLockSQLForTxnUsesPessimisticRowLock and TestValidateDataBranchLineageOwnerLifecycleAtCommitFastFailsStableWrite
  • Full short tests for ./pkg/frontend and ./pkg/frontend/databranchutils
  • Full short tests for the unchanged direct consumers ./pkg/sql/compile and ./pkg/publication
  • Race validation for TestLineageOwnerLifecycleLockSerializesEmptyProbe

Residual risks

The original failure is nondeterministic and depends on embedded-cluster scheduling under the Ubuntu UT-coverage workload; local CGo and race runs are strong but not identical to that hosted workload. The new GitHub run must still validate the pushed head. Optimistic transactions and direct non-quota lifecycle paths retain their existing write-barrier behavior. No retry, fallback, skip, or alternate error path was added.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 5, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Sep 5, 2026
@gouhongshen
gouhongshen marked this pull request as ready for review September 5, 2026 14:52
@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.

Deep review complete at d41710d.

The two-phase pessimistic admission protocol is sound: SELECT FOR UPDATE establishes ordering before quota reads, the deferred no-op UPDATE restores the write dependency after successful admission, and explicit data-branch transactions retain commit-time fast-fail validation. This fixes the duplicate workspace/MVCC-version failure without reopening the stale explicit-transaction commit race caught by the first revision.

I checked snapshot and data-branch call sites, optimistic/direct paths, fixed-SI handling, error cleanup, lock ordering, result ownership, and performance. Failure paths roll back the owned transaction and clear pending state; there is no new unbounded wait, goroutine, or collection. The extra statement is confined to low-frequency feature-limited owner mutations and does not add another lock wait after the row lock is held.

Validation is proportionate for this shared-state change: the original fulltext snapshot reproducer and concurrent data-branch quota regression cover both sides of the protocol, including race runs; Linux UT, SCA, coverage, PROXY BVT, and pessimistic multi-CN BVT are green. Latest main drift is an unrelated Iceberg waiter test change. No blocking correctness, concurrency, unhappy-path, or performance issue found.

@mergify mergify Bot added the queued label Sep 5, 2026
@mergify

mergify Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-05 16:35 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-05 16:36 UTC · at 5ec014fb0bbb63a55ed8db3436d3e502f2caa50b

This pull request spent 54 seconds in the queue, with no time running CI.

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.

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 f2e188f into matrixorigin:main Sep 5, 2026
21 of 22 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 5, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…ixorigin#28262)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#28259

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

### Root cause

`TestIssue23861FulltextSnapshotRestore` intermittently failed at the
first `create snapshot ... for account sys` with `query feature registry
for SNAPSHOT failed`. The lifecycle gate used a no-op `UPDATE` on the
bootstrap-created `SNAPSHOT` feature-registry row before the quota
lookup. In a pessimistic RC transaction, that update creates an MVCC
version; the subsequent strict registry query can observe both row
versions and return the internal error.

The first mode-aware implementation replaced that write with `SELECT ...
FOR UPDATE` on every pessimistic path. That removed the extra version
for matrixorigin#28259, but it also removed the write dependency used by explicit
data-branch transactions at commit. The coverage run then exposed the
regression in `TestIssue26087ConcurrentDataBranchQuota`: a branch
transaction could commit after a completed snapshot owner writer instead
of being rejected.

### Changes

- Add shared lifecycle-gate SQL for pessimistic row locking and
transaction-mode selection in `pkg/frontend/databranchutils`.
- Use `SELECT feature_code ... FOR UPDATE` only while admitting
feature-limited owner mutations, so the pessimistic quota/registry reads
do not create an extra feature-registry MVCC version.
- After feature admission succeeds, materialize the existing no-op
`UPDATE` write barrier before the owner mutation. Failed admission does
not materialize it and follows the existing rollback path.
- Keep the existing write barrier for optimistic owner publication,
direct non-quota lifecycle paths, and explicit-transaction commit
validation. The commit path uses fast-fail validation so a stale
data-branch transaction cannot commit after a completed owner writer.
- Keep the gate, quota checks, and owner publication in the same
transaction and clear/reset the pending lifecycle state on result
cleanup and session close.
- Add focused unit coverage for the pessimistic row-lock SQL and
preserve the stable write-barrier/commit-validation assertions.

### Issue-to-test proof

- Related to matrixorigin#28259: `TestIssue23861FulltextSnapshotRestore` exercises
the exact snapshot creation, fulltext table, feature-registry quota
lookup, concurrent restore rounds, and final row assertion. The final
code passed the exact CGo/tag test and the same test under race
detection for two iterations.
- The coverage regression is directly covered by
`TestIssue26087ConcurrentDataBranchQuota`, including the stale
explicit-transaction commit and replacement-begin terminal paths. It
passed after the two-phase pessimistic admission protocol and under race
detection for two iterations.
- Unit tests assert the pessimistic row-lock SQL, stable write-barrier
SQL, fast-fail commit-validation options, and lifecycle admission
ordering.

### Tests run

- `make -j8 cgo`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -short -v -count=1
-timeout=300s -tags matrixone_test -run
'^TestIssue23861FulltextSnapshotRestore$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -short -v -count=1
-timeout=300s -tags matrixone_test -run
'^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -short -v -count=2
-timeout=600s -tags matrixone_test -run
'^TestIssue23861FulltextSnapshotRestore$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -short -v -count=2
-timeout=600s -tags matrixone_test -run
'^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues`
- Focused frontend unit tests for
`TestLineageOwnerLifecycleLockSQLForTxnUsesPessimisticRowLock` and
`TestValidateDataBranchLineageOwnerLifecycleAtCommitFastFailsStableWrite`
- Full short tests for `./pkg/frontend` and
`./pkg/frontend/databranchutils`
- Full short tests for the unchanged direct consumers
`./pkg/sql/compile` and `./pkg/publication`
- Race validation for
`TestLineageOwnerLifecycleLockSerializesEmptyProbe`

### Residual risks

The original failure is nondeterministic and depends on embedded-cluster
scheduling under the Ubuntu UT-coverage workload; local CGo and race
runs are strong but not identical to that hosted workload. The new
GitHub run must still validate the pushed head. Optimistic transactions
and direct non-quota lifecycle paths retain their existing write-barrier
behavior. No retry, fallback, skip, or alternate error path was added.

---------

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
…ixorigin#28262)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#28259

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

### Root cause

`TestIssue23861FulltextSnapshotRestore` intermittently failed at the
first `create snapshot ... for account sys` with `query feature registry
for SNAPSHOT failed`. The lifecycle gate used a no-op `UPDATE` on the
bootstrap-created `SNAPSHOT` feature-registry row before the quota
lookup. In a pessimistic RC transaction, that update creates an MVCC
version; the subsequent strict registry query can observe both row
versions and return the internal error.

The first mode-aware implementation replaced that write with `SELECT ...
FOR UPDATE` on every pessimistic path. That removed the extra version
for matrixorigin#28259, but it also removed the write dependency used by explicit
data-branch transactions at commit. The coverage run then exposed the
regression in `TestIssue26087ConcurrentDataBranchQuota`: a branch
transaction could commit after a completed snapshot owner writer instead
of being rejected.

### Changes

- Add shared lifecycle-gate SQL for pessimistic row locking and
transaction-mode selection in `pkg/frontend/databranchutils`.
- Use `SELECT feature_code ... FOR UPDATE` only while admitting
feature-limited owner mutations, so the pessimistic quota/registry reads
do not create an extra feature-registry MVCC version.
- After feature admission succeeds, materialize the existing no-op
`UPDATE` write barrier before the owner mutation. Failed admission does
not materialize it and follows the existing rollback path.
- Keep the existing write barrier for optimistic owner publication,
direct non-quota lifecycle paths, and explicit-transaction commit
validation. The commit path uses fast-fail validation so a stale
data-branch transaction cannot commit after a completed owner writer.
- Keep the gate, quota checks, and owner publication in the same
transaction and clear/reset the pending lifecycle state on result
cleanup and session close.
- Add focused unit coverage for the pessimistic row-lock SQL and
preserve the stable write-barrier/commit-validation assertions.

### Issue-to-test proof

- Related to matrixorigin#28259: `TestIssue23861FulltextSnapshotRestore` exercises
the exact snapshot creation, fulltext table, feature-registry quota
lookup, concurrent restore rounds, and final row assertion. The final
code passed the exact CGo/tag test and the same test under race
detection for two iterations.
- The coverage regression is directly covered by
`TestIssue26087ConcurrentDataBranchQuota`, including the stale
explicit-transaction commit and replacement-begin terminal paths. It
passed after the two-phase pessimistic admission protocol and under race
detection for two iterations.
- Unit tests assert the pessimistic row-lock SQL, stable write-barrier
SQL, fast-fail commit-validation options, and lifecycle admission
ordering.

### Tests run

- `make -j8 cgo`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -short -v -count=1
-timeout=300s -tags matrixone_test -run
'^TestIssue23861FulltextSnapshotRestore$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -short -v -count=1
-timeout=300s -tags matrixone_test -run
'^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -short -v -count=2
-timeout=600s -tags matrixone_test -run
'^TestIssue23861FulltextSnapshotRestore$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -short -v -count=2
-timeout=600s -tags matrixone_test -run
'^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues`
- Focused frontend unit tests for
`TestLineageOwnerLifecycleLockSQLForTxnUsesPessimisticRowLock` and
`TestValidateDataBranchLineageOwnerLifecycleAtCommitFastFailsStableWrite`
- Full short tests for `./pkg/frontend` and
`./pkg/frontend/databranchutils`
- Full short tests for the unchanged direct consumers
`./pkg/sql/compile` and `./pkg/publication`
- Race validation for
`TestLineageOwnerLifecycleLockSerializesEmptyProbe`

### Residual risks

The original failure is nondeterministic and depends on embedded-cluster
scheduling under the Ubuntu UT-coverage workload; local CGo and race
runs are strong but not identical to that hosted workload. The new
GitHub run must still validate the pushed head. Optimistic transactions
and direct non-quota lifecycle paths retain their existing write-barrier
behavior. No retry, fallback, skip, or alternate error path was added.

---------

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
…ixorigin#28262)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#28259

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

### Root cause

`TestIssue23861FulltextSnapshotRestore` intermittently failed at the
first `create snapshot ... for account sys` with `query feature registry
for SNAPSHOT failed`. The lifecycle gate used a no-op `UPDATE` on the
bootstrap-created `SNAPSHOT` feature-registry row before the quota
lookup. In a pessimistic RC transaction, that update creates an MVCC
version; the subsequent strict registry query can observe both row
versions and return the internal error.

The first mode-aware implementation replaced that write with `SELECT ...
FOR UPDATE` on every pessimistic path. That removed the extra version
for matrixorigin#28259, but it also removed the write dependency used by explicit
data-branch transactions at commit. The coverage run then exposed the
regression in `TestIssue26087ConcurrentDataBranchQuota`: a branch
transaction could commit after a completed snapshot owner writer instead
of being rejected.

### Changes

- Add shared lifecycle-gate SQL for pessimistic row locking and
transaction-mode selection in `pkg/frontend/databranchutils`.
- Use `SELECT feature_code ... FOR UPDATE` only while admitting
feature-limited owner mutations, so the pessimistic quota/registry reads
do not create an extra feature-registry MVCC version.
- After feature admission succeeds, materialize the existing no-op
`UPDATE` write barrier before the owner mutation. Failed admission does
not materialize it and follows the existing rollback path.
- Keep the existing write barrier for optimistic owner publication,
direct non-quota lifecycle paths, and explicit-transaction commit
validation. The commit path uses fast-fail validation so a stale
data-branch transaction cannot commit after a completed owner writer.
- Keep the gate, quota checks, and owner publication in the same
transaction and clear/reset the pending lifecycle state on result
cleanup and session close.
- Add focused unit coverage for the pessimistic row-lock SQL and
preserve the stable write-barrier/commit-validation assertions.

### Issue-to-test proof

- Related to matrixorigin#28259: `TestIssue23861FulltextSnapshotRestore` exercises
the exact snapshot creation, fulltext table, feature-registry quota
lookup, concurrent restore rounds, and final row assertion. The final
code passed the exact CGo/tag test and the same test under race
detection for two iterations.
- The coverage regression is directly covered by
`TestIssue26087ConcurrentDataBranchQuota`, including the stale
explicit-transaction commit and replacement-begin terminal paths. It
passed after the two-phase pessimistic admission protocol and under race
detection for two iterations.
- Unit tests assert the pessimistic row-lock SQL, stable write-barrier
SQL, fast-fail commit-validation options, and lifecycle admission
ordering.

### Tests run

- `make -j8 cgo`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -short -v -count=1
-timeout=300s -tags matrixone_test -run
'^TestIssue23861FulltextSnapshotRestore$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -short -v -count=1
-timeout=300s -tags matrixone_test -run
'^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -short -v -count=2
-timeout=600s -tags matrixone_test -run
'^TestIssue23861FulltextSnapshotRestore$' ./pkg/tests/issues`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -short -v -count=2
-timeout=600s -tags matrixone_test -run
'^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues`
- Focused frontend unit tests for
`TestLineageOwnerLifecycleLockSQLForTxnUsesPessimisticRowLock` and
`TestValidateDataBranchLineageOwnerLifecycleAtCommitFastFailsStableWrite`
- Full short tests for `./pkg/frontend` and
`./pkg/frontend/databranchutils`
- Full short tests for the unchanged direct consumers
`./pkg/sql/compile` and `./pkg/publication`
- Race validation for
`TestLineageOwnerLifecycleLockSerializesEmptyProbe`

### Residual risks

The original failure is nondeterministic and depends on embedded-cluster
scheduling under the Ubuntu UT-coverage workload; local CGo and race
runs are strong but not identical to that hosted workload. The new
GitHub run must still validate the pushed head. Optimistic transactions
and direct non-quota lifecycle paths retain their existing write-barrier
behavior. No retry, fallback, skip, or alternate error path was added.

---------

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.

3 participants