Repository navigation
fix(snapshot): avoid MVCC version in pessimistic lifecycle gate - #28262
Conversation
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? |
69621af to
d41710d
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 54 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
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
|
…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>
…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>
…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>
What type of PR is this?
Which issue(s) this PR fixes:
Related to #28259
What this PR does / why we need it:
Root cause
TestIssue23861FulltextSnapshotRestoreintermittently failed at the firstcreate snapshot ... for account syswithquery feature registry for SNAPSHOT failed. The lifecycle gate used a no-opUPDATEon the bootstrap-createdSNAPSHOTfeature-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 UPDATEon 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 inTestIssue26087ConcurrentDataBranchQuota: a branch transaction could commit after a completed snapshot owner writer instead of being rejected.Changes
pkg/frontend/databranchutils.SELECT feature_code ... FOR UPDATEonly while admitting feature-limited owner mutations, so the pessimistic quota/registry reads do not create an extra feature-registry MVCC version.UPDATEwrite barrier before the owner mutation. Failed admission does not materialize it and follows the existing rollback path.Issue-to-test proof
TestIssue23861FulltextSnapshotRestoreexercises 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.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.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/issuesTestLineageOwnerLifecycleLockSQLForTxnUsesPessimisticRowLockandTestValidateDataBranchLineageOwnerLifecycleAtCommitFastFailsStableWrite./pkg/frontendand./pkg/frontend/databranchutils./pkg/sql/compileand./pkg/publicationTestLineageOwnerLifecycleLockSerializesEmptyProbeResidual 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.