Repository navigation
fix(snapshot): serialize cluster restore with lineage GC - #27826
Conversation
|
No unrelated CI blockers are currently tracked for exact head
|
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? |
69fddf0 to
c3e49eb
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head f4014f07414322a4294902035178bdf9d8f5e154 on base a3f1328612563cce6bc6cddaeddc8a3813bc6bb1.
[P1] The singleton lifecycle gate is owned for the lifetime of a user-controlled explicit transaction, making cluster-wide recovery and DDL availability user-controlled.
getBackExecutor joins the outer transaction when ByBegin is set (pkg/frontend/clone.go:583-589), and getDataBranchMutationExecutor writes the system-account singleton before any clone/drop work (pkg/frontend/data_branch.go:491-506). The updated quota test demonstrates the resulting lifetime: connection 1 executes BEGIN plus DATA BRANCH CREATE, connection 2 enters a lock wait, and it is released only by connection 1's later COMMIT (pkg/tests/issues/issue_26087_test.go:209-229). The same singleton now gates every non-temporary DROP TABLE, DROP DATABASE, snapshot/PITR mutation, and account/cluster restore. Therefore any tenant can hold an otherwise valid transaction open after a data-branch mutation (or ordinary DDL) and block restore and unrelated tenants for the outer transaction lifetime. GC's FastFail/one-second budget does not help foreground restore, which uses the normal blocking path. This replaces the original deadlock with an unbounded global convoy/cross-tenant availability problem. Please ensure the global boundary cannot be owned by an arbitrary user transaction or long clone/drop body (for example, use a scoped/versioned protocol or a bounded internal critical section), and add a deterministic cross-tenant holder-first/restore-second test plus contention/latency evidence.
[P1] The GC mutation is batched, but discovery is still unbounded and is amplified up to 16 times per invocation.
dataBranchLineageGCExecutor opens up to 16 independent transactions (pkg/sql/compile/alter_lineage_gc.go:51-83). Every one of them fully loads mo_branch_metadata, every branch snapshot edge, every kind='user' snapshot, and every active PITR before truncating the result to 128 deletes (pkg/sql/compile/alter_lineage_gc.go:117-148). With at least 2,048 eligible rows, one five-minute invocation therefore performs 16 complete catalog scans/materializations while deleting only 128 rows per scan. The former executor deadline has also been removed, so row count, bytes, allocations, I/O, and wall time are all unbounded; task concurrency 1 only prevents overlap, not task-worker monopolization or backlog growth. The five-row mock proves commit boundaries but provides no scale/performance proof. Please bound/page discovery or reuse a safely revalidated plan without rescanning the full catalog per batch, define a time/row/byte budget, and add scale/benchmark evidence for scan count, allocations, and runtime.
[P1] The claimed single owner-lifecycle writer inventory is incomplete: CCPR snapshot GC still bypasses the gate.
CCPR creates snapshots through ordinary CREATE SNAPSHOT (pkg/publication/iteration.go:793-830), so the row receives the default kind='user' and is included in lineage historical-source discovery. Its cleanup later executes a direct DELETE FROM mo_catalog.mo_snapshots in a separate transaction (pkg/publication/executor.go:1304-1336) without writing LineageOwnerLifecycleLockSQL. That mutation can commit while GC is validating or while account/cluster restore owns the gate and replaces mo_snapshots, so the singleton is not an exclusion/validation point for every catalog writer and the original restore-abort class remains reachable. Make the delete cross the same boundary in the same transaction (including commit-error handling), or establish a truly disjoint catalog kind/protocol with compatibility proof. Add deterministic CCPR-delete versus GC and account/cluster-restore coverage.
All current-head required CI is terminal and green. I reused it; these are uncovered lifecycle, scale, and reverse-writer counterexamples rather than failures of the existing test selection.
|
Addressed all three P1 findings on exact head
Valid and in scope, with one narrower reachable entry set. Ordinary DROP DATABASE/TABLE and administrative snapshot/PITR statements were already rejected in uncommitted user transactions; the four DATA BRANCH create/delete paths were the remaining bypass because their background executor joined
Valid and in scope. One scheduled invocation is now one fixed-SI transaction: one discovery, one fast-fail gate validation, and at most 128 paired deletes. The 16x rescan loop is removed. A one-minute local work budget bounds discovery/task-worker occupancy and rolls back/defer on expiry; parent cancellation still wins. The 2,049-candidate regression proves exactly one transaction/four discovery queries and a 128-row commit. A three-sample
Valid and in scope. CCPR cleanup now executes Validation passed: complete |
|
Fixed the current-head coverage failure on The failure was PR-caused: rejecting DATA BRANCH inside explicit Explicit DATA BRANCH mutations now keep their existing user transaction without owning the cluster-wide lifecycle row between statements. A successful mutation marks the transaction; terminal COMMIT performs a system-account fast-fail validation write on that same transaction immediately before commit. If a restore/snapshot writer crossed the boundary while the user transaction was open, validation fails and the complete user transaction rolls back on the transaction cleanup context, releasing its earlier catalog locks even if the request was canceled. Deterministic proof:
The complete PR description and the single CI-blocker marker are updated. The prior attempt-1 workflow was not rerun because this push created fresh current-head CI. |
|
Freshness follow-up: the unchanged twelve-patch series is now exact head The rebase was conflict-free and Post-rebase validation passed:
The earlier Ubuntu UT failure on old head |
|
Freshness follow-up: the unchanged twelve-patch series is now exact head The rebase was conflict-free and Post-rebase validation passed:
The complete PR description and unique blocker marker are updated; fresh current-head CI is authoritative. |
|
Freshness follow-up: the unchanged twelve-patch series is now exact head The rebase was conflict-free and Post-rebase validation passed:
The complete PR description and unique blocker marker are updated; fresh current-head CI is authoritative. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
P1: commit-time lifecycle validation is bypassed when an active explicit transaction is replaced by another BEGIN/START TRANSACTION. A successful DATA BRANCH mutation only sets lineageOwnerLifecycleValidation, but TxnHandler.Create -> createUnsafe commits the old transaction by calling commitUnsafe directly (txn.go:568); the validation hook exists only in Commit. Therefore BEGIN; CREATE DATA BRANCH ...; BEGIN; can publish the owner-catalog mutation without writing the shared lifecycle gate. A lineage-GC transaction may concurrently validate its stale discovery by taking the gate, so the serialization invariant this PR relies on is not complete.
Please centralize terminal commit validation so every reachable commit path (including implicit commits such as createUnsafe and SetAutocommit) either crosses the gate in the same transaction or rolls back on fast-fail, and add regression tests for those terminal paths. The ordinary COMMIT path and current GC batching/CCPR changes otherwise look substantially improved.
|
Addressed the valid P1 on exact head
The bypass was real and in scope. Deterministic proof:
The complete PR description and unique CI-blocker marker are updated. Fresh current-head CI is starting. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Approved on exact head d6925af23ab02f640ebb815d6a20b2441fb7f052 after re-reviewing the terminal-commit fix.
The prior lifecycle-gate bypass is now closed structurally: validation lives in the single commitUnsafe terminal point, so explicit COMMIT, replacement BEGIN, and enabling autocommit all validate in the same owning transaction immediately before physical commit. A validation failure rolls the transaction back while the handler lock is still held, so it cannot leave the owner mutation or catalog locks alive. The new table-driven unit test covers all three direct commit callers, and the two-CN test covers explicit COMMIT plus replacement BEGIN against a completed competing owner writer.
I re-enumerated every commitUnsafe caller and found no remaining terminal path outside this validation point. The focused exact-head frontend test passed locally. This approval does not wait for the still-running broad CI.
Merge Queue Status
This pull request spent 18 seconds in the queue, including 1 second running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #27824
What this PR does / why we need it:
Root cause
The failing PROXY BVT exposed inconsistent lock order around data-branch owner catalogs. Restore could hold snapshot/catalog locks and later replace
mo_feature_registry, while snapshot/PITR publication, lineage GC, account deletion, data-branch mutation, and CCPR cleanup entered through different orders. Restore could therefore be selected as a deadlock victim; the later account mismatch and reconnect failures were consequences of that aborted restore transaction.Review also exposed liveness boundaries: background GC could hold the global owner boundary through unbounded work and repeat full discovery up to 16 times; local contention could mask parent cancellation; a DATA BRANCH statement inside explicit
BEGINcould retain the singleton boundary until a user-controlled later commit; CCPR snapshot cleanup bypassed the boundary entirely; and commit-time validation initially covered only ordinary COMMIT, allowing repeated BEGIN or SET autocommit=1 to commit the marked transaction without crossing the boundary.Changes
SNAPSHOTrow inmo_feature_registryas the single owner-lifecycle boundary; remove the independentmo_tablesgate.lifecycle gate -> escaped snapshot delete -> commitin one transaction. Gate/delete failure rolls back; commit failure is returned without a blind post-commit rollback, preserving unknown-commit handling.Issue-to-test proof
snapshot/cluster/restore_dropped_account_with_cluster.sqlis the reported reproduction: it restores dropped/replaced accounts, verifies the account set, authenticates restored accounts, and validates table data. It passed twice through a real two-CN PROXY (204/204each); subsequent required PROXY CI also passed.TestLineageOwnerLifecycleLockSerializesEmptyProbeproves competing owner decisions cannot bypass the stable row.TestLockRestoreLineageOwnerLifecycleCoversWholeCatalogRestore,Test_doDropAccount_InTransaction, andTestOwnerCatalogDropEntryPointsStopAtLifecycleAdmissionFailurecover restore levels, standalone/reentrant account deletion, ordinary DROP entry points, and gate-failure rollback/order.TestGetDataBranchMutationExecutorAdmitsBeforeMutation,...RollsBackOnAdmissionFailure, andTestValidateDataBranchLineageOwnerLifecycleAtCommitFastFailsStableWriteprove common admission order, cleanup, same-transaction validation, system-account execution, disabled statement retry, and fast-fail policy.TestLineageOwnerLifecycleValidationCoversEveryTerminalCommitPathproves ordinary COMMIT, replacement BEGIN, and autocommit off-to-on all validate before physical commit and fully roll back on failure.\n-TestIssue26113CloneCreatedTableInSameTransactionpreserves DATA BRANCH's existing explicit-transaction atomicity and is the exact coverage-mode regression that caught the rejected-statement design.TestIssue26087ConcurrentDataBranchQuotauses two CNs to prove an open tenant transaction does not own the global lifecycle row, a completed system snapshot forces both tenant COMMIT and replacement BEGIN validation to fail and fully release its catalog locks, concurrent autocommit table/database branch mutations preserve exact quota outcomes, fixed SI is not advanced, and implicit transaction mode keeps its independent mutation transaction. The upstream test: synchronize data branch quota probe #27848 logtail-frontier synchronization remains composed in the same test.BenchmarkComputeAlterLineageCompactionPlan2049records the remaining single-discovery planner cost and allocation envelope under-benchmem.TestCompactExpiredAlterDataBranchLineageWithExecutorproves discovery precedes lifecycle admission and only the bounded delete pair follows it.TestDataBranchLineageGCExecutorMakesDurableProgressAcrossRunsproves one independent committed batch per run and eventual cleanup across runs.TestDataBranchLineageGCExecutorScansOnceAndBoundsMutationAtScaleuses 2,049 eligible generations to prove one discovery transaction and a 128-row commit cap instead of 16 complete rescans.TestDataBranchLineageGCExecutorDefersOnLocalTimeBudget,...DefersAfterContentionRollback,...ParentContextPrecedesContention, and...DoesNotSuppressOtherErrorsclose timeout, contention, parent-control, rollback, and substantive-error paths.TestDeleteSnapshotWithLifecycleGateIsAtomicAndOrderedproves CCPR gate/delete/commit order, SQL quoting, rollback on both pre-commit failures, and commit-error propagation.Validation
Latest review update, exact head
d6925af23a:TestLineageOwnerLifecycleValidationCoversEveryTerminalCommitPath: passed\n- focused lifecycle terminal-path race stress at-count=100: passed\n- coverage-mode exact two-CNTestIssue26087ConcurrentDataBranchQuota, including replacement BEGIN: passed\n- completepkg/frontend: passed\n- completepkg/frontend -race: passedgolangci-lint 2.6.2 --enable-only prealloc ./pkg/frontend ./pkg/tests/issues: 0 issuesgit diff --checkTestIssue26087ConcurrentDataBranchQuotaandTestIssue26113CloneCreatedTableInSameTransaction: passed togetherpkg/sql/compile: passedEarlier series evidence retained:
pkg/frontend,pkg/sql/compile,pkg/publication,pkg/util/executor, andpkg/frontend/...suites; CGo-configured vet204/204both runs)Freshness:
origin/main/ PR base:7a87bd69891d498ca72c7eb3a92458da2992f6a1(perf(load): avoid per-batch locks for covered unique indexes #27814)d6925af23ab02f640ebb815d6a20b2441fb7f052pkg/sql/compile/compile.goand adds LOAD unique-index lock promotion before source initialization plus retry-owned proof cleanup. The composed diff keeps that state machine unchanged; this PR's nil-plan internal-SQL guard remains isolated inrunSqlWithResultAndOptionsand still preserves DROP DATABASE foreign-key options for non-nil plans. Focused tests for both lock/lifecycle protocols, the complete compile package, and this PR's two exact embedded-cluster regressions passed after rebase.Residual risks
The shared write boundary serializes rare owner-lifecycle mutations globally. Autocommit owners hold it only for their mutation transaction; an explicit DATA BRANCH transaction holds no global row while idle and must win fast-fail validation immediately before COMMIT or roll back. Existing ordinary DDL and administrative statements remain prohibited in explicit transactions. GC still performs one complete read-only catalog discovery, but never holds the foreground boundary during that scan; each invocation has a one-minute work budget and can commit no more than 128 paired rows. Remaining eligible lineage advances on later scheduled runs.