Repository navigation
Description
Description
CREATE DATABASE dst CLONE missing_src succeeds even when the source database has never existed. MatrixOne silently creates an empty destination database, making a missing source indistinguishable from a legitimate empty source.
Environment
- Branch:
main - Commit:
2d9ee9c75398b5492f14db7d9bd4d9f777251bd3 - Test date:
2026-08-12 - Deployment: local single process, 1 Log Service + 1 TN + 1 CN
Steps to reproduce
DROP DATABASE IF EXISTS clone_missing_src;
DROP DATABASE IF EXISTS clone_missing_dst;
SELECT COUNT(*)
FROM mo_catalog.mo_database
WHERE datname = 'clone_missing_src';
-- 0
CREATE DATABASE clone_missing_dst CLONE clone_missing_src;
SELECT COUNT(*)
FROM mo_catalog.mo_database
WHERE datname = 'clone_missing_dst';
-- 1Actual behavior
The CLONE statement returns Query OK. An empty clone_missing_dst database is committed even though the source catalog count is zero.
Three independent attempts produced:
missing-source-count 0
created-target-count 3
Expected behavior
The statement must reject the missing source database and must not create any destination catalog or object state.
Stability and controls
- Reproducer:
3/3with independent missing source and target names; all returned success and created an empty target. - Empty-source control: cloning a real, empty source database returned success and created one empty target database.
- Table-level control: cloning a missing source table returned
ERROR 1064: table ... does not exist; the target table catalog count remained zero. - No source database was present before or after the three attempts.
Evidence
CREATE DATABASE clone_missing_dst_r1 CLONE clone_missing_src_r1; -- Query OK
CREATE DATABASE clone_missing_dst_r2 CLONE clone_missing_src_r2; -- Query OK
CREATE DATABASE clone_missing_dst_r3 CLONE clone_missing_src_r3; -- Query OK
missing-source-count 0
created-target-count 3
Local reproducer:
/private/tmp/mo-clone-2d9-validation/reproduce-missing-db.sql
Code analysis
pkg/frontend/clone_database_source.go:89-103 collects table and foreign-key metadata for the source name, but an empty result represents both a valid empty database and a nonexistent database. This path does not first verify that the source database exists.
After the empty metadata set is accepted, pkg/frontend/clone.go:917-922 unconditionally creates the destination database. With no objects to clone, the operation commits as a successful empty clone.
Regression coverage
Add a distributed database CLONE BVT with separate assertions for:
- a nonexistent current-state source: reject and leave no destination;
- a real empty source: succeed with an empty destination;
- a populated source: succeed with exact schema and rows;
- a missing table source: continue to reject without residue.
Related
No matching open or closed issue was found using exact searches for nonexistent database clone, source database does not exist, and missing CLONE sources. #22363 is a historical failure while cloning objects from existing databases and is not a duplicate.
Activity
fix: validate database clone existence (#27058)
gouhongshen commentedon Aug 14, 2026
fixed by #27058
Ariznawlll commentedon Aug 14, 2026
测试版本
origin/main@263567cf1a56da904788bc6d1d613ff19cb44783(2026-08-14)。
原问题验证
源数据库不存在时,普通 CLONE 和
IF NOT EXISTSCLONE 均返回Unknown database,且不会生成目标数据库。Happy Path 覆盖
空源数据库存在时,普通数据库 CLONE 可正常创建目标库,目录查询结果为 1。
Unhappy Path 覆盖
普通和
IF NOT EXISTS两种缺失源库 CLONE 均返回预期 1049;两种目标库在mo_catalog.mo_database中的计数均为 0。白盒验证
执行现有 Git4Data clone BVT 用例
test/distributed/cases/git4data/clone/clone_database_existence.sql,覆盖缺失源库拒绝与无目标残留。回归测试
已加入 motr#111 的 issue_27039_27040_27041_clone_if_not_exists.test,
./motr --branch main --repeat 3 -v 12_git4data.issue_27039_27040_27041_clone_if_not_exists连续 3 次通过(138/138 statements)。测试证据
MOTR 结果基线记录了两类缺失源库错误、目录无残留及空源库正常 clone;对应提交为
37ea270d。测试结论
测试通过。
fix: validate database clone existence (matrixorigin#27058)
fix: validate database clone existence (matrixorigin#27058)
fix: validate database clone existence (matrixorigin#27058)