Skip to content

[Bug]: mo-dump hangs forever in adjustViewOrder when a view's DDL text false-matches another view's name (substring dependency graph has no fake-cycle guard) — truncated backup still replays DROP DATABASE #64

Closed

Description

@Ariznawlll

Bug or Feature Request

Bug

Description

mo-dump hangs forever (0 bytes of table output after the USE db; line, 100% CPU busy-wait) when a database contains any view whose SHOW CREATE VIEW text false-matches another view's name via the tool's naive substring dependency analysis. Two independent false-positive shapes reproduce it 100%:

  1. View-name vs derived-column alias collision – the topological sort builds the dependency graph with

    if strings.Count(createTable[i], tables[j].Name) > 0 {  // plain substring!
        viewCount[viewPos[tables[i].Name]]++
    }

    so any occurrence of another view's name in the DDL text (derived-column alias, string literal, comment, etc.) is counted as a real dependency and can synthesize a fake cycle. The subsequent loop

    for order < len(viewName) {   // no cycle guard!
        for i := 0; i < len(viewName); i++ {
            if viewCount[i] == 0 && !visit[i] { ... }
        }
    }

    has no cycle detection or max-iteration guard, so a fake cycle makes mo-dump spin forever inside adjustViewOrder — confirmed by sample(1): the whole process sitz at main.adjustViewOrder (1006+ ms CPU inside one goroutine while all others idle).

  2. String-literal collision – two views whose DDL text mutually contains the other view's name (e.g. a status-filter literal equal to another view's name) also manufactures a fake cycle.

Wrong-ordering risk also exists (false positive without a cycle), but the silent hang is the attacker-visible failure: any mo-dump <db> invocation never returns, producing a truncated dump whose only contents are SET foreign_key_checks=0; DROP DATABASE IF EXISTS; CREATE DATABASE; USE db; — replaying which drops the source database's data on the restore side. This is the same "silent bad backup" blast radius as #30577 / mo-dump residue issues.

Steps to Reproduce

Instance: MO v3.x (b24d1b3), macOS arm64. mo-dump at mo_dump@324c33d (origin/main HEAD).

Repro 1 — view name collides with derived-column alias in another view (real cycle is v2 → v1; fake cycle adds v1 → v2)

CREATE DATABASE vn;
CREATE TABLE vn.t (id INT PRIMARY KEY, v INT);
CREATE VIEW vn.v1 AS SELECT v*2 AS v2 FROM vn.t;          -- DDL text contains "v2"
CREATE VIEW vn.v2 AS SELECT COUNT(*) AS total FROM vn.v1; -- real dependency v2 → v1
$ ./mo-dump -h 127.0.0.1 -P 16001 -u root -p *** -db vn
# hangs forever; output file contains only:
#   SET foreign_key_checks = 0;
#   DROP DATABASE IF EXISTS `vn`;
#   CREATE DATABASE `vn` ;
#   USE `vn`;
#   (nothing more; process must be SIGKILLed)
  • strings.Count(createTable[v1], "v2") matches the AS v2 alias → spurious edge v1 → v2.
  • Real edge v2 → v1 + spurious v1 → v2 = fake cycle → topological loop never terminates.

Repro 2 — no aliases involved, string literal equals the other view name

CREATE DATABASE vt;
CREATE TABLE vt.t (id INT PRIMARY KEY, status VARCHAR(10));
CREATE VIEW vt.active_users  AS SELECT id FROM vt.t WHERE status = 'pending_queue';
CREATE VIEW vt.pending_queue AS SELECT id FROM vt.t WHERE status = 'active_users';

No real dependency between the two views, but each DDL text contains the other view's name inside a string literal → cycle fabricated by substring matching → same infinite hang.

Expected

Both dumps should complete in milliseconds (verified under control experiments below).

Controls (all pass; only the above two families fail)

Database layout Result
Table + single view (any expression) OK
Table + two independent views OK
View chain with SELECT * passthrough (v2 → count(*) FROM v1, v1 = SELECT * FROM t) OK (no name collision in text)
Two views, string literal contains other name in only one direction OK (only one fake edge, no cycle)
Complex 5-object DB (mixing repro #1 chain with an independent JOIN view) HANG at repro-1 pair

sample(1) of the hung process:

4 main.main
  4 main.(*Options).dumpData
    4 main.adjustViewOrder     <-- 100 % of wall time, never returns

Suggested fix

  1. Replace the substring heuristic in adjustViewOrder (cmd/mo-dump/main.go ~line 357-365) with a parser-based or tokenized identifier match — at minimum wrap tokens with backticks / word boundaries so 'pending_queue', AS v2, comments etc. cannot count as table references. Alternatively query information_schema.views / MO's mo_catalog.mo_columns-driven relation graph for actual view dependencies.
  2. Independently, harden the topological loop with cycle detection (visited count in one pass unchanged after a full iteration → bail out with a clear error like cyclic view dependencies) so a future parser regression can never hang the whole backup.

Versions

  • mo-dump: github.com/matrixorigin/mo_dump@324c33d (HEAD of main at 2026-10-20)
  • MatrixOne: matrixorigin/matrixone built at commit b24d1b3 (2026-10-16), v3.x dev
  • OS: macOS 14.5 arm64

Additional context

  • Impact radius: any user DB containing views either with derived-column aliases sharing a name with another view, or string literals matching another view's name — both common in reporting / ETL-style schemas.
  • Workaround: rename the colliding alias / literal (often impractical), or drop the second view before dumping.
  • Downstream blast: like other "silent bad dump" issues, the truncated output is still a valid-looking SQL file that drops the target DB when replayed — data-loss multiplier on restore.

Activity

  1. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    Author

    Closing here — moving this issue to the main repo (matrixorigin/matrixone) for unified triage/tracking, since mo-dump is shipped and tested as part of the MatrixOne release toolchain. The main-repo issue will link back here. /cc @matrix-meow

  2. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    Author

    Moved to the main repo for unified triage: matrixorigin/matrixone#30672 (assignee @matrix-meow, milestone MO-202610). Closing this one; further discussion happens on the main-repo issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions