Skip to content

fix(frontend): order account lifecycle gates - #28436

Merged
mergify[bot] merged 4 commits into
matrixorigin:mainfrom
LeftHandCold:fix/account-snapshot-gate-order-28433
Sep 8, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:mainfrom
LeftHandCold:fix/account-snapshot-gate-order-28433

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #28433

What this PR does / why we need it:

CREATE ACCOUNT acquired the per-account __mo_account_lock first and later
entered the global SNAPSHOT lifecycle gate while revalidating account View
metadata. A standalone DROP ACCOUNT already enters the SNAPSHOT lineage
lifecycle barrier before acquiring the same account-name lock. Concurrent
CREATE/DROP of one account could therefore form a distributed lock cycle.

Take the existing SNAPSHOT gate at the beginning of CREATE's owned
transaction, before the account-name lock. This preserves DROP's owner
publication barrier and aligns CREATE, DROP, and data-branch target-account
locking to one order:

SNAPSHOT lifecycle gate -> __mo_account_lock

The compatibility behavior for deployments where the View metadata catalog is
not available is retained: when View metadata refresh is disabled, missing
catalog-table errors still bypass the optional gate.

Validation:

  • go test -mod=readonly -list '^TestInitGeneralTenantLocksSnapshotBeforeAccountName$' ./pkg/frontend
  • go test -mod=readonly -ldflags="..." -v -count=1 -timeout=5m -run '^TestInitGeneralTenantLocksSnapshotBeforeAccountName$' ./pkg/frontend
    • both passed in the CGo-enabled local image on 10.1.222.50.
  • Built the PR branch image and ran a real two-CN make dev-up cluster on 10.1.222.50.
    • CREATE ran on CN1 and same-name DROP on CN2, with the previously reproducing 150ms interleave.
    • 13/13 CREATE/DROP pairs succeeded; neither CN logged 20701 or a deadlock; final account residue was 0.

The focused UT is intentionally an ordering/error-path test. The two-CN SQL
replay supplies the public distributed-lock validation without adding a
timing-dependent BVT.

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

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Review conclusion at b96d410: no blocking code finding; recommend approval once required CI passes.

Read the complete three-file diff against base/merge-base fe802bd and traced #28433 through CREATE, standalone DROP, data-branch target-account admission, View lifecycle locking, and transaction completion. The new gate is acquired inside CREATE’s owned transaction before __mo_account_lock. The later SNAPSHOT -> View order remains intact, and DROP’s owner-publication write barrier is unchanged. ALTER ACCOUNT does not introduce a reverse SNAPSHOT acquisition in the checked transaction path.

Audit Result
Q1 ownership Existing transaction owns both locks through commit/rollback; gate errors return through finishTxn. System context changes resolution only, not transaction ownership.
Q2 lock order Removes the concrete account-name -> SNAPSHOT / SNAPSHOT -> account-name cycle. No new mutex/goroutine or independent wait mechanism; existing transaction cancellation and completion remain responsible.
Q3 boundedness Adds one existing catalog-row lock request per CREATE; no new registry, queue or retained allocation.

Compatibility fallback remains restricted to missing-table/missing-database errors when View metadata refresh is disabled; ordinary lock/transaction errors are not swallowed. The focused UT correctly checks failure-before-account-lock plus rollback. Author reports the focused CGo UT and 13/13 real two-CN CREATE/DROP pairs with zero residue; those are author-run evidence, not tests I independently executed. Diff check passed. Current CI run 34249898003 is still running, so this is not a claim of completed CI or a waiver of its checks. No live environment or heavyweight UT was started during review.

Operational caveat: acquiring the existing global SNAPSHOT gate earlier lengthens its hold interval and serializes CREATE initialization with other lifecycle work. That is the explicit lock-order tradeoff here, not a fix for the separate #28079 lifecycle-throughput issue; no throughput improvement is claimed. During a mixed-version rollout, old CNs still retain the old ordering until upgraded.

The authenticated account is the PR author; GitHub does not permit a formal self-APPROVE. Recording the recommendation for an independent maintainer.

@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 at b96d410 against base/merge-base fe802bd: no confirmed blocker. APPROVE.

Reviewed every hunk in authenticate.go, authenticate_test.go and snapshot.go, and traced CREATE, standalone DROP, restore account recreation, data-branch target-account admission (including explicit-transaction fast-fail commit validation), ALTER ACCOUNT, View gate ordering and transaction completion. This is a bounded bug fix to existing locking, so the feature-design artifact gate is not triggered.

The R3 contract is consistent: CREATE takes the sys SNAPSHOT row in its existing transaction before __mo_account_lock, and later retains SNAPSHOT -> View ordering. DROP's owner-publication write barrier is preserved. ALTER does not acquire SNAPSHOT after its account-name lock. The compatibility helper preserves the existing restriction to NoSuchTable/BadDB while View metadata refresh is disabled; other failures propagate. An ignored gate error is overwritten by the subsequent account-lock SQL construction before transaction completion.

Audit Result
Q1 ownership/error paths The same background transaction owns both locks through commit/rollback. Gate failure reaches finishTxn before account mutation; commit failure attempts rollback. Account resolution changes do not create another transaction.
Q2 ordering/liveness Removes the account-name -> SNAPSHOT versus SNAPSHOT -> account-name cycle. Existing transaction cancellation/completion remains the release mechanism; no new local mutex, callback, goroutine or cleanup wait. Explicit branch commit admission remains FastFail.
Q3 boundedness One additional existing-row query per CREATE; its result is cleared before account locking. No new retained collection or worker.
Compatibility/performance No schema, protocol, config or generated-artifact change. Earlier global-gate acquisition extends serialization across account initialization; this is the accepted lock-order tradeoff, not a throughput improvement. Old CNs retain old ordering until upgraded.

Validation reused: exact-head Actions run 34249898003 completed successfully, including Linux UT (log confirms race mode), UT coverage, shared build, SCA and both active multi-CN BVT jobs. The downloaded coverage artifact records execution of the added gate and error-return blocks. The new injected-error UT has a deterministic begin -> gate -> rollback oracle and excludes account locking. The author reports the named focused CGo UT and 13/13 real two-CN CREATE/DROP pairs with zero residue; these are author-run evidence, not independently replayed tests. No changed in-process concurrent test warrants repeated Go race stress for this SQL lock-order fix. Skipped CI jobs are not counted as passes. Exact-range diff check passed.

No code or working-tree files changed during this review.

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

mergify Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-08 17:29 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-09-08 18:20 UTC · at 6d44c50e964cf5ecd3eed02d478bd222c07d777a · squash

This pull request spent 51 minutes 44 seconds in the queue, including 51 minutes 16 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 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
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • 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)

@mergify
mergify Bot merged commit 6d44c50 into matrixorigin:main Sep 8, 2026
28 of 29 checks passed
@mergify mergify Bot removed the queued label Sep 8, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
`CREATE ACCOUNT` acquired the per-account `__mo_account_lock` first and later
entered the global `SNAPSHOT` lifecycle gate while revalidating account View
metadata. A standalone `DROP ACCOUNT` already enters the `SNAPSHOT` lineage
lifecycle barrier before acquiring the same account-name lock. Concurrent
CREATE/DROP of one account could therefore form a distributed lock cycle.

Take the existing `SNAPSHOT` gate at the beginning of CREATE's owned
transaction, before the account-name lock. This preserves DROP's owner
publication barrier and aligns CREATE, DROP, and data-branch target-account
locking to one order:

```
SNAPSHOT lifecycle gate -> __mo_account_lock
```

The compatibility behavior for deployments where the View metadata catalog is
not available is retained: when View metadata refresh is disabled, missing
catalog-table errors still bypass the optional gate.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
`CREATE ACCOUNT` acquired the per-account `__mo_account_lock` first and later
entered the global `SNAPSHOT` lifecycle gate while revalidating account View
metadata. A standalone `DROP ACCOUNT` already enters the `SNAPSHOT` lineage
lifecycle barrier before acquiring the same account-name lock. Concurrent
CREATE/DROP of one account could therefore form a distributed lock cycle.

Take the existing `SNAPSHOT` gate at the beginning of CREATE's owned
transaction, before the account-name lock. This preserves DROP's owner
publication barrier and aligns CREATE, DROP, and data-branch target-account
locking to one order:

```
SNAPSHOT lifecycle gate -> __mo_account_lock
```

The compatibility behavior for deployments where the View metadata catalog is
not available is retained: when View metadata refresh is disabled, missing
catalog-table errors still bypass the optional gate.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
`CREATE ACCOUNT` acquired the per-account `__mo_account_lock` first and later
entered the global `SNAPSHOT` lifecycle gate while revalidating account View
metadata. A standalone `DROP ACCOUNT` already enters the `SNAPSHOT` lineage
lifecycle barrier before acquiring the same account-name lock. Concurrent
CREATE/DROP of one account could therefore form a distributed lock cycle.

Take the existing `SNAPSHOT` gate at the beginning of CREATE's owned
transaction, before the account-name lock. This preserves DROP's owner
publication barrier and aligns CREATE, DROP, and data-branch target-account
locking to one order:

```
SNAPSHOT lifecycle gate -> __mo_account_lock
```

The compatibility behavior for deployments where the View metadata catalog is
not available is retained: when View metadata refresh is disabled, missing
catalog-table errors still bypass the optional gate.

Approved by: @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 kind/test-ci size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CREATE/DROP ACCOUNT deadlocks on inverted account-name and SNAPSHOT gates

3 participants