Skip to content

[Bug]: mo-dump SQL backups must be restorable, consistent, and preserve exact values #30673

Open

Description

@Ariznawlll

Consolidated scope: SQL backup consistency and temporal fidelity

A successful SQL-mode mo-dump export must replay through a supported client into a consistent database state with schema and values preserved. The reports below cover two independent failure modes in addition to the existing literal, geometry, and generated-column cases: reading different tables from different committed snapshots during one export, and reinterpreting TIMESTAMP text under a different restore-session time zone. These remain separate regression paths under one end-to-end backup/restore contract.

Additional acceptance criteria

  • During concurrent atomic updates across tables, one SQL dump represents a single committed snapshot; a restored database must not contain a cross-table state that never existed in the source.
  • A dump restored under a different session/system time zone preserves each TIMESTAMP instant (for example, identical UNIX_TIMESTAMP), while DATETIME remains unchanged.
  • If a schema or value cannot be represented/restored in the selected mode, export fails clearly before claiming success rather than emitting a partially applicable backup.

Additional reports

  • #30558 — concurrent commits between per-table reads produce a successfully restored but cross-table inconsistent database.
  • #30564 — cross-time-zone restore shifts TIMESTAMP values by eight hours while export and import both report success.

Additional consolidated scope

SQL dumps must emit row INSERTs accepted by the restore engine for the table schema. The generated-column report fails because the exporter includes computed values as ordinary INSERT values; it is a distinct trigger from byte escaping and GEOMETRY serialization, but exercises the same mo-dump SQL row-emission and restore contract.

Additional acceptance criteria

  • For STORED and VIRTUAL generated columns, emit INSERT column lists containing only writable columns and let MatrixOne recompute generated values during restore.
  • Restore the exported table on the same MatrixOne version and verify base and generated values exactly; MODUMP SUCCESS must not accompany an unreplayable INSERT.
  • Keep binary/control-byte, GEOMETRY WKB/SRID, and generated-column reproductions as separate regression cases.

Additional reports

  • #30682 — original report and discussion remain on that issue.

Additional consolidated scope

The SQL exporter must safely escape byte-string literals and emit type-correct SQL for binary-backed GEOMETRY values. The new report uses the same convertValue export path but fails at server payload decoding even when the client accepts raw NUL. Related reports remain separate reproductions where they exercise distinct paths. Closing a source issue records tracking consolidation only; no fix is claimed.

Additional acceptance criteria

  • Restore control/binary values with the default mysql client and preserve bytes exactly.
  • Export GEOMETRY as a valid type-aware expression (for example, WKB/hex with SRID handling) that restores successfully even under --binary-mode.
  • Keep SQL and CSV geometry cases distinct where the serializers differ; a successful export must not mask failed import.

Additional reports

  • #30581 — original report and discussion remain on that issue.

Consolidated tracking scope

Make text-format SQL dumps replayable with the default MySQL client while preserving binary and text values. The linked reports are retained as separate reproductions where they exercise different code paths. Closing a linked issue is an administrative consolidation only; no fix is claimed here.

Acceptance criteria

  • Cover raw NUL, Ctrl+Z, LF, TAB, backslash, and quote bytes in VARBINARY, TEXT, and BLOB values.
  • Restore with the default mysql client without --binary-mode; a failure must not be reported as a successful export.
  • Round-trip bytes exactly (for example, compare HEX values) and verify no text-pipeline corruption.

Included reports

  • #30554 — original report and discussion remain on that issue.

Original canonical report (preserved verbatim)

Bug or Feature Request

Bug

Description

mo-dump writes raw control bytes (NUL 0x00, Ctrl+Z 0x1a, and also \n/\t) verbatim into the SQL dump file instead of emitting the standard mysqldump text escapes (\0, \Z, \n, \t). The consequence is a two-layer data-safety failure:

  1. The backup cannot be restored with a default mysql client session. mysql treats a raw 0x00 inside a statement as a protocol violation unless --binary-mode is passed:

    ERROR at line 14: ASCII '\0' appeared in the statement, but this is not allowed unless option
    --binary-mode is enabled and mysql is run in non-interactive mode.
    

    Nothing in mo-dump's output, docs, or help suggests that --binary-mode is required; users doing the canonical mo-dump -db x > x.sql → mysql < x.sql workflow get a hard failure — or worse, a partially applied dump: the INSERT batch containing the NUL fails wholesale, while every other statement in the file has already executed (the dump starts with DROP DATABASE IF EXISTS), leaving the target database partially restored.

  2. Text-pipeline corruption. Raw NUL bytes don't survive common text tooling intact (some editors strip/replace them, terminal paste drops the tail, some channels treat 0x00 as end-of-data). A dump that silently loses bytes after the first NUL still looks like a valid SQL file (it ends with SET foreign_key_checks = 1; only if nothing after the NUL is lost; otherwise it just ends mid-INSERT with no marker), and replays as a truncated restore.

Note the server itself accepts the proper text escapes (verified: INSERT INTO t VALUES (1,'a\0b') stores hex = 610062), so this is purely a mo-dump serialization defect — the escape round-trip is achievable, mo-dump just doesn't do it.

For 0x1a (Ctrl+Z) there is an extra mysqldump-compat dimension: MySQL escapes it as \Z specifically because raw 0x1a is the DOS EOF marker and can truncate files on Windows — the same hazard applies to mo-dump output copied through Windows-oriented tooling.

Steps to Reproduce

MO v3.x commit b24d1b3 (2026-10-16), macOS arm64; mo-dump matrixorigin/mo_dump@324c33d (main HEAD).

CREATE DATABASE esc;
USE esc;
CREATE TABLE t (id INT PRIMARY KEY, s VARCHAR(200));
INSERT INTO t VALUES
 (1, 'it''s a "test"'),
 (2, 'back\\slash'),
 (3, 'line\nbreak\ttab'),       -- stored with real newline/tab via escapes on input
 (4, '中文+emoji😀🎉'),
 (5, '\0\Z control'),           -- stored NUL (0x00) and 0x1a
 (6, 'xxx''\\');

SELECT id, hex(s) proves storage is exact (row 5 → 001A20636F6E74726F6C).

$ ./mo-dump -h 127.0.0.1 -P 16001 -u root -p *** -db esc > esc.sql
$ od -c esc.sql   # around the row-5 literal:
# ... (5,'\x00\x1a control') ...        <-- raw bytes, not \0 \Z
$ mysql -h ... -P ... -u root -p *** < esc.sql
ERROR at line 14: ASCII '\0' appeared in the statement, but this is not allowed unless
option --binary-mode is enabled and mysql is run in non-interactive mode.
Query: 'INSERT INTO `t` VALUES (1,'it\'s a "test"'),(2,'back\\slash'),(3,'line
break	tab'),(4,'中文+emoji😀🎉'),(5,''.

Byte-level evidence from the produced file (python):

b"...(3,'line\nbreak\ttab'),(4,'\xe4\xb8\xad...(5,'\x00\x1a control'),(6,'xxx\'\\'"
NUL byte (0x00) count in whole file: 1      # raw, unescaped
0x1a raw count: 1                          # raw, unescaped

Expected

mysqldump-compatible text escapes in the dump file:

  • 0x00 → \0
  • 0x1a → \Z
  • \n → \n (two chars), \t → \t (actual behavior today: raw newline/tab inside the single-quoted literal, which also makes one INSERT statement span multiple physical lines)

so the dump file is plain text, replays with a default client, and survives text tooling.

Positive control

Server-side round-trip of text escapes works: INSERT INTO t VALUES (1,'a\0b') → hex(s) = 610062. Only the mo-dump export path drops the escapes.

Suggested fix

In the showInsert/escape path of cmd/mo-dump/main.go, escape 0x00 → \0, 0x1a → \Z, (\n, \t, \r dito — or at least keep the raw forms documented as requiring --binary-mode) when serializing VARCHAR values that are the default mo-dump SQL mode.

Versions

  • mo-dump: matrixorigin/mo_dump@324c33d (origin/main HEAD, 2026-10-20); filed on the main repo per triage routing
  • MatrixOne: commit b24d1b3 (2026-10-16), v3.x dev
  • OS: macOS 14.5 arm64; mysql client 8.x

Additional context

Part of the dump-fidelity family: #30666 (AUTO_INCREMENT seed dropped), #30638 (#30640/#30628 CSV family), #30577 (failed dump leaves DROP DATABASE residue). Here the backup "succeeds" but is unrestorable by default and corruption-prone in text pipelines.

Activity

  1. added
    kind/bug
    on Oct 20, 2026
  2. added this to the MO-202610 milestone on Oct 20, 2026
  3. changed the title [-][Bug]: mo-dump emits raw NUL (0x00) / Ctrl+Z (0x1a) bytes into SQL dumps instead of mysqldump text escapes — backup cannot replay via default mysql client and silently corrupts in text pipelines[/-] [+][Bug]: mo-dump SQL output must escape control and binary bytes for default-client restore[/+] on Oct 22, 2026
  4. changed the title [-][Bug]: mo-dump SQL output must escape control and binary bytes for default-client restore[/-] [+][Bug]: mo-dump SQL output must serialize binary values as restorable literals[/+] on Oct 22, 2026
  5. changed the title [-][Bug]: mo-dump SQL output must serialize binary values as restorable literals[/-] [+][Bug]: mo-dump SQL must emit restorable INSERTs for schema-valid values[/+] on Oct 22, 2026
  6. changed the title [-][Bug]: mo-dump SQL must emit restorable INSERTs for schema-valid values[/-] [+][Bug]: mo-dump SQL backups must be restorable, consistent, and preserve exact values[/+] on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions