Skip to content

[Bug]: CREATE DATABASE ... CLONE accepts a nonexistent source and creates an empty target #27041

Closed

Description

@Ariznawlll

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';
-- 1

Actual 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/3 with 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:

  1. a nonexistent current-state source: reject and leave no destination;
  2. a real empty source: succeed with an empty destination;
  3. a populated source: succeed with exact schema and rows;
  4. 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

  1. added this to the MO-202608 milestone on Aug 12, 2026
  2. added
    kind/bug
    on Aug 12, 2026
  3. added theissue type on Aug 12, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Aug 12, 2026
  5. added a commit that references this issue on Aug 14, 2026
    c172424
  6. gouhongshen commented on Aug 14, 2026

    @gouhongshen
    Contributor

    fixed by #27058

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

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    origin/main@263567cf1a56da904788bc6d1d613ff19cb44783(2026-08-14)。

    原问题验证

    源数据库不存在时,普通 CLONE 和 IF NOT EXISTS CLONE 均返回 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。

    测试结论

    测试通过。

  9. added 3 commits that reference this issue on Sep 17, 2026
    18dbebb
    ad7bbb1
    fa5d2a0
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