Repository navigation
Description
Describe the bug
When DATA BRANCH CREATE TABLE reads a named snapshot after the source table has been dropped and recreated with the same name, the new branch contains the correct historical data but its ancestry metadata points to the current same-name table rather than the table object stored in the snapshot.
The matching branch-protection snapshot also records the current table ID with a timestamp that predates that table's creation. Subsequent DATA BRANCH DIFF operations fail because the ancestry resolver looks for the current table ID at the historical timestamp.
Tested at commit 2eb7f523e5a10f352d3e258183ed8440510388de.
Steps to reproduce
drop snapshot if exists g4d_parent_identity_sp;
drop database if exists g4d_parent_identity;
create database g4d_parent_identity;
use g4d_parent_identity;
create table parent_t (
id int primary key,
val varchar(20)
);
insert into parent_t values (1, 'snapshot-row');
create snapshot g4d_parent_identity_sp
for table g4d_parent_identity parent_t;
set @snapshot_parent_id = (
select rel_id
from mo_catalog.mo_tables {snapshot='g4d_parent_identity_sp'}
where account_id = 0
and reldatabase = 'g4d_parent_identity'
and relname = 'parent_t'
);
drop table parent_t;
create table parent_t (
id int primary key,
val varchar(20)
);
insert into parent_t values (2, 'current-row');
set @current_parent_id = (
select rel_id
from mo_catalog.mo_tables
where account_id = 0
and reldatabase = 'g4d_parent_identity'
and relname = 'parent_t'
);
data branch create table child_t
from parent_t{snapshot='g4d_parent_identity_sp'};
select * from child_t;
select bm.table_id, bm.p_table_id, bm.clone_ts
from mo_catalog.mo_branch_metadata bm
join mo_catalog.mo_tables mt on mt.rel_id = bm.table_id
where mt.reldatabase = 'g4d_parent_identity'
and mt.relname = 'child_t';
select sname, obj_id, ts
from mo_catalog.mo_snapshots
where kind = 'branch'
and database_name = 'g4d_parent_identity'
and table_name = 'parent_t';
data branch diff child_t against parent_t;Actual behavior
The historical and current table IDs are different:
snapshot parent ID = 287580
current parent ID = 287581
The branch data is correctly copied from the snapshot:
1 snapshot-row
However, both records use the current table ID:
mo_branch_metadata.p_table_id = 287581
mo_snapshots.obj_id = 287581
DATA BRANCH DIFF then returns:
internal error: cannot find table 287581 commit ts at snapshot ...
The same result was reproduced with three independently created child tables.
The database-level form was also reproduced independently:
data branch create database g4d_parent_db_dst
from g4d_parent_db_src{snapshot='g4d_parent_db_identity_sp'};
data branch diff g4d_parent_db_dst.parent_t
against g4d_parent_db_src.parent_t;For three destination databases, the snapshot table ID was 287586, the
current same-name table ID was 287587, and every destination branch recorded
p_table_id = 287587. Each database-level DATA BRANCH DIFF then failed
because table 287587 did not exist at the snapshot timestamp.
Expected behavior
The branch ancestry and protection metadata should refer to the source table object that actually exists in the named snapshot (287580 in the example). Operations on the historical branch should not resolve its parent by the current table name.
Code context
handleCloneTable correctly passes the snapshot to the clone operation, but its cloneReceipt stores only the source database and table names. updateBranchMetaTable later calls:
tcc.Resolve(receipt.srcDb, receipt.srcTbl, nil)without the receipt snapshot. It therefore resolves the current same-name relation and stores its ID in both mo_branch_metadata and the branch-protection snapshot.
The database-level path uses the same receipt/update flow and was confirmed to
record the same incorrect parent identity after same-name table recreation.
Activity
VioletQwQ-0 commentedon Jul 29, 2026
PR #26310 merged as
ccfcea46981aba349b4fa11445202939f1045c53(reviewed head3eb675911c59623dd98a77871bbd0118a98a7206). Required CI and snapshot-aware identity regressions passed.QA handoff on main
f6dab28046d70412cec132f0068840896852101c:Pass: copied rows and parent identity come from the snapshot generation, metadata points to that generation, and DIFF succeeds. Fail: rebinding to the recreated table, wrong metadata, leaked protection, or DIFF failure.
Ariznawlll commentedon Jul 29, 2026
已在最新
main分支完成验证。测试版本:
52ea9f874f492c368a20efef16b46ab8ced2de37测试拓扑:Proxy + 2 CN
重复次数:3 轮
测试过程:
测试结果:
结论:该问题在上述最新 main commit 上验证通过。
Ariznawlll commentedon Jul 30, 2026
已在
main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c补充完成黑盒和白盒验证。黑盒验证:
mo_branch_metadata.p_table_id和 protection snapshotobj_id均等于 snapshot 内历史 relation ID,并与当前 relation ID 不同。结果:该 case
42/42条 SQL/断言通过;本轮 Data Branch 全集13/13case、280/280条 SQL/断言通过。白盒验证:
Unhappy path / 历史对象边界:
p_table_id和 protectionobj_id必须等于历史 ID 且不等于当前 ID。cannot find table ... at snapshot。结论:表级和数据库级 snapshot ancestry 均指向正确的历史对象,后续 DIFF 可用;黑盒回归已加入 motr#69。
Ariznawlll commentedon Jul 30, 2026
Unhappy Path / 历史对象专项验证
测试版本:
main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c该专项刻意制造“对象名称相同、relation generation 不同”:
p_table_id和 protection snapshotobj_id必须等于历史 ID,且不等于当前 ID。cannot find table ... at snapshot。结果:表级和数据库级 ancestry 均绑定历史对象;同名当前对象没有被误引用;后续 DIFF 正常。专项用例
42/42条 SQL/断言通过,对应 Go 集成测试返回ok。