Repository navigation
fix(snapshot): order restore catalog locks - #28743
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.
Reviewed exact head 442e3de against main 6602ca0, including all four changed files, issue #28742, callers and lifecycle consumers. COMMENT only for this self-authored PR.
Conclusion: no concrete blocker identified. This is a focused lock-order correction, not a new lifecycle subsystem requiring a separate major-design gate.
The new admission takes exclusive ownership of the system feature-registry catalog identity before the existing lineage write/SNAPSHOT/View gates. A heartbeat that already owns shared feature-registry metadata can finish before restore obtains the exclusive identity; once restore owns it, a new heartbeat waits there instead of retaining shared metadata while waiting on restore's SNAPSHOT row. Thus the reported cycle is broken at the outermost conflicting resource, without removing the existing lifecycle or MVCC write barrier. Both snapshot and PITR restore call this shared helper inside their existing transaction before the View gates. Account/cluster restore take the new gate; database/table restore retain the prior path. System account scoping is explicit and a missing identity or query failure aborts before lineage mutation. Commit/rollback and background-executor cleanup still own release; the context-aware fault hook does not create a production retry loop or detached worker.
The regression reuses the existing isolated two-CN restore/privilege fixture rather than adding another cluster. It checks a real feature-registry metadata waiter while restore is held before lifecycle admission, cancellation of both transactions, fresh-transaction reacquisition, unchanged dropped-account state after cancellation, then successful restore, durable revalidation state and the original subscription privilege oracles. Completion channels are buffered, waits bounded, fault removal/cancellation and worker joins unwind before cluster teardown. The waiter test observes real lock state rather than relying on a sleep to claim ordering. The new gate adds one indexed catalog-row acquisition and serializes conflicting metadata readers for whole-catalog restore; that is the necessary conflict domain, with no normal query hot-path change or new wire/catalog format.
Validation/limits: source-level ownership/wait-for/rollback and test-oracle review; reused the author's reported targeted normal/race restore regression, catalog/frontend/CN admission tests and restore-admission race validation. No independent native-suite or deployment execution, no CI waiting. Existing dirty worktree left untouched; live head/base rechecked unchanged before posting.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#28742 ## What this PR does / why we need it: A cluster restore can hold the SNAPSHOT lifecycle row while a CN view-metadata fence has already acquired shared metadata for `mo_feature_registry`. The restore later needs exclusive metadata ownership to replace that catalog relation, creating a lock-order cycle. This change makes cluster and account restore acquire the stable `mo_catalog.mo_tables` identity for `mo_feature_registry` with `FOR UPDATE` before the existing lineage, SNAPSHOT, and View lifecycle gates. A missing identity fails closed. Existing restore transaction lifetime, lineage barrier, SNAPSHOT/View protection, and rollback behavior remain in place. The regression runs the real CN view-metadata fence transaction while restore is paused after metadata ownership, observes the metadata waiter, verifies durable revalidation state, cancels both operations and proves a fresh transaction can reacquire both lifecycle locks, then reruns the successful restore and subscription privilege checks. Validation: - Targeted restore regression passed normally and with race detection. - Catalog and frontend tests passed. - CN view-metadata admission tests passed. - Restore admission test passed with race detection. - `git diff --check` passed.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#28742 ## What this PR does / why we need it: A cluster restore can hold the SNAPSHOT lifecycle row while a CN view-metadata fence has already acquired shared metadata for `mo_feature_registry`. The restore later needs exclusive metadata ownership to replace that catalog relation, creating a lock-order cycle. This change makes cluster and account restore acquire the stable `mo_catalog.mo_tables` identity for `mo_feature_registry` with `FOR UPDATE` before the existing lineage, SNAPSHOT, and View lifecycle gates. A missing identity fails closed. Existing restore transaction lifetime, lineage barrier, SNAPSHOT/View protection, and rollback behavior remain in place. The regression runs the real CN view-metadata fence transaction while restore is paused after metadata ownership, observes the metadata waiter, verifies durable revalidation state, cancels both operations and proves a fresh transaction can reacquire both lifecycle locks, then reruns the successful restore and subscription privilege checks. Validation: - Targeted restore regression passed normally and with race detection. - Catalog and frontend tests passed. - CN view-metadata admission tests passed. - Restore admission test passed with race detection. - `git diff --check` passed.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#28742 ## What this PR does / why we need it: A cluster restore can hold the SNAPSHOT lifecycle row while a CN view-metadata fence has already acquired shared metadata for `mo_feature_registry`. The restore later needs exclusive metadata ownership to replace that catalog relation, creating a lock-order cycle. This change makes cluster and account restore acquire the stable `mo_catalog.mo_tables` identity for `mo_feature_registry` with `FOR UPDATE` before the existing lineage, SNAPSHOT, and View lifecycle gates. A missing identity fails closed. Existing restore transaction lifetime, lineage barrier, SNAPSHOT/View protection, and rollback behavior remain in place. The regression runs the real CN view-metadata fence transaction while restore is paused after metadata ownership, observes the metadata waiter, verifies durable revalidation state, cancels both operations and proves a fresh transaction can reacquire both lifecycle locks, then reruns the successful restore and subscription privilege checks. Validation: - Targeted restore regression passed normally and with race detection. - Catalog and frontend tests passed. - CN view-metadata admission tests passed. - Restore admission test passed with race detection. - `git diff --check` passed.
What type of PR is this?
Which issue(s) this PR fixes:
issue #28742
What this PR does / why we need it:
A cluster restore can hold the SNAPSHOT lifecycle row while a CN view-metadata fence has already acquired shared metadata for
mo_feature_registry. The restore later needs exclusive metadata ownership to replace that catalog relation, creating a lock-order cycle.This change makes cluster and account restore acquire the stable
mo_catalog.mo_tablesidentity formo_feature_registrywithFOR UPDATEbefore the existing lineage, SNAPSHOT, and View lifecycle gates. A missing identity fails closed. Existing restore transaction lifetime, lineage barrier, SNAPSHOT/View protection, and rollback behavior remain in place.The regression runs the real CN view-metadata fence transaction while restore is paused after metadata ownership, observes the metadata waiter, verifies durable revalidation state, cancels both operations and proves a fresh transaction can reacquire both lifecycle locks, then reruns the successful restore and subscription privilege checks.
Validation:
git diff --checkpassed.