Repository navigation
fix(frontend): resolve subscription tables for DATA BRANCH and snapshots - #31039
Conversation
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to matrixorigin#30949 ## What this PR does / why we need it: A subscription database `N` in a subscriber account `S` is an alias over a publisher's physical database `D`. Ordinary reads attach the physical-owner identity and rebind `N -> D` before table resolution, but two owner paths bypassed that routing, so a subscription table that `SELECT`, `SHOW TABLES`, and `information_schema` all resolve was reported as missing: - `CREATE SNAPSHOT ... FOR TABLE N.t` probed `mo_catalog.mo_tables` with `reldatabase = N AND account_id = S`; physical rows live under `(D, physical owner)`, so the statement failed with `ERROR 20101: table N.t does not exist`. - `DATA BRANCH DIFF/MERGE/PICK` opened `eng.Database(ctx, N)` under `S`'s identity and looked only in `S`'s local catalog, failing with `ERROR 1146: no such table N.t`. This PR routes both read paths by per-operand physical-owner identity, keeps the existing writes-into-subscription rejection, closes the coverage-blind publication-routed snapshot drop, and serializes table-level snapshot creation against publication sources with concurrent publication/subscription DDL through a keyed RC admission protocol. ### Root causes 1. `doCreateSnapshot` (`SNAPSHOTLEVELTABLE`, `pkg/frontend/snapshot.go`) used `getSqlForCheckDatabaseTable` with `(reldatabase = N, account_id = S)`, so alias tables never matched their physical `mo_tables` rows. 2. `getRelations` (`pkg/frontend/data_branch.go`) resolved both diff/merge operands by name in the caller's account catalog only; the branch privilege check synthesized an unrouted SELECT, hiding the real visibility cause. 3. Publication-routed `DROP SNAPSHOT` was coverage-blind: it attached the publication account and deleted the snapshot by name with no check that the record lay inside the publication's persisted scope (pre-existing exposure; dangerous once physical-owner routing exists). 4. No admission serialization existed between table-level snapshot creation through a publication source and concurrent publication/subscription DDL: a revoke could pass its coverage check against state the snapshot commit had already relied on (catalog reads under RC vs binding state at commit). ### Exact changes Production: - `pkg/frontend/data_branch_subscription.go` (new): subscription operand classification (local / alias / missing) and physical-owner resolution via `getSubscriptionMeta`, shared by the DATA BRANCH and snapshot paths. - `pkg/frontend/data_branch_types.go`, `pkg/frontend/data_branch.go`, `pkg/frontend/data_branch_hashdiff.go`, `pkg/frontend/data_branch_helpers.go`: per-operand descriptor threading owner identity and the operand's transaction; `getRelations`, hash-diff scans, and LCA reopen resolve each read operand through its owner, so `DIFF/MERGE/PICK` work against alias operands; the writes-into-subscription rejection (cannot use a subscription database as a destination) is preserved; same-transaction integrity is enforced. - `pkg/frontend/data_branch_privilege.go`: privilege classification reports the real visibility cause (alias vs missing) instead of a synthesized unrouted SELECT failure. - `pkg/frontend/snapshot.go`: table-level `CREATE SNAPSHOT FOR TABLE N.t` resolves aliases through the subscription meta; the snapshot record binds the physical `(database, logical table id)` identity and the coverage check enforces `reldatabase` / `relname` / `rel_id == snapshot objId`; publication-routed drop rebinds the record into the publication's persisted scope before delete (scope-bound deletion). - `pkg/frontend/snapshot_publication.go` (new): publication binding resolution and revalidation, drop-time binding for database/table/foreign-source records, the shared source-gate SQL derivation (`mo_feature_registry`), owner-sequence locking. - `pkg/frontend/lifecycle_admission_rc.go`: keyed RC admission protocol; publication DDL invalidates in-flight snapshot bindings (`invalidatePublicationViewMetadata`); split key order for replacement tables (local physical id vs published logical id). - `pkg/frontend/snapshot_record_fault.go` (new): test-only record-insert fault seam, inert unless armed by tests. Tests and design: - New frontend unit tests — `data_branch_subscription_test.go`, `data_branch_owner_scoped_test.go`, `snapshot_publication_test.go` (23 tests: subscription visibility model, write-destination rejection, privilege causes, binding resolution/revalidation/drop binding incl. foreign source, coverage check, RC admission plan values and split key order, owner-sequence locking, create admission/rebind, hashdiff owner-scoped identity, LCA reopen candidates, same-transaction integrity, operand transaction threading, pinned transaction view, reroute/replay recovery, live-context LCA scan). - New transaction-backed integration lifecycle proof — `pkg/tests/sqlintegration/publication_snapshot_lifecycle_test.go` (`TestIssue30949PublicationSnapshotLifecycleAdmission`, 17 subtests: publish/subscribe across two accounts; snapshot and diff of alias tables; in-flight revoke/retarget/alias-replacement fail-closed then heal; blocked-writer error-1205 alias-key probe; abandonment residue phases with processlist drain, record/usage/lock absence assertions, and writable probes; keyed `mo_locks` gate-waiter oracle proving holder = admission txn vs waiter = revoke txn and post-release absence; `-count=2` rerunnable). - New BVT case — `test/distributed/cases/publication_subscription/pub_sub_data_branch.sql` + `.result` (user-visible SQL repro: snapshot and diff over subscription tables; expected errors for write-into-subscription and post-revoke access). - `pkg/frontend/authenticate_test.go`: plan-value coverage for the lifecycle admission. - Design document — `docs/design/20261023-subscription-table-branch-snapshot-routing.md` (v7, SHA256 `d7e04d7dc200bd5d3f44fc68e615d46a46b09ab9a93503cfedceb391ab80f176`), committed byte-identical to the revision that passed the independent design review; section 1 records the base reproduction evidence, section 11 the review record. ### Issue-to-test proof - Base failure: on merge-base `bc84bd142600b745503e225cb89cb1526df8d35e`, `create snapshot sp_sub_t1 for table sub3 t1` fails with `ERROR 20101 (HY000): table sub3.t1 does not exist` and `data branch diff sub3.t1 against sub3.t1` fails with `ERROR 1146 (42S02): no such table sub3.t1`, while `select count(*)` / `show tables` / `information_schema.tables` resolve the same tables (reproduction recorded in design document section 1). - Post-fix: the same statements succeed against the fixed build — 16 consecutive repro runs rc=0 plus 3 expected negatives (`/tmp/mo-issue30949-r13/green-repro-r13.log`); the strict BVT file reports 324/324 checks, failed:0 (`/tmp/mo-30949-r13-myfile-fresh.log`). - The integration lifecycle test asserts the equivalence oracle end-to-end: alias snapshots equal physical-owner snapshots, alias diffs report no differences, and every revoke/retarget/replacement interleaving fails closed then heals on resubscribe. ### Test commands All run from the worktree with `GOWORK=off`, `-mod=readonly`, `CGO_CFLAGS="-I$PWD/cgo -I$PWD/thirdparties/install/include"`: - `go test -count=1 -v -timeout 25m -run TestIssue30949PublicationSnapshotLifecycleAdmission ./pkg/tests/sqlintegration/` — 17/17 subtests PASS, `ok 21.181s` (`/tmp/mo-30949-r14-f3int2.log`) and re-proven on the final bytes `ok 19.483s`, exit 0 (`/tmp/mo-30949-r15-f3int-lintfix.log`). - `go test -race -count=1 -run TestIssue30949PublicationSnapshotLifecycleAdmission ./pkg/tests/sqlintegration/` — `ok 119.552s`, zero `WARNING: DATA RACE` (`/tmp/mo-30949-r14-race_f3int.log`). - Complete `go test -race ./pkg/frontend/` package run — `ok 99.112s`, zero DATA RACE (`/tmp/mo-30949-r14-race_frontend_full.log`). - `-count=2` rerun of the lifecycle test — `ok 30.344s` (`/tmp/mo-30949-r14-f3count2.log`). - Focused frontend unit run (23 new tests, `-v` verified every name executes) — 23/23 PASS, `ok 1.691s`, exit 0 (`/tmp/mo-30949-final-frontend-ut-v.log`); full frontend unit package `ok 33.473s`. - `go vet ./pkg/frontend/ ./pkg/tests/sqlintegration/` — exit 0; `gofmt` clean. - `golangci-lint run -c .golangci.yml --new-from-rev bc84bd1 ./pkg/frontend/ ./pkg/tests/sqlintegration/` — 0 issues, exit 0 (`/tmp/mo-30949-final-lint2.log`). - BVT with an isolated mo-tester against an isolated MO runtime: `publication_subscription` [TOTAL 3271, FAILED 0], `git4data/branch` [SUCCESS 6131, IGNORED 20, FAILED 0], `snapshot` [TOTAL 18191, FAILED 0]; strict new file `pub_sub_data_branch` 324/324, failed:0. ### Residual risks - Account-level `CREATE SNAPSHOT ... FROM PUBLICATION` intentionally remains on the pre-existing broad gate for account-covering publications (`database_id = 0`); unchanged by this PR. - Publication table lists persist names only and can go stale for foreign-owned publications; binding revalidation compares logical table ids, so a replaced table keeps coverage while a dropped table fails closed. - The record-insert fault seam in `pkg/frontend/snapshot_record_fault.go` is test-only and inert unless armed; unarmed production behavior is unaffected. - The full distributed BVT matrix runs in CI; locally the three impacted suites above plus focused unit, integration, and race proof are green.
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? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 1f962fac6e3858f82489de5ae9c823c13d347b32
Assessment: approve
Reviewed the complete 18-file delta, surrounding callers, design, tests and supplied review concerns. The design correctly separates subscriber, publication-owner and physical-owner identities while reusing existing authorization and lifecycle admission. Lock ordering and post-lock revalidation protect concurrent rebind/revoke operations; owner-scoped reads preserve caller cancellation. All three previous concerns are addressed. No actionable correctness, isolation, cleanup or design finding remains.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Retained evidence is under /home/xupeng/.local/state/mo-bot/jobs/f4f291c11da7b690cd40c7a5/attempt-1. review-audit.json maps commands, source fingerprints, exit receipts and log hashes; review-notes.md records the review scope and reasoning.
-
Isolation preflight passed. Compatible native libraries passed the repository provenance verifier after all 192 tracked native input paths and contents matched. Logs: preflight.log, native-provenance.log and native-link-flags.log; receipts: checks/1792913219239667207-3.json, checks/1792913229907690611-3.json and checks/1792913275829798437-3.json.
-
Focused go test -race -count=2 passed all 23 new frontend test roots and all 17 SQL lifecycle integration scenarios twice, including cancellation, rollback, rebind/revoke serialization and concurrent creation/deletion. No race reports. Log: focused-race.log; exit-zero receipt: checks/1792913629347162176-4.json.
-
Verified the recorded approved v7 design hash against its Git revision; subsequent document changes only record approval. Inspected unconditional bounded worker cleanup and SQL pool closure before fatal teardown assertions. Log: design-revision.log; receipt: checks/1792913435790362134-3.json.
-
Frozen current-head evidence records successful shared build, x86 UT, arm64 SCA, coverage, PROXY and COMPOSE PESSIMISTIC BVT, and CI Required checks. Skipped checks were not counted as passes.
-
Final audit confirmed the exact head, merge-base, unchanged source and test-result counts. Log: review-audit.log; exit-zero receipt: checks/1792913810726716246-4.json.
Limitations:
-
Full distributed BVT and mixed-version upgrades were not rerun locally. Raw CI logs, author temporary logs and the original design-decision JSON were unavailable; author-reported test counts were not treated as independently reproduced. The versioned approval record and reviewed design revision were available.
-
No performance benchmark was run. Added metadata work is confined to branch/snapshot entry points; distinct-owner lineage reopening may require a second lookup. Ordinary SELECT/DML execution is unchanged, but affected-operation latency is not quantified.
-
Standalone linked-issue text was absent; its behavioral contract was assessed through the frozen PR description and design. Documented third-owner lineage and old-CN cleanup limitations remain outside this change.
-
git diff --check exited 2 for trailing whitespace in moved SQL and empty BVT result cells. These were inspected as nonblocking formatting issues, not reported as a passing check.
Merge Queue Status
This pull request spent 2 hours 7 minutes 22 seconds in the queue, with no time running CI. ReasonThe merge conditions cannot be satisfied due to failing checks
Failing checks:
HintYou may have to fix your CI before adding the pull request to the queue again. Waiting for any of
All conditions
Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #30949
What this PR does / why we need it:
A subscription database
Nin a subscriber accountSis an alias over a publisher's physical databaseD. Ordinary reads attach the physical-owner identity and rebindN -> Dbefore table resolution, but two owner paths bypassed that routing, so a subscription table thatSELECT,SHOW TABLES, andinformation_schemaall resolve was reported as missing:CREATE SNAPSHOT ... FOR TABLE N.tprobedmo_catalog.mo_tableswithreldatabase = N AND account_id = S; physical rows live under(D, physical owner), so the statement failed withERROR 20101: table N.t does not exist.DATA BRANCH DIFF/MERGE/PICKopenedeng.Database(ctx, N)underS's identity and looked only inS's local catalog, failing withERROR 1146: no such table N.t.This PR routes both read paths by per-operand physical-owner identity, keeps the existing writes-into-subscription rejection, closes the coverage-blind publication-routed snapshot drop, and serializes table-level snapshot creation against publication sources with concurrent publication/subscription DDL through a keyed RC admission protocol.
Root causes
doCreateSnapshot(SNAPSHOTLEVELTABLE,pkg/frontend/snapshot.go) usedgetSqlForCheckDatabaseTablewith(reldatabase = N, account_id = S), so alias tables never matched their physicalmo_tablesrows.getRelations(pkg/frontend/data_branch.go) resolved both diff/merge operands by name in the caller's account catalog only; the branch privilege check synthesized an unrouted SELECT, hiding the real visibility cause.DROP SNAPSHOTwas coverage-blind: it attached the publication account and deleted the snapshot by name with no check that the record lay inside the publication's persisted scope (pre-existing exposure; dangerous once physical-owner routing exists).Exact changes
Production:
pkg/frontend/data_branch_subscription.go(new): subscription operand classification (local / alias / missing) and physical-owner resolution viagetSubscriptionMeta, shared by the DATA BRANCH and snapshot paths.pkg/frontend/data_branch_types.go,pkg/frontend/data_branch.go,pkg/frontend/data_branch_hashdiff.go,pkg/frontend/data_branch_helpers.go: per-operand descriptor threading owner identity and the operand's transaction;getRelations, hash-diff scans, and LCA reopen resolve each read operand through its owner, soDIFF/MERGE/PICKwork against alias operands; the writes-into-subscription rejection (cannot use a subscription database as a destination) is preserved; same-transaction integrity is enforced.pkg/frontend/data_branch_privilege.go: privilege classification reports the real visibility cause (alias vs missing) instead of a synthesized unrouted SELECT failure.pkg/frontend/snapshot.go: table-levelCREATE SNAPSHOT FOR TABLE N.tresolves aliases through the subscription meta; the snapshot record binds the physical(database, logical table id)identity and the coverage check enforcesreldatabase/relname/rel_id == snapshot objId; publication-routed drop rebinds the record into the publication's persisted scope before delete (scope-bound deletion).pkg/frontend/snapshot_publication.go(new): publication binding resolution and revalidation, drop-time binding for database/table/foreign-source records, the shared source-gate SQL derivation (mo_feature_registry), owner-sequence locking.pkg/frontend/lifecycle_admission_rc.go: keyed RC admission protocol; publication DDL invalidates in-flight snapshot bindings (invalidatePublicationViewMetadata); split key order for replacement tables (local physical id vs published logical id).pkg/frontend/snapshot_record_fault.go(new): test-only record-insert fault seam, inert unless armed by tests.Tests and design:
data_branch_subscription_test.go,data_branch_owner_scoped_test.go,snapshot_publication_test.go(23 tests: subscription visibility model, write-destination rejection, privilege causes, binding resolution/revalidation/drop binding incl. foreign source, coverage check, RC admission plan values and split key order, owner-sequence locking, create admission/rebind, hashdiff owner-scoped identity, LCA reopen candidates, same-transaction integrity, operand transaction threading, pinned transaction view, reroute/replay recovery, live-context LCA scan; the concurrent-rebind subtest releases its admission-barrier mock through an unconditional cleanup with deadline-bounded barrier/join waits).pkg/tests/sqlintegration/publication_snapshot_lifecycle_test.go(TestIssue30949PublicationSnapshotLifecycleAdmission, 17 subtests: publish/subscribe across two accounts; snapshot and diff of alias tables; in-flight revoke/retarget/alias-replacement fail-closed then heal; blocked-writer error-1205 alias-key probe; abandonment residue phases with processlist drain, record/usage/lock absence assertions, and writable probes; keyedmo_locksgate-waiter oracle proving holder = admission txn vs waiter = revoke txn and post-release absence; teardown closes all three SQL pools before its final joined error assertion;-count=2rerunnable).test/distributed/cases/publication_subscription/pub_sub_data_branch.sql+.result(user-visible SQL repro: snapshot and diff over subscription tables; expected errors for write-into-subscription and post-revoke access).pkg/frontend/authenticate_test.go: plan-value coverage for the lifecycle admission.docs/design/20261023-subscription-table-branch-snapshot-routing.md(v8, SHA256f38bb32deb3b1f6000f23600a924826547bea719d45509cd3118dc4aa9480280). The independently approved revision is v7 (SHA256d7e04d7dc200bd5d3f44fc68e615d46a46b09ab9a93503cfedceb391ab80f176); v8 changes only the header and the section 11 review record, which now records the design-only PASS with its traceable decision artifact (state/artifacts/issue-30949/pre-pr-review-1792751823194.json,approved=true, no findings; v7/v8 archived copies understate/artifacts/issue-30949/). Section 1 records the base reproduction evidence.Issue-to-test proof
bc84bd142600b745503e225cb89cb1526df8d35e,create snapshot sp_sub_t1 for table sub3 t1fails withERROR 20101 (HY000): table sub3.t1 does not existanddata branch diff sub3.t1 against sub3.t1fails withERROR 1146 (42S02): no such table sub3.t1, whileselect count(*)/show tables/information_schema.tablesresolve the same tables (reproduction recorded in design document section 1)./tmp/mo-issue30949-r13/green-repro-r13.log); the strict BVT file reports 324/324 checks, failed:0 (/tmp/mo-30949-r13-myfile-fresh.log).Test commands
All run from the worktree with
GOWORK=off,-mod=readonly,CGO_CFLAGS="-I$PWD/cgo -I$PWD/thirdparties/install/include":go test -count=1 -v -timeout 25m -run TestIssue30949PublicationSnapshotLifecycleAdmission ./pkg/tests/sqlintegration/— 17/17 subtests PASS,ok 21.181s(/tmp/mo-30949-r14-f3int2.log) and re-proven on the final bytesok 19.483s, exit 0 (/tmp/mo-30949-r15-f3int-lintfix.log).go test -race -count=1 -run TestIssue30949PublicationSnapshotLifecycleAdmission ./pkg/tests/sqlintegration/—ok 119.552s, zeroWARNING: DATA RACE(/tmp/mo-30949-r14-race_f3int.log).go test -race ./pkg/frontend/package run —ok 99.112s, zero DATA RACE (/tmp/mo-30949-r14-race_frontend_full.log).-count=2rerun of the lifecycle test —ok 30.344s(/tmp/mo-30949-r14-f3count2.log).-vverified every name executes) — 23/23 PASS,ok 1.691s, exit 0 (/tmp/mo-30949-final-frontend-ut-v.log); full frontend unit packageok 33.473s.go vet ./pkg/frontend/ ./pkg/tests/sqlintegration/— exit 0;gofmtclean.golangci-lint run -c .golangci.yml --new-from-rev bc84bd142600b745503e225cb89cb1526df8d35e ./pkg/frontend/ ./pkg/tests/sqlintegration/— 0 issues, exit 0 (/tmp/mo-30949-final-lint2.log).publication_subscription[TOTAL 3271, FAILED 0],git4data/branch[SUCCESS 6131, IGNORED 20, FAILED 0],snapshot[TOTAL 18191, FAILED 0]; strict new filepub_sub_data_branch324/324, failed:0.Residual risks
CREATE SNAPSHOT ... FROM PUBLICATIONintentionally remains on the pre-existing broad gate for account-covering publications (database_id = 0); unchanged by this PR.pkg/frontend/snapshot_record_fault.gois test-only and inert unless armed; unarmed production behavior is unaffected.