You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DATA BRANCH CREATE DATABASE rejects a valid database whose foreign-key graph contains a cycle. The source schema and data are valid and usable, but branch creation stops with:
ERROR 20101 (HY000): internal error: There is a cycle in dependency graph
The target database is not created.
Reproduction
DROPDATABASE IF EXISTS g4d_fk_cycle_src;
DROPDATABASE IF EXISTS g4d_fk_cycle_dst;
CREATEDATABASEg4d_fk_cycle_src;
CREATETABLEg4d_fk_cycle_src.a(
id INTPRIMARY KEY,
b_id INT
);
CREATETABLEg4d_fk_cycle_src.b(
id INTPRIMARY KEY,
a_id INT,
CONSTRAINT fk_b_a
FOREIGN KEY(a_id) REFERENCESg4d_fk_cycle_src.a(id)
);
ALTERTABLEg4d_fk_cycle_src.a
ADD CONSTRAINT fk_a_b
FOREIGN KEY(b_id) REFERENCESg4d_fk_cycle_src.b(id);
INSERT INTOg4d_fk_cycle_src.aVALUES (1, NULL);
INSERT INTOg4d_fk_cycle_src.bVALUES (1, 1);
UPDATEg4d_fk_cycle_src.aSET b_id =1WHERE id =1;
SELECT*FROMg4d_fk_cycle_src.a;
SELECT*FROMg4d_fk_cycle_src.b;
DATA BRANCH CREATE DATABASE g4d_fk_cycle_dst
FROM g4d_fk_cycle_src;
Actual result
The source tables contain valid mutually referencing rows, but database branch creation fails:
ERROR 20101 (HY000): internal error: There is a cycle in dependency graph
The failure is atomic, but the valid database cannot be branched.
Expected result
Database branch creation should support a valid cyclic foreign-key graph, for example by separating table creation from foreign-key restoration, or otherwise restoring the constraints after all referenced tables exist.
Reproducibility
Reproduced 3/3 times with separate source and destination database names.
Code observation
collectCloneDatabaseSource calls fkTablesTopoSort. The current topological sorter returns an error whenever the foreign-key graph contains a cycle, so DATA BRANCH CREATE DATABASE exits before cloning any object.
Merged fix: #26292, merge commit 52ea9f874f492c368a20efef16b46ab8ced2de37 (final PR head 622e09571687fb7d06f59f9acad1d3db4f7140af).
Current main at handoff: 41332062a6740978f269088a92ee362a888c7bd7.
QA Decision
required: yes
reason: the change affects Data Branch creation, persisted cyclic-FK metadata, cross-account behavior, and session-state restoration
production_entrypoint: DATA BRANCH CREATE DATABASE from live and named-snapshot sources containing a valid mutual-FK cycle
automated_terminal_coverage: the merged embedded regression covers live/snapshot and same-account/cross-account cases, destination-local FK IDs and enforcement, repeated-target failure behavior, and restoration of foreign_key_checks
remaining_validation: execute those paths in a deployed environment, including a failed/repeated branch attempt followed by ordinary FK-protected DML in the same session
PASS requires successful branch creation and copied rows, destination-local FK metadata, invalid writes rejected, and foreign_key_checks restored after both success and failure without altering a pre-existing target. FAIL includes clone rejection, source-object IDs in target metadata, disabled constraints, session-state leakage, or target mutation after a failed statement.
Please record the tested build/commit, environment, source mode, account context, and terminal results. Keep this issue open until explicit QA PASS evidence is posted.
Activity
fix: support cyclic foreign keys in database branch (#26292)
VioletQwQ-0 commentedon Jul 30, 2026
QA handoff
Merged fix: #26292, merge commit
52ea9f874f492c368a20efef16b46ab8ced2de37(final PR head622e09571687fb7d06f59f9acad1d3db4f7140af).Current
mainat handoff:41332062a6740978f269088a92ee362a888c7bd7.QA Decision
foreign_key_checksPASS requires successful branch creation and copied rows, destination-local FK metadata, invalid writes rejected, and
foreign_key_checksrestored after both success and failure without altering a pre-existing target. FAIL includes clone rejection, source-object IDs in target metadata, disabled constraints, session-state leakage, or target mutation after a failed statement.Please record the tested build/commit, environment, source mode, account context, and terminal results. Keep this issue open until explicit QA PASS evidence is posted.
Ariznawlll commentedon Aug 1, 2026
测试版本
main15a2d07c687a62a0984cf62846b092912a28c0f1原问题验证
构造 A→B、B→A 的循环 FK,写入闭环数据后分别从实时库和命名 snapshot 创建数据库 Data Branch。连续 3 轮均成功;两个目标库连接查询均得到 1 行,且 target-local FK 元数据各为 2 条。
Happy Path 覆盖
snapshot='<name>'两种建库路径。foreign_key_checks会话值均保持正确。Unhappy Path 覆盖
foreign_key_checks完全一致。白盒验证
回归测试
测试证据
PASS 26111_cyclic_foreign_keys_live_snapshot_failure_atomicity。测试结论
测试通过。
Ariznawlll commentedon Aug 1, 2026
测试版本
main15a2d07c687a62a0984cf62846b092912a28c0f1原问题验证
构造相互引用的合法循环外键 schema:表
a通过b_id引用b,表b通过a_id引用a。写入相互关联的合法行后执行DATA BRANCH CREATE DATABASE motr_cycle_dst FROM motr_cycle_src,验证目标库中的环形外键和数据。本次新增黑盒回归连续执行 3 轮,每轮 47 条语句/断言,3/3 均成功;与 #26113、#26070 共用的回归用例总计 141 条语句/断言成功。
Happy Path 覆盖
a、b,得到(a.id=1, a.b_id=1, b.a_id=1),确认两张表的数据和相互引用均被正确保留。ALTER TABLE ... ADD CONSTRAINT的约束建立方式,覆盖非一次性建表的正常 schema。Unhappy Path 覆盖
b插入指向不存在a.id=999的行,稳定返回外键错误20101/1452。b的记录数保持为 1,非法写入没有部分落库,验证复制后的环形外键仍有效且拒绝原子。白盒验证
未增加独立故障注入。循环依赖解析与约束恢复都可通过公开的
DATA BRANCH CREATE DATABASE、查询和非法写入验证,因此以端到端黑盒契约为准。回归测试
已加入 motr 黑盒回归:PR #74,测试文件:issue_26113_26111_26070_branch_integrity.test。
测试证据
执行命令:
./motr --config /tmp/motr-git4data-fulltext-blackbox-config.yml --repeat 3 --do-test 'issue_(26144|26113)' -v。其中本用例 3 轮均为success,共141/141条语句/断言成功;对应回归提交:8f0f759。测试结论
测试通过。
test: isolate cyclic foreign key regression (#27647)
test: remove redundant data branch teardown (#28099)
test: consolidate compatible branch integration fixtures (#28750)
fix: support cyclic foreign keys in database branch (matrixorigin#26292)
test: isolate cyclic foreign key regression (matrixorigin#27647)
test: remove redundant data branch teardown (matrixorigin#28099)
test: consolidate compatible branch integration fixtures (matrixorigi…
fix: support cyclic foreign keys in database branch (matrixorigin#26292)
test: isolate cyclic foreign key regression (matrixorigin#27647)
test: remove redundant data branch teardown (matrixorigin#28099)
test: consolidate compatible branch integration fixtures (matrixorigi…
fix: support cyclic foreign keys in database branch (matrixorigin#26292)
test: isolate cyclic foreign key regression (matrixorigin#27647)
test: remove redundant data branch teardown (matrixorigin#28099)
test: consolidate compatible branch integration fixtures (matrixorigi…