Skip to content

[Bug]: mo-dump multi-database export can place cross-database views before their source tables #30572

Closed
matrixorigin/mo_dump
#53

Description

@Ariznawlll

问题

mo-dump 文档支持用 -db A,B 导出多个数据库;若 A 中的视图引用 B 中的表,按 A,B 顺序生成的脚本会先创建视图,再创建 B 库。导出以 MODUMP SUCCESS 结束,但在空目标上恢复时于 CREATE VIEW 报错,留下部分恢复的 A 库。只需调换 -db 参数顺序为 B,A,相同数据即可完整恢复。

环境

  • MatrixOne main:75ff736835c3d00d40dc00a0a1d3b11129388e5b;隔离单实例 LOG/TN/CN,@@version=8.0.30-MatrixOne-v1.3.0。
  • mo-dump main:324c33dbdc7075cd5d7beaafd1e15c76709dd442。

最小复现

CREATE DATABASE view_db;
CREATE DATABASE data_db;
CREATE TABLE data_db.t (id INT PRIMARY KEY, v DECIMAL(10,2));
INSERT INTO data_db.t VALUES (1,1.25),(2,2.50);
CREATE VIEW view_db.v AS SELECT id,v FROM data_db.t WHERE v > 1;
SELECT COUNT(*),SUM(v) FROM view_db.v; -- 2, 3.75
mo-dump ... -db view_db,data_db > dump.sql

在空目标恢复(本地复现先移除这两个临时数据库,再导入 dump.sql):

ERROR 1049 (42000) at line 9: Unknown database data_db

生成脚本的关键顺序是:CREATE DATABASE view_db → CREATE VIEW view_db.v AS ... FROM data_db.t → CREATE DATABASE data_db → CREATE TABLE data_db.t。源文件末尾仍有 MODUMP SUCCESS。恢复失败后 view_db 已创建但无视图,data_db 尚未创建;连接仍可正常执行查询。该 SQL 文件不能完成空目标恢复。

使用不同名称的三套独立数据库重复上述流程,3/3 同样在视图定义处报缺少被引用数据库。正常对照 mo-dump ... -db data_db,view_db 在空目标恢复成功,基表和视图均返回 2 行、SUM(v)=3.75。因此不是跨库视图本身不受支持,也不是测试数据问题。

定位

cmd/mo-dump/main.go 的 dumpData 逐个按 opt.dbs 输入顺序输出库对象;adjustViewOrder 只处理当前数据库内的视图顺序,没有跨库对象的依赖排序或延后创建机制。README 明确支持 -db 后用逗号指定多个数据库,但未将跨库依赖列为已知限制。

相关但不同:matrixone#30555 是无依赖的同库视图名称互含导致导出挂起;本问题是正常导出后的跨库恢复顺序错误。已查主库及 mo_dump 的 open/closed issue、相关 PR 和兼容性合同,未发现同一问题。

Activity

  1. added this to the MO-202610 milestone on Oct 19, 2026
  2. added
    kind/bug
    on Oct 19, 2026
  3. added theissue type on Oct 19, 2026
  4. added
    severity/s0
    and removed on Oct 19, 2026
  5. assigned and unassigned on Oct 23, 2026
  6. slyunnn commented on Oct 26, 2026

    @slyunnn

    Regression and extended verification for #30572 (2026-10-26)

    Verification Environment

    • MatrixOne main: b466f4ae9b74813a4ff93eaf43a6c81e6cbb8b0b — fix: acknowledge ISCP drain before executor runtime starts (#31167). The running binary was rebuilt and restarted; git_version() returned b466f4a at all 3 SQL endpoints.
    • mo-dump main: d9d6375512620f12ff371b8602cc1d10d6f6caa0, locally rebuilt. Associated fix: mo_dump PR #53, merge commit f33f68e554e2d8fb41c8746414e4b12bdc3c1e33, including 3bb8076a01668c710afc0a314d8f1177ed439586 (fix: restore cross-database views after their dependencies).
    • Topology: 2 CN / 1 TN / 1 Log service / Proxy. Setup, export, native mysql 9.7.1 restore, and query assertions ran separately over MySQL text-protocol routes Proxy 6001, CN1 16001, and CN2 16002.

    What Was Covered

    • OK — Original adverse argument order, -db view_db,data_db: a view in the first database referenced a table in the second. The dump put CREATE TABLE before CREATE VIEW; native-client restore exited 0 on all 3 routes.
    • OK — The restored source table retained (1,1.25) and (2,2.50); the restored view returned COUNT(*)=2 and SUM(v)=3.75 on each route.
    • OK — Boundary dependency chain across 3 databases, exported in reverse order (top,mid,data): the table and both views restored successfully, and both view queries returned 2 / 3.75 at all endpoints.
    • OK — Normal-order control (data,view) also restored with matching table and view results. Every export exited 0 and included MODUMP SUCCESS.
    • Not covered — A live genuinely cyclic view graph (the server does not ordinarily permit creating this fixture), concurrent DDL during export, and a missing/non-selected source database. The owning tool's view-order tests cover bounded cycle errors; this run does not claim a cross-database snapshot guarantee.

    Findings

    The previously failing reverse-order export is now restorable on an empty target. The direct, chained, and normal-order scenarios passed 9/9 endpoint/scenario combinations. No partial restore or client error occurred in these controlled fixtures. These were native MySQL-client script replays, not a whole-file packet sent through a driver.

    Large-data regression required: No. The defect is dependency ordering between database objects, not row volume or batch/spill behavior. A base table with 2 rows and a 3-database chain crosses the relevant graph boundary without arbitrary data-scale cost.

    MOTR / BVT Coverage

    The owning mo-dump repository contains direct cross-database ordering tests, and the full go test -count=1 ./... suite passed on this tool revision. The live 9/9 export/restore checks are additional command-level evidence. No duplicate SQL-only MOTR case, issue commit, or weekly PR change was made; the critical behavior is emitted dump order plus tool/client execution.

    Final Conclusion

    Fixed for #30572 on the tested MatrixOne and mo-dump revisions. This conclusion concerns the supplied dependency-ordering scenario and does not assert atomic restore or concurrent-DDL consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions