Repository navigation
fix: enforce named snapshot object scope - #27134
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 d43a6e6. Named-snapshot object identity is enforced before execution across ordinary relation planning, SHOW, CLONE, RESTORE TABLE, and both DATA BRANCH endpoints; internal catalog/privilege probes retain timestamp travel without masquerading as the user-selected scoped snapshot. Logical table identity across copy-table ALTER and restore failure atomicity are covered. Full pkg/sql/plan tests, focused frontend tests, the dependent issue regression, vet, and diff checks passed locally.
Merge Queue Status
This pull request spent 1 hour 56 minutes 17 seconds in the queue, including 42 minutes 14 seconds running CI. Required conditions to merge
|
aptend
left a comment
There was a problem hiding this comment.
Deep review completed on exact head d43a6e6. Named table/database scope is now enforced at the authoritative relation/database identities for ordinary scans, SHOW CREATE/TABLES/DATABASES, CLONE, RESTORE TABLE, and both DATA BRANCH endpoints. The logical-table-ID fallback correctly preserves table-snapshot identity across copy-table ALTER, while internal catalog/privilege probes intentionally switch to the already-resolved MO_TS so they do not impersonate a user-selected object-scoped snapshot. I also traced inherited view snapshots and sibling table binding: only the explicitly named relation is scope-validated, its dependency snapshot remains usable, and the bind-context snapshot is restored before sibling relations.
The restore mismatch is rejected before FK discovery or destructive restore work, database-level SHOW metadata is narrowed by historical dat_id, and table-level database-wide SHOW operations fail closed. Focused frontend and planner scope regressions passed 10/10 with the required local CGo setup, all exact-head CI checks are terminal and green/skipped, and git diff --check is clean. LGTM.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27116
What this PR does / why we need it:
Root cause
Named snapshots retain their declared level and object ID in
Snapshot.ExtraInfo, but relation planning and selected SHOW paths applied only their timestamp. A table snapshot could therefore read a different table, including through SHOW CREATE.RESTORE TABLEalso omitted the target-database check when its snapshot was database-level.The initial scope enforcement also exposed two internal metadata readers that must retain historical time travel without presenting themselves as a user-selected named snapshot: DATA BRANCH's synthetic privilege query and SHOW RECOVERY WINDOW's
mo_catalog.mo_tablesscan. Finally, a copy-table ALTER replaces a physical relation while retaining its logical table ID, which is the identity captured by a table snapshot.Changes
MO_TS; validate the actual user-selected relation separately.SHOW DATABASESboundaries.Issue-to-test proof
test/distributed/cases/snapshot/snapshot_scope.sqlcovers [Bug]: Snapshot scope is ignored for cross-table reads and database-snapshot table restore #27116's cross-table SELECT and cross-database RESTORE repros, same-object controls, restore failure atomicity, table/database SHOW boundaries, copy-table ALTER logical identity, and DATA BRANCH rejection with the named snapshot on either endpoint.pkg/sql/plan/query_builder_test.go:TestBuildTableRejectsOutOfScopeSnapshotproves an unrelated relation is rejected during named-snapshot planning.pkg/sql/plan/snapshot_scope_test.gocovers named-snapshot scope levels, logical-ID selection, table snapshots rejected bySHOW DATABASES, and database-snapshot catalog plans constrained bydat_id.pkg/frontend/data_branch_helpers_test.go:TestValidateDataBranchNamedSnapshotScopeproves DATA BRANCH validates the resolved endpoint's logical table identity.pkg/frontend/snapshot_test.go:TestCheckRestorePrivEnforcesDatabaseSnapshotScopeproves the database-snapshot restore target check permits its source database and rejects another database.pkg/frontend/show_recovery_window_test.go:TestSearchTablesReadsCatalogAtSnapshotTimestampproves the internal recovery-window catalog scan usesMO_TS.Tests run
make build— PASS.make err-check— PASS.mo-cgo-test -count=1 -timeout=180s ./pkg/sql/plan— PASS.mo-cgo-test -count=1 -timeout=120s -run '^TestBuildShowDatabases(RejectsTableSnapshot|RestrictsDatabaseSnapshot)$' ./pkg/sql/plan— PASS.mo-cgo-test -list '^TestBuildShowDatabases(RejectsTableSnapshot|RestrictsDatabaseSnapshot)$' ./pkg/sql/plan— both tests enumerated.snapshot_scope— 54/54;diff_schema_evolve— 278/278;show_recovery_window— 109/109.CI follow-up
The prior Proxy BVT failure was PR-caused and fixed in the earlier integration commits; the later Proxy and pessimistic BVT jobs passed. The earlier arm64 SCA failure is green after compliant error construction.
The earlier Coverage failure was PR-caused, not the external download outage: workflow
31755103070attempt 2 completed its coverage-UT producer successfully, then its final Coverage job reported 61/83 changed statements (73.49%), below the 75% threshold. This commit added direct semantic tests for the previously uncovered table-snapshot rejection and database-dat_idfiltering branches. The follow-up workflow31762472675passed its Coverage job and all required enabled checks.Residual risks
No catalog migration, fallback path, concurrency behavior, or resource ownership change is introduced. Database snapshots now expose only their declared database through
SHOW DATABASES; table snapshots reject database-wide SHOW operations by design.