Skip to content

fix(snapshot): order restore catalog locks - #28743

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-28742-restore-gate
Sep 11, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-28742-restore-gate

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

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_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.

@XuPeng-SH
XuPeng-SH requested a review from aptend as a code owner September 11, 2026 16:21
@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 →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@XuPeng-SH
XuPeng-SH merged commit b1c6b97 into matrixorigin:main Sep 11, 2026
18 of 21 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/fix-28742-restore-gate branch September 11, 2026 17:38
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.

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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants