Skip to content

fix(snapshot): rebuild role privileges after restore - #28218

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-28206-4afe7b3b
Sep 5, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-28206-4afe7b3b

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Sep 5, 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:

Related to #28206

What this PR does / why we need it:

Root cause

Account restore treated mo_role_privs as both a generic copy target and an owner-rebuilt catalog. The generic phase dropped, recreated, and copied the table; the post-object handler then deleted its rows and rebuilt privileges with restored object IDs. In one transaction, DistTAE could consequently find both the old system-catalog row and the newly inserted row for mo_catalog.mo_role_privs, violating deleteTable's unique catalog-row invariant and panicking.

Changes

  • Define owner-rebuilt system catalogs as a distinct restore policy which skips generic bulk restore.
  • Apply that policy to mo_role_privs; its existing post-object handler remains the sole owner of privilege restoration and ID remapping.
  • Centralize the bulk-skip predicate and validate that every rebuild policy has exactly one registered handler.
  • Extend the cluster snapshot BVT to prove both removal of post-snapshot privileges and preservation of snapshot privileges.

Issue-to-test proof

  • TestSystemCatalogRebuildPoliciesHaveHandlers proves owner-rebuilt catalogs cannot re-enter either generic catalog-restore discovery path and that each has exactly one handler.
  • TestValidateSystemCatalogRestoreHandlersRejectsIncompleteRegistry proves incomplete and duplicate ownership declarations fail closed.
  • cluster_level_snapshot_restore_to_sys_account.sql exercises the reported cluster snapshot sequence, verifies db01 is removed, verifies the snapshot role privilege is restored, and verifies the post-snapshot role privilege is removed.

Tests

  • make build
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/frontend
  • Target BVT on the rebased commit through Proxy: 393/393 statements passed.
  • The same target BVT also passed twice consecutively before the final rebase; teardown queries confirmed zero residual test roles, privileges, snapshots, and db01 rows.
  • Exact-head CI: Ubuntu/x86 UT, Linux/arm64 SCA, UT coverage, multi-CN Compose/Proxy BVT, and multi-CN Compose/Pessimistic BVT passed.

Residual risks

The restore transaction and DistTAE uniqueness invariant are unchanged. The policy change removes one redundant catalog recreation and does not alter privilege remapping or transaction boundaries. Exact-head multi-CN CI closes the topology-specific validation gap from the local environment.

@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

Choose a reason for hiding this comment

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

Deep-reviewed at 2491a66.

The failure path is closed at the correct ownership boundary: mo_role_privs is now excluded from generic drop/recreate/copy and remains solely rebuilt by the ordered post-object handler. All account-level snapshot, timestamp, PITR, and cluster restore paths use the same skip policy, while the handler still runs only after referenced databases, relations, views, publications, and subscriptions have their final target identities.

The previous ID-remapping semantics are preserved. Wildcards retain zero, database and relation identities are rebound, omitted objects lose their grants, and handler registry mismatches fail closed. The public regression proves both directions: snapshot privileges survive and post-snapshot privileges disappear. Exact-head UT, SCA, and multi-CN BVT evidence is green. I found no correctness, compatibility, performance, or unhappy-path blocker.

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

mergify Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-05 09:00 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-05 09:01 UTC · at 72734534dd11f18401fd0072c63168064fef812f · squash

This pull request spent 16 seconds in the queue, including 2 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 7273453 into matrixorigin:main Sep 5, 2026
53 of 54 checks passed
@mergify mergify Bot removed the queued label Sep 5, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

### Root cause

Account restore treated `mo_role_privs` as both a generic copy target and an owner-rebuilt catalog. The generic phase dropped, recreated, and copied the table; the post-object handler then deleted its rows and rebuilt privileges with restored object IDs. In one transaction, DistTAE could consequently find both the old system-catalog row and the newly inserted row for `mo_catalog.mo_role_privs`, violating `deleteTable`'s unique catalog-row invariant and panicking.

### Changes

- Define owner-rebuilt system catalogs as a distinct restore policy which skips generic bulk restore.
- Apply that policy to `mo_role_privs`; its existing post-object handler remains the sole owner of privilege restoration and ID remapping.
- Centralize the bulk-skip predicate and validate that every rebuild policy has exactly one registered handler.
- Extend the cluster snapshot BVT to prove both removal of post-snapshot privileges and preservation of snapshot privileges.

### Issue-to-test proof

- `TestSystemCatalogRebuildPoliciesHaveHandlers` proves owner-rebuilt catalogs cannot re-enter either generic catalog-restore discovery path and that each has exactly one handler.
- `TestValidateSystemCatalogRestoreHandlersRejectsIncompleteRegistry` proves incomplete and duplicate ownership declarations fail closed.
- `cluster_level_snapshot_restore_to_sys_account.sql` exercises the reported cluster snapshot sequence, verifies `db01` is removed, verifies the snapshot role privilege is restored, and verifies the post-snapshot role privilege is removed.

### Tests

- `make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/frontend`
- Target BVT on the rebased commit through Proxy: 393/393 statements passed.
- The same target BVT also passed twice consecutively before the final rebase; teardown queries confirmed zero residual test roles, privileges, snapshots, and `db01` rows.
- Exact-head CI: Ubuntu/x86 UT, Linux/arm64 SCA, UT coverage, multi-CN Compose/Proxy BVT, and multi-CN Compose/Pessimistic BVT passed.

### Residual risks

The restore transaction and DistTAE uniqueness invariant are unchanged. The policy change removes one redundant catalog recreation and does not alter privilege remapping or transaction boundaries. Exact-head multi-CN CI closes the topology-specific validation gap from the local environment.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

### Root cause

Account restore treated `mo_role_privs` as both a generic copy target and an owner-rebuilt catalog. The generic phase dropped, recreated, and copied the table; the post-object handler then deleted its rows and rebuilt privileges with restored object IDs. In one transaction, DistTAE could consequently find both the old system-catalog row and the newly inserted row for `mo_catalog.mo_role_privs`, violating `deleteTable`'s unique catalog-row invariant and panicking.

### Changes

- Define owner-rebuilt system catalogs as a distinct restore policy which skips generic bulk restore.
- Apply that policy to `mo_role_privs`; its existing post-object handler remains the sole owner of privilege restoration and ID remapping.
- Centralize the bulk-skip predicate and validate that every rebuild policy has exactly one registered handler.
- Extend the cluster snapshot BVT to prove both removal of post-snapshot privileges and preservation of snapshot privileges.

### Issue-to-test proof

- `TestSystemCatalogRebuildPoliciesHaveHandlers` proves owner-rebuilt catalogs cannot re-enter either generic catalog-restore discovery path and that each has exactly one handler.
- `TestValidateSystemCatalogRestoreHandlersRejectsIncompleteRegistry` proves incomplete and duplicate ownership declarations fail closed.
- `cluster_level_snapshot_restore_to_sys_account.sql` exercises the reported cluster snapshot sequence, verifies `db01` is removed, verifies the snapshot role privilege is restored, and verifies the post-snapshot role privilege is removed.

### Tests

- `make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/frontend`
- Target BVT on the rebased commit through Proxy: 393/393 statements passed.
- The same target BVT also passed twice consecutively before the final rebase; teardown queries confirmed zero residual test roles, privileges, snapshots, and `db01` rows.
- Exact-head CI: Ubuntu/x86 UT, Linux/arm64 SCA, UT coverage, multi-CN Compose/Proxy BVT, and multi-CN Compose/Pessimistic BVT passed.

### Residual risks

The restore transaction and DistTAE uniqueness invariant are unchanged. The policy change removes one redundant catalog recreation and does not alter privilege remapping or transaction boundaries. Exact-head multi-CN CI closes the topology-specific validation gap from the local environment.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

### Root cause

Account restore treated `mo_role_privs` as both a generic copy target and an owner-rebuilt catalog. The generic phase dropped, recreated, and copied the table; the post-object handler then deleted its rows and rebuilt privileges with restored object IDs. In one transaction, DistTAE could consequently find both the old system-catalog row and the newly inserted row for `mo_catalog.mo_role_privs`, violating `deleteTable`'s unique catalog-row invariant and panicking.

### Changes

- Define owner-rebuilt system catalogs as a distinct restore policy which skips generic bulk restore.
- Apply that policy to `mo_role_privs`; its existing post-object handler remains the sole owner of privilege restoration and ID remapping.
- Centralize the bulk-skip predicate and validate that every rebuild policy has exactly one registered handler.
- Extend the cluster snapshot BVT to prove both removal of post-snapshot privileges and preservation of snapshot privileges.

### Issue-to-test proof

- `TestSystemCatalogRebuildPoliciesHaveHandlers` proves owner-rebuilt catalogs cannot re-enter either generic catalog-restore discovery path and that each has exactly one handler.
- `TestValidateSystemCatalogRestoreHandlersRejectsIncompleteRegistry` proves incomplete and duplicate ownership declarations fail closed.
- `cluster_level_snapshot_restore_to_sys_account.sql` exercises the reported cluster snapshot sequence, verifies `db01` is removed, verifies the snapshot role privilege is restored, and verifies the post-snapshot role privilege is removed.

### Tests

- `make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/frontend`
- Target BVT on the rebased commit through Proxy: 393/393 statements passed.
- The same target BVT also passed twice consecutively before the final rebase; teardown queries confirmed zero residual test roles, privileges, snapshots, and `db01` rows.
- Exact-head CI: Ubuntu/x86 UT, Linux/arm64 SCA, UT coverage, multi-CN Compose/Proxy BVT, and multi-CN Compose/Pessimistic BVT passed.

### Residual risks

The restore transaction and DistTAE uniqueness invariant are unchanged. The policy change removes one redundant catalog recreation and does not alter privilege remapping or transaction boundaries. Exact-head multi-CN CI closes the topology-specific validation gap from the local environment.

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 size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants