Repository navigation
fix: preserve account lifecycle ordering under concurrency - #29234
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
GPT-6 high review at exact head 78a33f9 (base bbbfb70): REQUEST_CHANGES.
[P2] Mixed-version deployments can lose writer fairness. pkg/frontend/snapshot.go:3552 switches to Shared unconditionally and relies on WriterFair, but an old lock owner does not understand that field; its existing Shared admission still allows new Shared holders to pass queued lifecycle writers. The lock RPC has no capability/version admission for this behavior. Add a compatible fallback or gate shared fairness on supported owners, plus old-owner/old-execution-node coverage.
[P2] The public regression does not prove that the View gate is no longer serialized. The test observes two CREATE operations at the account-name/SNAPSHOT gate, releases those locks, and only checks final success. It can still pass if inheritViewMetadataRevalidation uses an exclusive FOR UPDATE gate and the operations serialize there. Add a deterministic observation at the View-gate phase, including queued-writer blocking of later readers and same-transaction re-entry.
[P2] Integration-test cleanup can report success with residue. cleanupAccounts uses execSQLMaybe and swallows DROP errors without verifying deletion. issue28079HoldAccountName performs fallible operations before registering connection/rollback cleanup, so an early failure can leak the connection/transaction. Make teardown errors visible, establish cleanup ownership immediately, and independently verify no accounts/transactions remain.
Current-head CI, race integration, SCA and lint are green, but mixed-version, repeated same-instance cleanup, and deployment concurrency evidence remain unverified. No confirmed new production double-cleanup or deadlock was found beyond these blockers.
iamlinjunhong
left a comment
There was a problem hiding this comment.
Review at exact head 78a33f9. All 29 checks are completed with no failing conclusion, and the PR is mergeable (behind).
No P0/P1 issue is confirmed. Three P2 findings remain. The previous review P2s have no author reply in review threads or PR conversation, so this is submitted as COMMENT.
[P2] Mixed-version lock owner can ignore WriterFair
Location: pkg/lockservice/lock_table_proxy.go:172-178; pkg/lockservice/lock.go:198-203.
A new CN with protocol v28+ creates the proxy and sends a WriterFair Shared request directly to the owner, but the routing decision only checks the origin CN protocolServiceID. An older owner does not understand the new field and its isLockModeAllowed path still admits any Shared row request while an Exclusive waiter is queued. Continuous CREATE ACCOUNT readers can therefore bypass a queued lifecycle writer during a rolling upgrade and starve the writer. Add owner capability negotiation or a compatible fallback, with an old-owner/new-owner mixed-version test.
[P2] The integration test does not prove that the View gate is shared
Location: pkg/tests/issues/issue_28079_test.go:114-117.
The regression only observes concurrent Shared holders on the SNAPSHOT feature-registry row. It never observes the mo_view_refresh row, queues an Exclusive writer there, or checks same-transaction re-entry. A regression that changes ViewMetadataLifecycleSharedGateSQL back to an exclusive lock can therefore still pass. Add a deterministic View-gate observation covering queued-writer blocking and re-entry.
[P2] Integration-test cleanup can leave residue and leaked connections
Location: pkg/tests/issues/issue_28079_test.go:51-59, 167-177.
cleanupAccounts calls execSQLMaybe, which discards DROP errors and does not verify deletion. issue28079HoldAccountName acquires a connection and begins a transaction before the caller installs its defers, so a failure in db.Conn, begin, or FOR UPDATE can bypass cleanup. Make teardown errors visible, verify the accounts and transactions are gone, and register connection/rollback ownership immediately after acquisition.
aunjgr
left a comment
There was a problem hiding this comment.
[P1] Writer fairness is not compatible with old lock owners during a rolling upgrade
Reviewed 78a33f9 against merge-base bbbfb70.
This change immediately replaces CREATE ACCOUNT's exclusive lifecycle gates with Shared locks and relies on the new LockOptions.WriterFair bit to stop later readers from passing a queued Exclusive writer. That bit is added to the lock protobuf without a negotiated lock-protocol capability or fallback. An old release lock owner decodes the unknown field as false; an old remote pipeline also drops SessionInfo.LockWriterFair.
Concrete rolling-upgrade sequence: existing Shared CREATE holders are active, DROP/restore queues an Exclusive lifecycle writer, and new-binary CNs continue issuing CREATE ACCOUNT. If the authoritative lock owner is old, every new Shared request can join the current holder generation, so the lifecycle writer can be starved indefinitely. Before this PR CREATE used Exclusive gates, so this mixed-version availability regression did not exist.
Allocate and negotiate a lock capability for writer-fair admission. Until every possible owner supports it, retain an admission path that cannot barge ahead of lifecycle writers. Add an old-owner/new-client regression with a queued writer and repeated readers, including remote process forwarding.
This PR also introduces a distributed lock-admission policy across frontend, pipeline transport, proxy, owner queue, cancellation, and lifecycle DDL but has no approved design artifact covering mixed-version operation, failure transitions, and rollout. The repository design gate therefore remains open in addition to the concrete compatibility defect. Current same-version CI and diff checks pass.
78a33f9 to
3c78348
Compare
|
Addressed the review findings at head
Local validation passed for all affected packages, focused race tests, the two-CN race integration test, affected-package |
3c78348 to
df08132
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review: no blocking finding
Reviewed head df08132946a1223257efc420e95cb04fbb9353a0 against live base / merge-base a73f14eee3e6e36bd987d11beee35b329de6d5cf (60 changed files). The review worktree is clean; no production or test changes were made in this review. No subagents were started.
Decision: no-blocker / approval recommendation for the reviewed code and available evidence. This is a follow-up self-review because the same assistant participated in the preceding fixes; it is submitted as COMMENT, not represented as an independent GitHub approval. It does not assert that pending CI has passed.
Previous comments
I checked the review bodies, issue comments, inline comments, and review threads, then verified the implementations rather than accepting the author's reply as proof. No inline review threads are present. The substantive concerns from the earlier XuPeng-SH, iamlinjunhong, and aunjgr reviews are addressed at this head:
| Concern | Disposition and evidence |
|---|---|
| Old owners silently ignore the new fairness option | Closed. First acquisition uses owner-atomic LockWriterFair capability admission (v99 after rebase). Only typed, pre-admission ErrNotSupported permits an Exclusive fallback. Transport failures preserve the existing indeterminate-outcome cleanup path. Direct initiating-CN acquisition precedes any old pipeline's verification SELECT. Remote fallback, transport-error, bind-change, and runtime-version tests cover the distinct outcomes. |
| The concurrency test did not prove the real View gate | Closed. TestIssue28079ConcurrentCreateAccountsShareLifecycleGate observes real SNAPSHOT and View Shared holders on two CNs, queues competing writers, verifies same-transaction re-entry, and verifies enforced pessimistic/RC ownership under optimistic/SI defaults. It does not infer admission merely from a frontend barrier. |
| Cleanup could hide errors or leave setup resources behind | Closed. Connections/transactions acquire immediate cleanup ownership; failure paths release barriers and join outstanding work; DROP errors surface; final account and lock/waiter checks verify teardown. Repeated integration race evidence is available. |
| Missing approved design | Closed. docs/design/account_lifecycle_shared_gate.md records invariants, competing owners, mixed-version prerequisites, validation, and the revision history. The revision-9 rebase corrections and revision-10 pre-read RC-refresh correction have recorded design review; implementation matches those decisions. |
Complete change map and adversarial checks
| Closure | Risk and challenge | Result |
|---|---|---|
| Owner admission, waiters, proxy generations, v99 RPC | R3: queued writer versus later reader; same-txn re-entry; ordinary non-fair Shared control; leading-writer cancellation; in-flight proxy re-entry; old owner, transport uncertainty, and bind changes | No confirmed violation. Existing holder re-entry precedes fairness; new fair proxy admissions reach the owner; eligible Shared notification stops at an Exclusive waiter. Ordinary Shared policy is not globally changed. |
| Direct frontend gates and RC refresh | R3: stale initial SNAPSHOT; View refresh after prior account writes; lower-layer retry/definition errors; old pipeline; missing catalog compatibility | No confirmed violation. LockRowsForSnapshotRefresh shares the existing implementation and accepts only a successful, non-definition-changing RC refresh before verification. Ordinary LockRows retains its replay contract; lower-layer failures propagate. The integration failure case verifies rollback of prior catalog writes and released locks. |
| All competing transaction owners | R3: DDL, CLONE/DATA BRANCH, SNAPSHOT/PITR, publication/GC, View recovery; explicit SI versus forced RC; temporary and prepared ALTER | No confirmed violation. Fixed-SI operations retain pessimistic/SI semantics; only the RC-required class forces/requires RC. Temporary ALTER is excluded through the session's temporary alias resolution. Newly run adjacent transaction/DDL regressions pass under race detection. |
| Planner shared state | R3: concurrent account initialization versus ordinary planner users | Query-local boolean literals remove mutable shared expression ownership without changing their boolean type/value contract. Removal of unused SessionsColTypes removes the concurrent global write. Owning-package race evidence was reused. |
| Test, protocol, and delivery artifacts | R2/R3: distinct oracles, fixture isolation, negative controls, generated consumer compatibility, hot-path measurement | The concurrency and refresh/failure cases prove different contracts and reuse the existing fixture. Negative controls fail at the intended initial/View refresh boundary. Protobuf regeneration and incremental static-check evidence are valid for this production revision. |
The Range-upgrade candidate was traced and discarded, not promoted to a speculative finding: CREATE's new-account catalog locks use the new account's lock group, whereas the lifecycle keys use system-account group 0; those catalog writes do not fill the lifecycle table/group ledger. The initial gate and its later re-entry also do not grow that ledger repeatedly. Existing restore writer ownership remains a stronger lifecycle fence. This conclusion does not claim a new general fairness policy for Range requests.
Unhappy-path closure
| Resource / wait | Q1: cleanup ownership | Q2: termination | Q3: retained growth |
|---|---|---|---|
| Direct gate process, vectors, and transaction | Process/packer/vector cleanup follows successful and failed lookup/admission paths; owning background transaction commits or rolls back | Admission uses the caller context and existing lock deadline; verification follows admission | Fixed lifecycle keys; no new retry loop or worker |
| Remote capability/fallback | Request, response, and RPC cancellation use existing owners; uncertain admission retains a transaction cleanup route | Fallback occurs only once after proven non-admission; transport ambiguity does not trigger a weaker retry | One capability attempt plus at most one compatibility fallback per owner attempt |
| Waiter / proxy generation | Holder release remains transaction-owned; waiter cancellation, notification, detach, reset, and generation re-entry were traced | Leading-writer cancellation advances eligible readers; queued writers retain ordering; existing timeout/cancel/service-close paths terminate waits | Existing outstanding-request / holder lifetime bounds; no new persistent cache or unbounded retry state |
Remote unlock's existing service-lifetime retry behavior is not mistaken for caller-context cancellation; this PR does not change that contract.
Validation evidence
Newly executed at exact head, with the repository CGo wrapper, -tags matrixone_test -race -count=1 -timeout=12m, package ./pkg/tests/issues:
TestIssue26113CloneCreatedTableInSameTransaction: PASS (14.43 s).TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock: PASS (2.99 s), including clone/diff/pick/merge subtests.TestIssue27055DatabaseCloneReadsExplicitTransactionSource: PASS (1.72 s), including uncommitted source changes and commit/rollback.TestIssue28934AddForeignKeyLockOrdering: PASS (2.62 s), including fixed-SI stale-snapshot rejection, opposing writers, timeout, rollback, and retry.- Combined terminal result: PASS, package 26.078 s, process exit 0. Log:
/tmp/mo29234-deep-adjacent-20260927.log. git diff --checkagainst the reviewed base: PASS.
Reused semantically valid preceding validation, rather than relabeling it as new execution:
- Full relevant package tests; owning-package race runs for frontend, lockservice, planner, and lockop.
- Two-CN lifecycle concurrency and refresh/failure integration tests under
-race -count=2; terminal PASS logs inspected. - Isolated cluster-restore regression under
-race -count=10: 10/10 PASS after the pre-read refresh fix. The earlier candidate failure was reproduced against a passing main control; it was not dismissed as flaky. - Initial-gate and View-only negative controls fail with the expected stale-input retry when the new admission policy is removed.
- Incremental vet/lint (0 reported new lint issues) and byte-identical generated protobuf verification.
Performance, engineering quality, and limits
The direction is reasonable: reuse the existing lock owner/queue and transaction policies, perform capability negotiation at the owner, and keep refresh handling inside the shared lock implementation. No new distributed membership oracle, background coordinator, or retry framework is introduced. The broader writer audit is necessary to make Shared readers safe, rather than unrelated feature expansion.
The retained-held-row Shared join A/B benchmark actually exercises addHolder: recorded main median 3386 ns/op versus candidate 3407 ns/op (about +0.6%), with 25 allocations/op on both. This is bounded evidence for that hot path, not proof of unchanged p99 under a long competing-writer queue or production CREATE throughput. The two-CN test proves overlap/order, not a throughput number. A loaded mixed CREATE/lifecycle-writer latency benchmark would be useful follow-up, not an unproven correctness blocker.
Two small, non-blocking improvements:
- Synchronize the design header (still revision 9 / validation pending) with its revision-10 decision log and completed local evidence.
- Add
Method_LockWriterFairto request/response debug-string dispatch so this new RPC has the same payload visibility as ordinary Lock.
Operational prerequisite remains important: while pre-v99 frontends serve lifecycle traffic, they must use pessimistic/RC defaults. Old optimistic frontends can omit the physical lock entirely; the new owner protocol cannot repair a request that was never sent. This is explicitly documented, not a claim of arbitrary mixed-default rolling-upgrade safety.
At the final live check, head and base still match the reviewed objects. Several CI checks (UT, SCA, coverage, and BVT) are still running; no terminal failing check was listed. This review does not wait for or waive those checks, dismiss another reviewer's request, or merge the PR.
XuPeng-SH
left a comment
There was a problem hiding this comment.
No blocking findings at df08132. The prior substantive review concerns are addressed; see my detailed review #5329927587 for the comment-by-comment disposition, adversarial checks, validation evidence, and performance limits. Required CI checks are still running; this approval does not waive them.
What type of PR is this?
Which issue(s) this PR fixes:
issue #28079
What this PR does / why we need it:
docs/design/account_lifecycle_shared_gate.md(revision 10).Validation on the rebased revision:
TestIssue26640ClusterRestoreRebindsSubscriptionPrivileges:-race -count=10, 10/10 passed after fixing the directly reproduced RC error.TestIssue28079ConcurrentCreateAccountsShareLifecycleGate:-race -count=2, 2/2 passed in one process.TestIssue28079LifecycleRefreshAndViewFailure: forces initial RC refresh with a real gate writer and View refresh with a one-shot committed-timestamp lock-result injection; checks current inherited generation and rollback after a View failure. It passed with the concurrency regression under-race -count=2. Two old-behavior negative controls reproduce RC retry at their respective gates.pkg/frontend,pkg/sql/colexec/lockop, andpkg/sql/compiletests; complete owning-package race suites for frontend, lockservice, sql/plan, and lockop; scopedgo vet; incrementalgolangci-lintover all changed Go packages (0 issues);git diff --checkpassed.lock.pb.gois byte-identical. Identical-source A/B held-row Shared-join benchmark medians: main 3386 ns/op, branch 3407 ns/op (25 allocs/op each); this bounded sample is not a loaded-system performance claim.CI for this new revision is pending.