Skip to content

[Bug]: TAE loses database on restart after compaction and merge despite successful Close #26308

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

The only exact historical match is #4127, which was closed in 2022 because the old replay flow and the test were considered obsolete. There is no open issue for the current implementation and stack.

Environment

  • Branch: main
  • Commit: 159742db6672ff5dadb617880b831da026f0a3f4
  • Platform: macOS arm64

Summary

TAE can return success from DB.Close() after an append/compact/merge sequence, but the next db.Open() cannot restore the database. Depending on timing, replay either reports Unknown database db or terminates in replayTxnStore.registerPreparedDMLTables with ExpectedEOB.

This was reproduced in three independent processes.

Steps to reproduce

Re-enable the existing TestReplay7 in pkg/vm/engine/tae/db/test/replay_test.go and make the first close explicit:

func TestReplay7(t *testing.T) {
    defer testutils.AfterTest(t)()
    testutils.EnsureNoLeak(t)
    ctx := context.Background()

    opts := config.WithQuickScanAndCKPOpts(nil)
    tae := testutil.InitTestDB(ctx, ModuleName, t, opts)

    schema := catalog.MockSchemaAll(18, 14)
    schema.Extra.BlockMaxRows = 10
    schema.Extra.ObjectMaxBlocks = 5

    bat := catalog.MockBatch(schema, int(schema.Extra.BlockMaxRows*15+1))
    defer bat.Close()
    testutil.CreateRelationAndAppend(
        t, 0, tae, testutil.DefaultTestDB, schema, bat, true,
    )
    testutil.CompactBlocks(
        t, 0, tae, testutil.DefaultTestDB, schema, true,
    )
    testutil.MergeBlocks(
        t, 0, tae, testutil.DefaultTestDB, schema, true,
    )
    time.Sleep(100 * time.Millisecond)

    assert.NoError(t, tae.Close())
    tae, err := db.Open(ctx, tae.Dir, opts)
    assert.NoError(t, err)
    defer tae.Close()

    txn, rel := testutil.GetDefaultRelation(t, tae, schema.Name)
    testutil.CheckAllColRowsByScan(t, rel, bat.Length(), false)
    assert.NoError(t, txn.Commit(context.Background()))
}

Run it in independent processes:

for i in 1 2 3; do
  go test ./pkg/vm/engine/tae/db/test \
    -run '^TestReplay7$' -count=1 -v
done

Actual behavior

All three runs failed after DB.Close() had returned nil and db.Open() had started.

Two runs reopened with an empty catalog and then reported:

Replay-Checkpoints ... "max-table-id": 0, "object-count": 0
Unknown database db

One run terminated while replaying WAL:

panic: ExpectedEOB
github.com/matrixorigin/matrixone/pkg/vm/engine/tae/txn/txnimpl.
    (*replayTxnStore).registerPreparedDMLTables

Before close, the flush/merge path also recorded ExpectedEOB. Extending the cleanup interval did not eliminate the failure: one run passed and two still failed.

Expected behavior

After a successful DB.Close(), reopening the same directory should restore the database, table, and all 151 committed rows. Replay must not terminate because a committed DML record refers to catalog state omitted by the selected checkpoint.

Impact

A successful shutdown followed by restart can leave committed data inaccessible, or prevent the database from reopening. This is a data availability and recovery correctness issue.

Activity

  1. added this to the MO-202607 milestone on Jul 28, 2026
  2. added
    kind/bug
    on Jul 28, 2026
  3. added theissue type on Jul 28, 2026
  4. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    在最新 main 上通过另一条业务负载复现了相同的恢复 panic,补充到本 issue,不再新建重复 issue。

    测试版本:0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c
    平台:macOS arm64
    拓扑:单 LOG + 单 TN + 单 CN

    触发过程:

    1. 使用全新数据目录启动 MatrixOne。
    2. 执行 Data Branch 回归集合,共 13 个 case、280 条 SQL/断言,包含:
      • 多轮 CREATE / DIFF / PICK / MERGE / CLONE / SNAPSHOT;
      • 16 层合法 branch lineage;
      • 50,000 行基表,10,000 行 UPDATE、10,000 行 DELETE、10,000 行 INSERT;
      • 跨租户 branch quota 并发创建和清理。
    3. 测试全部结束并完成对象清理后,通过 SIGINT 停止 mo-service,进程正常退出。
    4. 使用同一二进制、同一配置和同一数据目录重新启动。

    结果:连续重启验证 2/2 都在恢复阶段退出,退出码为 2,panic 签名完全一致:

    panic: ExpectedEOB
    
    github.com/matrixorigin/matrixone/pkg/vm/engine/tae/txn/txnimpl.
        (*replayTxnStore).registerPreparedDMLTables
        pkg/vm/engine/tae/txn/txnimpl/replaystore.go:117
    github.com/matrixorigin/matrixone/pkg/vm/engine/tae/txn/txnimpl.
        (*replayTxnStore).prepareCommit
        pkg/vm/engine/tae/txn/txnimpl/replaystore.go:90
    

    代码路径与本 issue 描述一致:WAL replay 的 dirty table 记录进入 registerPreparedDMLTables 后,db.GetTableEntryByID(record.ID) 返回 ExpectedEOB,当前代码直接 panic(err),导致整个服务无法启动。

    对照验证:

    • 同一二进制使用全新的空数据目录可以正常启动;
    • 因此不是二进制、端口或基础配置错误,而是已有数据目录的恢复路径触发;
    • 该数据目录是在公开 SQL Data Branch 负载后产生的,说明问题不只存在于 TestReplay7 的构造场景。

    结论:该恢复正确性问题在 main@0ebba1c0c 仍存在,而且可由 Data Branch 重负载后的重启稳定触发,建议继续保持 issue Open。

  5. jiangxinmeng1 commented on Aug 19, 2026

    @jiangxinmeng1
    Contributor

    fixed by #26415

  6. Ariznawlll commented on Aug 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:d7899e703dfaef428f272c2fc0452813c0b8636c
    • 部署方式:TAE 嵌入式 Go 测试,独立临时数据目录
    • 测试日期:2026-08-20

    原问题验证

    执行:

    GOROOT=/opt/homebrew/Cellar/go/1.26.5/libexec \
    CGO_CFLAGS='-I<worktree>/cgo -I<thirdparties>/include' \
    go test ./pkg/vm/engine/tae/db/test -run '^TestReplay7$' -count=3 -v

    TestReplay7 覆盖 151 行写入、flush、compact、merge、DB.Close()、重新 db.Open() 以及 WAL/checkpoint replay。当前 main 连续 3 轮均成功,未出现 ExpectedEOB、Unknown database、panic 或数据缺失。

    Happy Path 覆盖

    1. append 后执行 compact/merge。
    2. 成功关闭 TAE 数据库。
    3. 重新打开同一目录并完成 replay。
    4. 重新打开后全量扫描仍得到 151 行。

    Unhappy Path 覆盖

    1. 覆盖原 issue 的关闭重开恢复边界;3/3 均未再触发 replay panic 或空 catalog。
    2. 每轮测试结束后独立临时目录清理完成。

    白盒验证

    TestReplay7 是 TAE replay 专项 Go 回归,执行 3/3 通过;该内部生命周期问题不适合转成 MOTR SQL case。

    回归测试

    继续保留 pkg/vm/engine/tae/db/test/replay_test.go 中的 TestReplay7,不新增 MOTR case。

    测试证据

    Go 输出:--- PASS: TestReplay7,最终 ok github.com/matrixorigin/matrixone/pkg/vm/engine/tae/db/test 4.257s。

    测试结论

    测试通过。

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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions