Skip to content

[Bug]: DATA BRANCH DIFF fails after GC and restart #27465

Closed

Description

@Ariznawlll

Description

DATA BRANCH DIFF cannot read a live branch after storage GC and a service restart. A minimal one-edge branch is sufficient: the pre-restart DIFF is correct, while the first post-restart DIFF fails during history lookup even though both tables and the branch protection record remain present.

Environment

  • Branch: main
  • Commit: dd040ad6913e9b86f592b574e5fffb610003f72a
  • Deployment: local single-process topology (1 CN, 1 TN, 1 Log Service), local filesystem storage
  • Test date: 2026-08-22

Steps to reproduce

create database db_gc_restart;
use db_gc_restart;
create table root(id int primary key, v int);
insert into root values (1,1),(2,2),(3,3),(4,4);

data branch create table leaf from root;
update root set v=101 where id=1;
delete from root where id=2;
update leaf set v=303 where id=3;
insert into leaf values(5,505);

-- Before lifecycle actions this returns four changes.
data branch diff leaf against root output count;

select mo_ctl('dn','flush','db_gc_restart.root');
select mo_ctl('dn','flush','db_gc_restart.leaf');
select mo_ctl('dn','globalcheckpoint','');
select mo_ctl('dn','diskcleaner','force_gc');

-- Still returns four before restart.
data branch diff leaf against root output count;

-- Gracefully restart this local MO service, then reconnect.
data branch diff leaf against root output count;

Actual behavior

The post-restart DIFF fails with:

HY000 / 20101: internal error: cannot find database <id> (db_gc_restart) created_time at snapshot <ts>

The failed read does not alter visible data: in the expanded chain matrix, the root table retained 3 rows, the leaf retained 5 rows, and 2 branch-protection records remained present after every failure.

Expected behavior

GC and restart must not invalidate history required by a live Data Branch. The post-restart DIFF should return the same four changes as before restart.

Stability and controls

  • Minimal one-edge reproducer with GC + restart: 3/3 failed on latest main.
  • Expanded root -> middle -> leaf lifecycle matrix with GC + restart: 10/10 failed; each run passed the pre-restart DIFF.
  • Same expanded topology with restart but without GC: 3/3 passed, including exact DIFF results and subsequent branch-history reclamation.
  • Failure checks: both table contents and branch protection metadata remained intact after each error.
  • No branch-table mergeobjects is required. This distinguishes the issue from [Bug]: DATA BRANCH DIFF loses history after branch-table mergeobjects and GC #27451, which requires branch-table compaction and fails with a missing object error before restart.

Evidence

  • DataBranchGcRestartDirectProbe.java: minimal 3-run matrix.
  • DataBranchProtectRecoveryProbe.java: 10-run chain matrix plus 3-run restart-only control.

Code analysis

Confirmed failure site: getDatabaseCreatedTimeLowerBoundByPK in pkg/frontend/data_branch.go scans mo_database at the branch history timestamp and raises this error when it cannot find the database creation timestamp.

Hypothesis: after GC/restart, the snapshot catalog scan used to derive the collection lower bound no longer sees the still-live database's historical creation record. The helper was introduced by #24371 while optimizing arbitrary-DAG collection ranges; the fallback or retention path should preserve a usable lower bound for a live branch.

Regression coverage

After the fix, add a deterministic case under motr/suites/12_git4data / test/distributed/cases/git4data/branch/diff/ that creates a one-edge branch, advances flush/checkpoint/GC, restarts the service in the appropriate recovery workflow, and asserts exact post-restart DIFF rows plus table/protection state.

Related

Activity

  1. added this to the MO-202608 milestone on Aug 21, 2026
  2. added
    kind/bug
    on Aug 21, 2026
  3. added theissue type on Aug 21, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Aug 22, 2026
  5. gouhongshen commented on Aug 22, 2026

    @gouhongshen
    Contributor

    Triage decision: defer.

    Reason: the reported GC-and-restart failure cannot currently be reproduced or proved with an executable regression, so an active s0 fix would be speculative.

    Current evidence: (1) the issue SQL ran on current main through flush, global checkpoint, forced disk GC, a full mo-service process restart, and reconnect; DATA BRANCH DIFF returned the exact four rows, root/leaf retained 3/5 rows, and the branch protection row remained present; (2) the same one-edge lifecycle executed against the reported dd040ad code in an isolated storage-backed cluster and reached post-restart DIFF without the reported database-created-time lookup error; its only failure was an embedded-recovery protection-snapshot identity mismatch, which is not evidence for this issue; (3) a direct dd040ad mo-service binary was built, but its fixed launch ports were concurrently occupied by an unrelated in-progress local test, so no direct old-binary run was possible without changing that tests service scope.

    Attempted test construction: a deterministic Go integration case covering the exact DDL/DML, flush/checkpoint/force_gc, full restart, exact DIFF count and rows, table contents, and protection state. It was not retained because it passed the reported DIFF behavior on the investigated revisions and therefore cannot prove a new fix.

    To promote later: provide a reproducible data directory/configuration or a failing executable case on current main that reaches getDatabaseCreatedTimeLowerBoundByPK after restart; then a focused root-cause fix and regression can be safely validated.

  6. added and removed
    severity/s0
    on Aug 22, 2026
  7. added
    severity/s0
    and removed on Sep 4, 2026
  8. gouhongshen commented on Sep 4, 2026

    @gouhongshen
    Contributor

    Triage decision: defer.

    Reason: the reported GC-and-restart failure still cannot be reproduced or turned into a failing executable regression, so changing the catalog-history path would be speculative.

    Current evidence: I built the exact reported commit dd040ad6913e9b86f592b574e5fffb610003f72a and ran its real mo-service in an isolated local single-process topology with persistent filesystem storage. Three independent rounds executed the issue’s minimal DDL/DML, verified the four-change DIFF before lifecycle actions, flushed both tables, forced a global checkpoint and disk GC, verified DIFF again, gracefully stopped the full service, restarted it over the same data directory, and reconnected. All 3/3 post-restart runs returned count 4; exact rows were root UPDATE (1,101), root DELETE (2,2), leaf UPDATE (3,303), and leaf INSERT (5,505). Root/leaf row counts stayed 3/5 and the live branch-protection row count stayed 1. This closes the earlier direct-old-binary evidence gap; prior investigation also passed the same lifecycle on current main and in an isolated storage-backed integration fixture.

    Code findings: getDatabaseCreatedTimeLowerBoundByPK and its “cannot find database ... created_time at snapshot” failure remain present at the reported commit and current main. No intervening change explains a distinct fix for that lookup. Since the exact public reproducer does not reach the failure even on the reported revision, there is no demonstrated violated invariant from which to derive a safe production change.

    Attempted regression construction: the deterministic integration scenario covers the exact DDL/DML, pre-GC DIFF, flush/checkpoint/force-GC, full process restart, exact post-restart DIFF rows/count, table contents, and protection metadata. It passes on the reported revision, so retaining it as proof of a new fix would be invalid. A BVT file also cannot itself restart the owning service; the appropriate recovery harness was exercised directly instead.

    To promote later: provide the failing data directory and launch configuration, or a deterministic case on current main that reaches the database-created-time lookup failure after restart. That evidence can identify the missing retention/state transition and support a focused fix plus a regression that fails before the change.

  9. 44 remaining items

  10. added
    severity/s0
    and removed on Oct 12, 2026
  11. gouhongshen commented on Oct 16, 2026

    @gouhongshen
    Contributor

    PR #30410 is trying to fix this issue.

  12. gouhongshen commented on Oct 17, 2026

    @gouhongshen
    Contributor

    PR #30410 has merged and is awaiting manual validation. The issue remains open.

  13. XuPeng-SH commented on Oct 17, 2026

    @XuPeng-SH
    Contributor

    本轮实际执行验证(2026-10-17,main d9cf2dd4e2b92e2193bb390115be624b76099764,Linux/amd64、Go 1.27.1、匹配 make cgo 产物):

    mo-cgo-test -p 2 -count=1 -tags matrixone_test -json -timeout=25m -run '^(TestDataBranchDiffAcrossCheckpointGCAndRestart|TestRecoveryClusterStartupBudget)$' ./pkg/embed 返回 PASS,生命周期根测试 219.80s:

    • gc_checkpoint_restart:200.60s,通过原 issue 的一边 branch SQL、完整 DIFF 行和 OUTPUT COUNT、当前表数据及 branch protection 检查;探针真实对象文件在 70 轮 checkpoint 检查后、2m57.824s 内被物理回收,随后两次完整集群 Close/Start 后的断言均通过。没有将 force_gc 返回 OK 当作 GC 完成证据。
    • checkpoint_restart:11.80s,通过;flush_only_restart:7.40s,通过。两项独立集群保留生产 1h GC TTL,对照结果未依赖 GC 场景状态。
    • TestRecoveryClusterStartupBudget 全部 6 个子场景通过,另外单独 -race -count=1 执行同一根测试也通过。
    • 完整 logtailreplay 包执行通过(360 个测试/子测试通过;现有 Requires real tombstone object files 的一项跳过,不计通过)。

    #30410 是回归覆盖,生产修复此前由 #29867 落地;本轮实测证明当前 main 上报告的嵌入式恢复场景通过,不将测试代码描述成新的生产修复,也不扩展为未执行的多进程/远程部署验证。按约定将 #27465 转给 @Ariznawlll 继续测试确认。

  14. Ariznawlll commented on Oct 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:7c2847207dc5bd87f6c23dc7318f7be21c0a5f2a
    • 部署方式:隔离工作树、Darwin arm64、Go 1.27.1;生命周期集成测试每个场景启动独立 1 CN / 1 TN / 1 LogService embedded 集群和本地文件存储。仅 GC 场景使用私有集群加速扫描/TTL,checkpoint-only 与 flush-only 对照保持生产默认 GC TTL。另在隔离独立 mo-service 的 MySQL 6001 运行 MOTR SQL。
    • 测试日期:2026-10-18(北京时间;任务来自 10 月 17 日转入)

    原问题验证

    已确认生产修复 PR #29867 进入本次官方 main,PR #30410 增补生命周期回归测试。独立执行 TestDataBranchDiffAcrossCheckpointGCAndRestart -count=3,总计 610.476 秒、3/3 根测试通过。每轮 gc_checkpoint_restart 均按原 issue 建立 root/leaf 一边分支,产生 root UPDATE(1,101)、DELETE(2,2) 与 leaf UPDATE(3,303)、INSERT(5,505) 共 4 条差异;执行 flush、global checkpoint、force_gc,并通过探针对象文件实际消失证明物理 GC 完成,之后完整集群 Close/Start 两次,每次仍能读取 4 条精确 DIFF 及 OUTPUT COUNT=4、root 3 行、leaf 5 行、branch protection 1 条。没有把 force_gc 返回 OK 当作 GC 已完成。

    Happy Path 覆盖

    1. 相同分支数据在普通独立 SQL 连接中 DIFF COUNT=4,root (1,101),(3,3),(4,4)、leaf (1,1),(2,2),(3,303),(4,4),(5,505);MOTR 成对用例定向 3/3,45/45 语句通过。
    2. checkpoint_restart 及 flush_only_restart 各自在独立集群中按精确差异、行数与保护记录断言通过;各 3/3。GC 主路径两次重启后仍保持正确,3/3。

    Unhappy Path 覆盖

    1. 原有失败点“物理 GC 后重启找不到 mo_database 历史创建行”在 3/3 次完整生命周期中未再出现;重启前后均核对分支数据与保护记录,未出现半成功或静默丢行。
    2. checkpoint-only 与 flush-only 对照分别保留不同的 GC 条件,避免把仅 flush 的成功误当作 GC/重启通过。本次未在共享环境执行破坏性全局 GC。

    白盒验证

    运行的是合入后的生产集成测试 pkg/embed/branch_checkpoint_restart_test.go,不是 mock 返回值;该测试实际检查物理探针对象回收、完整服务重启和 SQL DIFF 值。-count=3 PASS。#30410 的 PR 说明亦提供仅回退 #29867 关键 guard 时复现 20101 的负对照,本轮未对官方 main 改写生产代码。

    回归测试

    • MatrixOne 生命周期集成回归:TestDataBranchDiffAcrossCheckpointGCAndRestart,3/3;独立环境执行的 GC/重启路径不放进共享 MOTR,以免对其他测试执行全局清理。
    • MOTR 持续 SQL 回归:suites/14_issue_regression/t/issue_27465_data_branch_diff_lifecycle_surface.test 与 r/issue_27465_data_branch_diff_lifecycle_surface.result,已追加汇总 PR #247,head 086bfdaf;定向 3/3、45/45 语句,覆盖原始分支/DIFF 值但不冒充 GC/重启。PR 尚未合入,完整 suite/共享集成 CI 尚未通过。

    测试证据

    • MOTR 新增成对回归提交
    • MatrixOne 生命周期集成测试 PR #30410
    • 隔离官方 main 工作树 /private/tmp/mo-30265-qa-adWo0K:go test -tags matrixone_test -count=3 -timeout=25m -run '^TestDataBranchDiffAcrossCheckpointGCAndRestart$' ./pkg/embed 返回 ok ... 610.476s;MOTR 本地 run var/log/run-1792255950874343000 返回 total=3 success=3 failed=0 skipped=0。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions