Skip to content

[Bug]: RESTORE DATABASE {snapshot=...} silently deletes publications targeting the restored database and never recreates them — subscribers break permanently #30610

Done

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

b24d1b3 (2026-10-16)

Other Environment Information

  • Hardware: macOS arm64 (Apple Silicon)
  • Topology: single-node standalone
  • OS: macOS

Actual Behavior

RESTORE DATABASE <db> {snapshot="<snap>"} silently deletes the publication targeting that database and never recreates it. All subscribers of that publication then break permanently with there is no publication <name>.

Reproduced 3/3 rounds on a fresh standalone instance. In every round:

  1. create publication pubS database spb account acc1; — publication exists, subscription spb_sub works
  2. create snapshot snapS for database spb;
  3. insert a row (post-snapshot mutation)
  4. restore database spb {snapshot="snapS"}; — restore itself succeeds (data rolls back correctly)
  5. show publications; → empty, pubS is gone (mo_catalog.mo_pubs row deleted)
  6. On the subscriber account: use spb_sub; select ... → ERROR 20101: there is no publication pubS

The subscription database remains as a dangling record (show subscriptions still lists it), so the subscriber has no signal that the source vanished — queries just fail.

Root cause (source-level)

The PITR path does recreate publications after a database restore: pitr.go:1621 calls createPubByPitr(...) (defined at pitr.go:2607), which reads mo_catalog.mo_pubs {MO_TS = ...} and re-runs CREATE PUBLICATION for every publication of the restored database.

The snapshot path has no counterpart: snapshot_restore_with_ts.go (the whole file's function list — restoreToAccountFromTS, restoreDatabaseFromTS, recreateTableFromTS, etc.) contains no publication handling at all. The drop-and-recreate dance during database restore removes the mo_pubs row (the database being restored is dropped first), and nothing rebuilds it.

So the two restore paths disagree: PITR restores publications (that's the intent — see createPubByPitr's log message "create pub after the database is created by pitr"), while snapshot restore destroys them.

Expected Behavior

RESTORE DATABASE ... {snapshot=...} should restore publications targeting the database the same way the PITR path does (recreate mo_pubs rows), keeping the publication and its subscriptions working across the restore. At minimum, dropping the publication should be loud (warn/error), not silent.

Steps to Reproduce

-- sys tenant:
create account acc1 admin_name 'admin' identified by 'admin123';
create database spb; create table spb.t (id int primary key); insert into spb.t values (1),(2);
create publication pubS database spb account acc1;

-- acc1 tenant:
create database spb_sub from sys publication pubS;   -- works

-- sys tenant:
create snapshot snapS for database spb;
insert into spb.t values (3);
restore database spb {snapshot="snapS"};
show publications;   -- EMPTY: pubS silently deleted

-- acc1 tenant:
use spb_sub; select * from t;   -- ERROR 20101: there is no publication pubS

Additional information

Activity

  1. added
    kind/bug
    on Oct 19, 2026
  2. added this to the MO-202610 milestone on Oct 19, 2026
  3. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    PR #30675 current-head review update — case-sensitive publication replay

    XuPeng-SH's formal review of head 45730bd08bd20183f70fe2785dbbcf8844ad917b reports a new P1 authorization regression in pkg/frontend/publication_replay.go: with lower_case_table_names=0, restoring a snapshot can lowercase the saved publication table name. If both PublishedT and a private publishedt exist, the restored publication then targets the latter, allowing the subscriber to read a table that was private before restore. If only PublishedT exists, replay instead fails because publishedt cannot be found. The review requests preserving catalog identifier bytes and adding case-collision plus non-collision regressions.

    The reviewer reports a real SQL probe showing access denied before restore and subscriber access to the private value afterward; the merge-base controls passed. This is the reviewer's execution evidence, not a test I ran in this turn. It extends the existing RESTORE DATABASE publication issue, so no duplicate issue was opened. Issue remains open and assigned to matrix-meow pending fix and validation.

  4. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    QA follow-up for PR #30675 after the synchronize to head 1eadf5008d3e984f50a07c9548d9e32aabad594b:

    The source-level fix for the previously reported case-sensitive authorization regression is present in this head: publicationStatementForReplay constructs the internal CREATE PUBLICATION AST directly from catalog names, rather than reparsing generated SQL with a hard-coded lower-case mode. The current test diff includes case-distinct identifier coverage and real-SQL regression scenarios. This is a static confirmation only; I could not run the Go or MatrixOne service tests in this workspace, and the latest formal review is still on the prior head 45730bd08bd20183f70fe2785dbbcf8844ad917b.

    Please rerun the case-sensitive collision and non-collision restore cases against this exact head and record the results. I am leaving this issue open and its assignee unchanged until exact-head validation is independently confirmed.

  5. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    PR #30675 cross-path follow-up — PITR publication replay (rechecked at current head)

    Current PR head is 93a72247caacc871efb3dce27cdbcf05798a5761. The earlier finding remains in the current patch: restoreToDatabaseOrTableWithPitr calls createPubByPitr(..., nil) in pkg/frontend/pitr.go, even though createPubByPitr now accepts omittedViews and filters only known unservable views in publicationInfoForBulkRestore.

    PITR restores views later through restoreViewsWithPitr, where an unservable FULLTEXT view can be deliberately skipped and marked unservable. Passing nil means an explicit publication selection that includes that omitted view is still replayed unchanged and can fail publication validation / abort PITR restore. Please add a PITR regression for a publication selecting a FULLTEXT view whose index is unavailable at the restore point, and pass the restore's confirmed omitted-view set or reorder replay after those omissions are known. Keep unexpected missing objects fail-closed.

    This is a source-level recheck of the current patch, not a new local SQL reproduction. The PR body reports local tests on the new head, but this workspace has no MatrixOne checkout/Go toolchain/service, and the visible CI runs are connector E2Es rather than the required restore regression. Issue #30610 remains open and assigned to daviszhen pending a fix and exact-head validation.

  6. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    PR #30675 synchronization update — current head e7e40871c12d8dd092bee8b22a46727b0903edea

    The PR remains open and unmerged. The latest commit changes only the TestInactiveAfterCannotConnect test fixture: it makes setup failures fatal, ensures app cleanup, waits with a bounded eventual assertion, and raises the initial successful-connect budget from 100 ms to 10 s. Static inspection indicates this targets the test panic described in the author's report; it does not change publication replay production code.

    For this exact SHA, GitHub shows Iceberg Connector E2E succeeded and Connector/J Pool Reset E2E is still running; combined status checks are empty. The latest formal approval I found is for older head 1180cd9361046a1b7cd52560d4e0a7c0c7cba28a; no fresh review is recorded on e7e4087. The author reports that two other failures on prior head 93a7224 were cleanup/cluster-startup incidents and that their local macOS reruns passed. Those are author-reported results, not independent validation here.

    I did not run MatrixOne tests locally because this workspace has no MatrixOne checkout or Go toolchain. Issue remains open and assigned to daviszhen; no issue duplication, status change, or reassignment. Next step is to inspect the final exact-head CI (including UT/BVT/SCA) and obtain a fresh review before testing/transfer.

  7. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    Local current-main QA for merged PR #30675 (9693f11), run 2026-10-24:

    • Tested on upstream main 463803d. The 13 Go files changed by this merge have identical Git blob IDs at the tested service-source revision 6f773c5 and current main. The local SQL service binary came from 6f773c5 (SHA-256 51489b59a60310e79eddcf1182c582685b2c60f800f35a0a625eb5359469349b).
    • Ran the committed test/distributed/cases/snapshot/database_restore_publication.sql through separate real MySQL-protocol sessions on an isolated local CN and compared each result with its committed .result: 26/26 SELECT result sets matched, zero mismatches. This includes the reported database-snapshot restore with a live subscriber, subscriber reads after restore, repeated database restore, table-only restore, FK/view ordering, external-FK preservation of the live publication/comment, quoted identifiers and table selection, empty account grants, and zero-table publication state.
    • Focused go test ./pkg/frontend -short -tags=matrixone_test publication/snapshot tests passed (30 top-level PASS markers, package runtime 0.494s), including catalog identifier/case-mode handling, replay ownership boundaries, known-unservable-view filtering, and error propagation.
    • Readback after cleanup found zero fixture publications, accounts, or databases.

    This confirms the reported snapshot database-restore failure in the scoped local run. It is single-node and does not include live PITR, a lower_case_table_names=0 case-collision matrix, or full Compose acceptance. Those boundaries remain for tester confirmation; the issue should stay open until that follow-up.

  8. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    Supplemental local current-main QA for merged PR #30675, run 2026-10-24. The 13 Go files changed by merge SHA 9693f11c84a23f5020394170ef16bf6e61ba5f7a match the tested service source 6f773c556d4f3177f5373eb193cd576e080b662f; upstream main was pinned at 463803dfbbaed941501e231ba216c0a69e6c73c9. The reused service binary SHA-256 is 51489b59a60310e79eddcf1182c582685b2c60f800f35a0a625eb5359469349b.

    On a second owned single-node service with a fresh /tmp data root and unique ports, I enabled lower_case_table_names=0 and used real MySQL-protocol SQL. The fixture created separate PublishedT and private publishedt tables with distinct values, then published only PublishedT. After snapshot database restore, the publication catalog still listed exactly PublishedT; the published and private control tables each returned their pre-snapshot row, and the subscriber listed only PublishedT and read the expected public row. The same case-distinct fixture was restored through live database PITR: the publication retained exact table selection, both source tables returned their pre-anchor rows, and the subscriber read the expected published row. All 11 assertions passed; cleanup readback found zero fixture publications and accounts. Logs and fixture are kept locally in the QA workspace.

    Setup note: account creation after switching the fresh service to mode 0 returned error 1146 for information_schema.CHARACTER_SETS; I preserved that attempt and pre-provisioned the local subscriber while mode was 1, then verified both new sys and subscriber sessions were mode 0 before the challenge. I have not classified that separate setup interaction as a #30675 result.

    This supplements the prior 26/26 committed snapshot result-set checks and focused Go tests. It is still scoped single-node evidence: no multi-CN/Compose run, no PITR FULLTEXT/unservable-view omission challenge, and no three-round repeat. It does not claim full acceptance. The issue remains open and assigned to daviszhen; I made no assignee change.

  9. Ariznawlll commented on Nov 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    当前 main 复验:snapshot 通过,但 PITR 边界仍有确定反例,保持 OPEN

    测试版本

    • 被测及评论时官方 main:c255da6778fac39bc53b5b9defaab3b6f945e4d6。
    • 独立归档构建,binary SHA256:2eaddeaa961297dcb8df498c6abe47610ed16e1eca5ad35edb287538570f7ba0。
    • 真实双 CN MySQL 协议;每轮两个 listener 均通过 SELECT git_version() 核对完整 SHA。

    1. Snapshot publication 健康控制:3 个 root tests × 3 轮,9/9 PASS

    执行当前源码的:

    • TestSnapshotDatabasePublicationReplayBoundaries
    • TestSnapshotEmptyPublicationTablesRestore
    • TestSnapshotPublicationSkipsExternalTables

    覆盖真实 subscriber、重复 RESTORE、FK/view、quoted identifier、显式/空表集合、空授权、大小写碰撞、external table,以及删除 FULLTEXT 索引后成为 unservable 的 view。无 FAIL、SKIP。

    日志 SHA256:6ba295b566b8fe53e6c004cb7ffea9e99b319778f346105a0306ac4fe9e5059e。

    2. PITR + publication + unservable FULLTEXT view:3/3 均失败

    每轮使用独立账号、数据库、publication、subscription 和 PITR,执行以下真实 SQL 流程:

    1. base_t 上建立 FULLTEXT,创建依赖 MATCH ... AGAINST 的 v_ft,发布 base_t,v_ft。
    2. 第二 CN 的订阅账号实际读取 base_t 和 v_ft,确认恢复前链路健康。
    3. 删除 FULLTEXT 索引,使 v_ft 成为恢复时必须省略的 unservable view。
    4. 保留原 PITR 时间条件,在恢复点之后插入另一行,再执行 RESTORE DATABASE ... FROM PITR ...。
    5. 三轮均在 RESTORE 本身返回:
    ERROR 20101: internal error: table 'v_ft' not exists
    

    因此尚未进入后续 publication/subscriber 正确性断言,不能记为通过,也不能用 snapshot 的 9/9 代替该路径。

    三轮日志 SHA256:

    • 46309d9f341eec50037d95bb19fb81e871f8ece9ad2e575ea2ec4624c3c4115b
    • 7d89f9da1a04f86ec8edcb6437cf0a0a55b7b2759f00618d356b6dd753427022
    • 2fd847745effba8848b990005961cb547f280c1d53bb55bd5048e5aea30f9f7d

    探针 SHA256:d424886b068ffb057c24454caa3024125a4c1d3e6250cff7cbe62e45499d56fd。

    3. 源码对应关系与结论

    当前 pkg/frontend/pitr.go 的数据库 PITR publication 重放仍调用 createPubByPitr(..., nil),没有像 snapshot 路径那样传入应省略的 unservable-view 集合。这与本轮 v_ft not exists 反例一致,但这里以真实运行结果为准,不仅凭源码推断。

    本轮确认:原 Issue 的 snapshot 修复在当前 main 的定向矩阵通过;相邻且此前明确保留的 PITR FULLTEXT/unservable-view 缺口仍可稳定触发。 因此 Issue 继续保持 OPEN。失败探针未推送为“已通过”的 MOTR 回归;启动阶段的端口竞态/连接基础设施失败也未混入三轮产品结果。

  10. Ariznawlll commented on Nov 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    原 snapshot publication 场景验收通过;PITR 反例已拆分

    数据库 PITR 在省略 FULLTEXT view 后重放 publication 时的 20101: table 'v_ft' not exists 已另提 #33510:#33510 。三轮真实失败和最小复现均保留在新 Bug,没有写成 PASS golden,也不由 snapshot 结果推断 PITR 已修复。

    因此关闭本 Issue 的原 snapshot publication 范围;#33510 继续保持 OPEN。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions