Skip to content

[Bug]: DATA BRANCH DIFF loses history after branch-table mergeobjects and GC #27451

Closed

Description

@Ariznawlll

Description

DATA BRANCH DIFF loses access to branch history after the branch table is compacted with mergeobjects and storage GC advances. The base and branch tables remain fully readable, and the branch-protection snapshot row still exists, but DIFF fails with error 20405 because a referenced object file has already been removed.

Environment

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

Steps to reproduce

drop database if exists db_branch_merge_gc;
create database db_branch_merge_gc;
use db_branch_merge_gc;

create table root(id int primary key, v int, note varchar(20));

insert into root select result,result,concat('v-',result) from generate_series(1,2000) g;
select mo_ctl('dn','flush','db_branch_merge_gc.root');
insert into root select result,result,concat('v-',result) from generate_series(2001,4000) g;
select mo_ctl('dn','flush','db_branch_merge_gc.root');
insert into root select result,result,concat('v-',result) from generate_series(4001,6000) g;
select mo_ctl('dn','flush','db_branch_merge_gc.root');
insert into root select result,result,concat('v-',result) from generate_series(6001,8000) g;
select mo_ctl('dn','flush','db_branch_merge_gc.root');
insert into root select result,result,concat('v-',result) from generate_series(8001,10000) g;
select mo_ctl('dn','flush','db_branch_merge_gc.root');
insert into root select result,result,concat('v-',result) from generate_series(10001,12000) g;
select mo_ctl('dn','flush','db_branch_merge_gc.root');

data branch create table leaf from root;
update root set v=100001,note='root-update' where id=1;
delete from root where id=2;
update leaf set v=300003,note='leaf-update' where id=3;
insert into leaf values(13001,13001,'leaf-insert');

-- This initially returns the expected four-row diff.
data branch diff leaf against root;

select mo_ctl('dn','flush','db_branch_merge_gc.root');
select mo_ctl('dn','flush','db_branch_merge_gc.leaf');
select mo_ctl('cn','mergeobjects','t:db_branch_merge_gc.leaf:overlap');

-- Repeat this block. The error occurs within 2-3 cycles in the 3/3 matrix.
select mo_ctl('dn','globalcheckpoint','');
select mo_ctl('dn','diskcleaner','force_gc');
data branch diff leaf against root;

The complete assertion probe used for the matrix is DataBranchMergeGcProbe.java. It repeats the checkpoint/GC block up to six times and checks table contents, protection metadata, and connection reuse after an error.

Actual behavior

The initial diff is:

root | UPDATE | 1     | 100001 | root-update
root | DELETE | 2     | 2      | v-2
leaf | UPDATE | 3     | 300003 | leaf-update
leaf | INSERT | 13001 | 13001  | leaf-insert

After compacting leaf and advancing checkpoint/GC, DIFF fails:

HY000 / 20405: file <object-name>_00000 is not found

Final three-run evidence:

MODE_OK mode=gc_only round=1 cycles=6
MODE_OK mode=merge_only round=1 cycles=1
MODE_SQL_ERROR mode=merge_gc round=1 cycle=3 state=HY000 code=20405 message=file ... is not found
POST_ERROR_OK mode=merge_gc round=1 root=11999 leaf=12001 protect=1 connection=usable

MODE_OK mode=gc_only round=2 cycles=6
MODE_OK mode=merge_only round=2 cycles=1
MODE_SQL_ERROR mode=merge_gc round=2 cycle=2 state=HY000 code=20405 message=file ... is not found
POST_ERROR_OK mode=merge_gc round=2 root=11999 leaf=12001 protect=1 connection=usable

MODE_OK mode=gc_only round=3 cycles=6
MODE_OK mode=merge_only round=3 cycles=1
MODE_SQL_ERROR mode=merge_gc round=3 cycle=2 state=HY000 code=20405 message=file ... is not found
POST_ERROR_OK mode=merge_gc round=3 root=11999 leaf=12001 protect=1 connection=usable

Before compaction, metadata_scan shows that the zero-copy branch and its base reference the same six object names. The branch-protection row remains present when the error occurs.

Expected behavior

As long as both Data Branch tables and their protection metadata are live, object compaction and GC must not remove history needed by DATA BRANCH DIFF. The four-row diff should remain stable for every checkpoint/GC cycle.

Stability and controls

  • Reproducer: 3/3; failure occurred on GC cycle 3, 2, and 2.
  • Control 1 (gc_only, no mergeobjects): 3/3 passed, six GC cycles each.
  • Control 2 (merge_only, no GC): 3/3 passed.
  • Source-only compaction: did not reproduce; compacting the branch table is the necessary compaction path in the minimized case.
  • Failure integrity: after every error, root contained 11999 rows, leaf contained 12001 rows, the branch-protection row count was 1, and the same connection remained usable.
  • Cleanup: every generated database was dropped in finally.

Evidence

  • Full local probe output: merge-gc-evidence.txt
  • Minimal assertion probe: DataBranchMergeGcProbe.java
  • Existing BVT gap: test/distributed/cases/git4data/branch/diff/diff_9.sql covers flush/checkpoint/GC but does not compact the branch table before GC.

Code analysis

Confirmed path:

  • Branch protection is registered as a table-level snapshot at the clone timestamp in pkg/frontend/data_branch_snapshot.go.
  • Snapshot timestamps are distributed to table retention lists in pkg/vm/engine/tae/logtail/snapshot.go:1933-2054.
  • GC decides whether a dropped object is retained through ObjectIsSnapshotRefers in pkg/vm/engine/tae/db/gc/v3/exec_v1.go:398-467 and pkg/vm/engine/tae/logtail/snapshot.go:2257-2300.

Hypothesis: the branch table initially reuses the base object's physical names, but the branch-side object entries have branch-side lifecycle timestamps. When branch-side compaction replaces those entries, GC evaluates at least one reference as unprotected and removes the shared old file even though the live branch-protection snapshot still needs it. The exact deletion decision should be confirmed in the GC object-reference map.

Regression coverage

Extend test/distributed/cases/git4data/branch/diff/diff_9.sql (or add a focused case under the same suite) with:

  1. multiple flushed source objects;
  2. a Data Branch table with source-side and branch-side changes;
  3. mergeobjects on the branch table;
  4. repeated checkpoint/GC cycles;
  5. exact DIFF rows plus source/branch row-count assertions.

Related

Searches across open/closed issues and PRs for DATA BRANCH DIFF, mergeobjects, branch protect snapshot, GC, and the exact file-not-found behavior found no matching report.

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 21, 2026
  5. gouhongshen commented on Aug 21, 2026

    @gouhongshen
    Contributor

    PR #27464 is trying to fix this issue.

  6. gouhongshen commented on Aug 22, 2026

    @gouhongshen
    Contributor

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

  7. added and removed
    severity/s0
    on Aug 25, 2026
  8. Ariznawlll commented on Aug 25, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:`main`
    • commit:`ae12701a888fac102e9641cc7cbb8706527366d8`
    • 部署方式:本地 1CN/1TN/1Log,Git4Data 数据分支场景
    • 测试日期:2026-08-25

    原问题验证

    在分支表产生历史差异后执行 `mergeobjects`,再连续执行 3 个 global checkpoint/GC 周期。连续 3 个独立轮次中,历史 DIFF 均未丢失:DIFF 仍为 4 项,根表/分支表行数为 `11999/12001`,snapshot 数为 `1`。

    Happy Path 覆盖

    1. `mergeobjects` 后历史 DIFF 能正确列出预期的插入、删除与更新差异。
    2. GC 后根表和分支表的行数保持正确,快照仍可读取。

    Unhappy Path 覆盖

    1. 连续 3 轮 checkpoint/GC 后均未出现 DIFF 归零、历史行丢失或读取错误。

    白盒验证

    不适用;该问题的风险是 mergeobjects/GC 后可查询历史是否保持,已由端到端数据分支场景直接验证。

    回归测试

    已有 MatrixOne BVT:diff_9.sql。该行为依赖历史链路而非数据规模,不需要大数据量测试。

    测试证据

    • 修复 commit `b017f59` 已包含在本次 tested main 中。
    • latest main 的 mergeobjects + 3 次 checkpoint/GC 场景 `3/3` 通过。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions