Repository navigation
Description
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, nomergeobjects): 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,
rootcontained 11999 rows,leafcontained 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.sqlcovers 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
ObjectIsSnapshotRefersinpkg/vm/engine/tae/db/gc/v3/exec_v1.go:398-467andpkg/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:
- multiple flushed source objects;
- a Data Branch table with source-side and branch-side changes;
mergeobjectson the branch table;- repeated checkpoint/GC cycles;
- exact
DIFFrows plus source/branch row-count assertions.
Related
- [Feature Request]: Enhance data branch diff with fallback, delta output, and summary statistics #23751 — Data Branch DIFF feature tracking
- fix: data branch diff returns wrong results after GC+restart #24010 — earlier GC/restart DIFF correctness fix
- feat(data-branch): Branch Protect Snapshot to guard LCA history from GC #24313 — Branch Protect Snapshot implementation
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
gouhongshen commentedon Aug 21, 2026
PR #27464 is trying to fix this issue.
fix: keep data branch diff after branch compaction and GC (#27464)
gouhongshen commentedon Aug 22, 2026
PR #27464 has merged and is awaiting manual validation. The issue remains open.
Ariznawlll commentedon Aug 25, 2026
测试版本
原问题验证
在分支表产生历史差异后执行 `mergeobjects`,再连续执行 3 个 global checkpoint/GC 周期。连续 3 个独立轮次中,历史 DIFF 均未丢失:DIFF 仍为 4 项,根表/分支表行数为 `11999/12001`,snapshot 数为 `1`。
Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
不适用;该问题的风险是 mergeobjects/GC 后可查询历史是否保持,已由端到端数据分支场景直接验证。
回归测试
已有 MatrixOne BVT:diff_9.sql。该行为依赖历史链路而非数据规模,不需要大数据量测试。
测试证据
测试结论
测试通过。
fix: keep data branch diff after branch compaction and GC (matrixorig…
fix: keep data branch diff after branch compaction and GC (matrixorig…
fix: keep data branch diff after branch compaction and GC (matrixorig…