Skip to content

[Bug]: PITR RESTORE DATABASE fails with strconv.ParseInt error when the database is referenced by a publication (published databases are unrecoverable via PITR) #30607

Closed

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 ... FROM PITR fails completely when the target database is referenced by a publication. The restore aborts with a raw strconv error leaking an internal column-layout mismatch:

ERROR 1105 (HY000) at line 1: strconv.ParseInt: parsing "pubpxb": invalid syntax

(the string being parsed is the publication's own name). The database is left unrestored — data written after the target timestamp is NOT rolled back, so recovery silently fails with no side effects applied.

Isolation matrix (all three cases same instance, same PITR p1):

Case Publication state Restore result
A no publication exists success (data rolled back to target timestamp)
B publication targets the restored database fails with strconv.ParseInt: parsing "<pub_name>": invalid syntax, no restore
C publication exists but references a different database success

Steps to Reproduce

create pitr if not exists p1 for account range 3 'h';
create account acc1 admin_name 'admin' identified by 'admin123';
create database pubB;
create table pubB.t (id int primary key);
insert into pubB.t values (1),(2);
create publication pubpxB database pubB account acc1;   -- key ingredient

-- wait > pitr granularity, e.g. 60s, then record T slightly in the past:
-- T = date_sub(now(), interval 5 second)
insert into pubB.t values (10),(11);   -- data that should be rolled back

restore database pubB from pitr p1 '<T>';
-- ERROR 1105: strconv.ParseInt: parsing "pubpxb": invalid syntax
-- pubB.t still contains the rows inserted after T (restore did not happen)

Reproduced 3/3 on fresh standalone instances.

Root cause direction

pkg/frontend/publication_subscription.go has two different column layouts for reading mo_catalog.mo_pubs:

getPubInfoSqlOld = "select account_id, pub_name, database_name, database_id, ..."
getPubInfoSql    = "select account_id, account_name, pub_name, database_name, database_id, ..."

The restore path selects mo_pubs rows while rebuilding the target database and parses a column that it expects to be numeric (account_id / database_id), but the column actually read is the publication name string — i.e. a column-order mismatch between the old/new getPubInfoSql layouts (the row scanner position does not match the selected layout). The error string parsing "pubpxb" (the pub name) confirms a text field is being fed to strconv.ParseInt.

Expected Behavior

Restoring a database that is being published must either (a) succeed, treating mo_pubs rows correctly regardless of layout, or (b) return a clean, actionable error. Today the restore neither works nor explains itself; a published database is simply unrecoverable via PITR, while the documented purpose of PITR is to recover user databases — and creating a publication is a perfectly legal state for a user database.

Additional information

  • Related known issue [Bug]: CDC must recover or fail explicitly after source-generation changes #30512 (PITR account restore kills CDC) shows the PITR-restore × replication-protocol intersection is fragile; this bug is the same intersection from the publication side.
  • Existing unit test snapshot_pubsub_restore_test.go covers the subscriber-side subscription restore, but not the publisher-side database restore with live publications — this scenario is untested upstream.

Activity

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

    @Ariznawlll
    CollaboratorAuthor

    Precise root cause located

    The failing component is createPubByPitr (pkg/frontend/pitr.go:2607, called at pitr.go:1621): after a PITR database restore it re-creates publications by reading mo_catalog.mo_pubs {MO_TS = ...} via getPubInfoWithPitrFormat:

    select pub_name, database_name, database_id, table_list, account_list, created_time, update_time, owner, creator, comment from mo_catalog.mo_pubs {MO_TS = %d} where account_id = %d and database_name = '%s';

    The result is parsed by extractPubInfosFromExecResult, which expects the current mo_pubs column layout (which since the account_name addition is: account_id, account_name, pub_name, database_name, database_id, ...). The {MO_TS} query above selects a historical projection whose column order no longer matches the extractor — so a pub_name string ("pubpxb") ends up in the database_id/account_id position and strconv.ParseInt fails, aborting the whole restore.

    So the previously reported layout mismatch is between getPubInfoWithPitrFormat (pitre.go:74) and extractPubInfosFromExecResult, not just between getPubInfoSqlOld and getPubInfoSql. The fix should either add the missing account_name column to getPubInfoWithPitrFormat/align the extractor, or make the extractor read columns by name.

  4. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:774d0eda08c622e8717bed8caa8cd8c2ae3ffc2a(测试前核对官方 origin/main;修复 PR fix(frontend): align PITR publication query projection with its row parser (#30607) #30643 的 merge commit 5d79a583e858cf8d3924f4b7d4ce3b760ca4364c 是其祖先)
    • 部署方式:隔离工作树启动本地 mo-service -launch etc/launch/launch.toml,1 CN / 1 TN / 1 LogService,MySQL 6001;SELECT git_version() 返回 774d0eda08。未使用共享 TKE 或外部故障注入。
    • 测试日期:2026-10-21(北京时间)

    原问题验证

    按原报告的 PITR 时间粒度等待超过 60 秒后,在时间点前插入 (1,'initial'),(2,NULL),时间点后插入 (10,'later'),(11,NULL),对仍有 live publication 的数据库执行 RESTORE DATABASE ... FROM PITR。修复后该路径 3/3 成功;每轮恢复前 4 行、SUM(id)=24,恢复后精确为 (1,'initial'),(2,NULL) 两行、SUM(id)=3,后插入行全部消失,publication 元数据仍为 1 条。原先的 strconv.ParseInt: parsing "pubpxb" 错误未再出现。

    Happy Path 覆盖

    1. 已发布数据库(原始 B 路径)3/3:数据与 NULL 均恢复到时间点,publication 保留。
    2. 无 publication 的数据库(原始 A 对照)3/3:恢复后同样精确为 2 行,publication 为 0。
    3. 存在 publication 但只指向其他数据库(原始 C 对照)3/3:目标数据库恢复正确,其 publication 为 0;无关数据库的 publication 保留为 1。

    Unhappy Path 覆盖

    1. 对已恢复的发布数据库插入 (20,'sentinel') 后用非法时间字符串恢复,3/3 返回错误 1105;原有两行、sentinel 及 publication 均保持不变。
    2. 用不存在的 PITR 策略恢复,3/3 返回错误 20101;同样没有删除或改写上述数据和 publication。
    3. 清理测试 publication、数据库、账户和 PITR 后,相关 mo_pubs 与数据库残留均为 0。

    白盒验证

    在同一完整 SHA 上运行 Test_getPubInfoWithPitrLayout|Test_createPubByPitr -count=3,通过。修复 PR #30643 的 UT Coverage、multi-CN PESSIMISTIC BVT、PROXY BVT、CI Required 检查成功。白盒结果只作辅助,关闭依据包括上述真实 SQL/PITR 路径。

    回归测试

    已将独立 oracle 的时间点前后数据、发布元数据、原始 A/B/C 路径和失败原子性加入 MOTR #247,commit 2f9726f3,文件:Python 场景、预期输出、用例入口。在上述隔离服务上定向运行 3/3 成功、0 failed、0 skipped;#247 尚未合入,完整 MOTR suite/集成 CI 本次未运行。

    测试证据

    • 修复:matrixone PR #30643,已合入上述官方 main SHA。
    • 持续回归:MOTR PR #247,head 2f9726f3;上述三个文件包含可复核的 SQL、预期输出及失败原子性断言。
    • 定向回归执行摘要:首轮 total=1 success=1 failed=0 skipped=0;随后 --repeat 2 为 total=2 success=2 failed=0 skipped=0。执行前脚本参数错误已在本地修正,不属于产品失败,修正后的 3 次结果如上。

    测试结论

    测试通过。

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