Skip to content

fix: rebind role privilege object IDs during restore - #26700

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
aptend:fix/26640-restore-role-privs
Aug 5, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
aptend:fix/26640-restore-role-privs

Conversation

@aptend

@aptend aptend commented Aug 4, 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:

Fixes #26640

What this PR does / why we need it:

Snapshot and PITR restore copy system-catalog rows before all target objects have been recreated. Identity-bearing rows therefore cannot blindly retain source physical IDs. In particular, restored mo_role_privs.obj_id values could point to source objects instead of the target database or relation, leaving valid privileges unusable after restore.

This PR:

  • introduces explicit restore policies and ordered post-restore handlers for identity-bearing system catalogs;
  • rebuilds database privilege object IDs with target physical database IDs;
  • rebuilds table and view privilege object IDs with target relation logical IDs;
  • keeps snapshot reads scoped to the source account while resolving and writing identities in the target account;
  • preserves cluster restore ordering for publications and subscription databases;
  • adds snapshot, PITR, cross-account, cluster-subscription, validation, and failure-path regression coverage.

Validation:

  • .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/frontend -count=1
  • .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/tests/issues -run "^TestIssue26640" -count=1
  • focused race tests with -count=100
  • full pkg/frontend race suite
  • go vet ./pkg/frontend ./pkg/tests/issues
  • git diff --check
  • changed-code CI coverage: 117/139 (84.17%)

@aptend
aptend requested a review from XuPeng-SH as a code owner August 4, 2026 09:02
@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 →

@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Aug 4, 2026

@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 21342a3.\n\nThe previous cluster-restore blocker is closed: publication owners are resolved by stable account name, creator users and owner roles are rebound from snapshot IDs through stable names to current tenant-local IDs, and the database ID is resolved inside the restored publisher. Missing identities now fail explicitly instead of dereferencing a historical account ID. The regression recreates both publisher and subscriber and verifies the restored publication account/database IDs.\n\nThe original privilege fix also preserves the distinct ID contracts: database-scoped grants map to target database IDs, direct table/view grants map to relation logical IDs, wildcard zero remains a sentinel, and grants for deliberately omitted objects are removed rather than retaining a collision-prone source ID. Post-object handlers run after FK/view and publication/subscription phases for account snapshot, account PITR, and cluster restore.\n\nValidated the full pkg/frontend test suite, all three TestIssue26640 embedded-cluster regressions, go vet for frontend and issues, and git diff --check. CI is green.

@mergify

mergify Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@mergify mergify Bot added kind/bug Something isn't working queued labels Aug 5, 2026
@mergify

mergify Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-05 02:21 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-05 03:04 UTC · at 5733aa365b0867130ae33fd9238687907f07c3ad · squash

This pull request spent 43 minutes 10 seconds in the queue, including 42 minutes 47 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 Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • 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

@mergify
mergify Bot merged commit ace13bf into matrixorigin:main Aug 5, 2026
26 of 27 checks passed
@mergify mergify Bot removed the queued label Aug 5, 2026
@LeftHandCold LeftHandCold mentioned this pull request Aug 5, 2026
1 of 7 tasks
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

Snapshot and PITR restore copy system-catalog rows before all target objects have been recreated. Identity-bearing rows therefore cannot blindly retain source physical IDs. In particular, restored `mo_role_privs.obj_id` values could point to source objects instead of the target database or relation, leaving valid privileges unusable after restore.

This PR:

- introduces explicit restore policies and ordered post-restore handlers for identity-bearing system catalogs;
- rebuilds database privilege object IDs with target physical database IDs;
- rebuilds table and view privilege object IDs with target relation logical IDs;
- keeps snapshot reads scoped to the source account while resolving and writing identities in the target account;
- preserves cluster restore ordering for publications and subscription databases;
- adds snapshot, PITR, cross-account, cluster-subscription, validation, and failure-path regression coverage.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/frontend -count=1`
- `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/tests/issues -run "^TestIssue26640" -count=1`
- focused race tests with `-count=100`
- full `pkg/frontend` race suite
- `go vet ./pkg/frontend ./pkg/tests/issues`
- `git diff --check`
- changed-code CI coverage: `117/139 (84.17%)`

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

Snapshot and PITR restore copy system-catalog rows before all target objects have been recreated. Identity-bearing rows therefore cannot blindly retain source physical IDs. In particular, restored `mo_role_privs.obj_id` values could point to source objects instead of the target database or relation, leaving valid privileges unusable after restore.

This PR:

- introduces explicit restore policies and ordered post-restore handlers for identity-bearing system catalogs;
- rebuilds database privilege object IDs with target physical database IDs;
- rebuilds table and view privilege object IDs with target relation logical IDs;
- keeps snapshot reads scoped to the source account while resolving and writing identities in the target account;
- preserves cluster restore ordering for publications and subscription databases;
- adds snapshot, PITR, cross-account, cluster-subscription, validation, and failure-path regression coverage.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/frontend -count=1`
- `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/tests/issues -run "^TestIssue26640" -count=1`
- focused race tests with `-count=100`
- full `pkg/frontend` race suite
- `go vet ./pkg/frontend ./pkg/tests/issues`
- `git diff --check`
- changed-code CI coverage: `117/139 (84.17%)`

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

Snapshot and PITR restore copy system-catalog rows before all target objects have been recreated. Identity-bearing rows therefore cannot blindly retain source physical IDs. In particular, restored `mo_role_privs.obj_id` values could point to source objects instead of the target database or relation, leaving valid privileges unusable after restore.

This PR:

- introduces explicit restore policies and ordered post-restore handlers for identity-bearing system catalogs;
- rebuilds database privilege object IDs with target physical database IDs;
- rebuilds table and view privilege object IDs with target relation logical IDs;
- keeps snapshot reads scoped to the source account while resolving and writing identities in the target account;
- preserves cluster restore ordering for publications and subscription databases;
- adds snapshot, PITR, cross-account, cluster-subscription, validation, and failure-path regression coverage.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/frontend -count=1`
- `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/tests/issues -run "^TestIssue26640" -count=1`
- focused race tests with `-count=100`
- full `pkg/frontend` race suite
- `go vet ./pkg/frontend ./pkg/tests/issues`
- `git diff --check`
- changed-code CI coverage: `117/139 (84.17%)`

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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cross-account account snapshot restore leaves table grants bound to source object IDs

3 participants