Skip to content

[Bug]: mo-dump SQL repeats INSERT header for a row larger than net-buffer-length, making successful backup unrestorable #30638

Closed
matrixorigin/mo_dump
#62

Description

@Ariznawlll

Description

mo-dump SQL mode emits two consecutive INSERT INTO headers when a single row exceeds its default 1 MiB -net-buffer-length. The command exits 0 and prints MODUMP SUCCESS, but the generated backup is invalid SQL and cannot restore the row.

Environment

  • MatrixOne branch: main; fixed test commit: 7c146f4adbf068dd0c06b377157cfb7d7698b1eb (2026-10-20)
  • mo-dump main: 324c33dbdc7075cd5d7beaafd1e15c76709dd442
  • Isolated local LOG/TN/CN, SQL port 6001; no shared cluster or customer data.

Steps to reproduce

CREATE DATABASE dump_large_src;
CREATE TABLE dump_large_src.t(id INT PRIMARY KEY, payload LONGTEXT);
INSERT INTO dump_large_src.t VALUES (1, REPEAT('x', 1049000));
SELECT id, LENGTH(payload) FROM dump_large_src.t; -- 1, 1049000
CREATE DATABASE dump_large_dst;
mo-dump -u root -db dump_large_src -tbl t > dump.sql
mysql --binary-mode=1 -D dump_large_dst < dump.sql

The connection flags/credentials should be adapted to the test cluster. -tbl t intentionally produces a table-only script, so the destination database is created separately.

Actual behavior

mo-dump exits 0 and appends MODUMP SUCCESS. The SQL contains two consecutive headers for one row:

INSERT INTO `t` VALUES INSERT INTO `t` VALUES (1, '...')

Import fails with ERROR 1064 (42000) near the second INSERT INTO; the destination table has zero rows. The source still has exactly one row of length 1,049,000, and a subsequent SELECT 1 succeeds.

Expected behavior

An export with a valid supported LONGTEXT row should produce a restorable SQL statement independent of the configured output buffer. If export cannot represent the row, it must fail explicitly instead of writing MODUMP SUCCESS.

Stability and controls

  • Reproducer: 3/3 independent new source/destination databases, all export exit 0, each dump has exactly two INSERT INTO headers, all imports fail with 1064, each destination remains empty.
  • The same 1,049,000-byte row with -net-buffer-length 2097152 imports successfully and compares equal in both directions for every column.
  • The same row exported with -csv imports successfully with exact byte-for-byte payload equality.
  • A separate 1,000-byte row with the default buffer imports successfully and compares equal.
  • No original table was modified by the failing imports.

Evidence

Local isolated artifacts: large_row_a.sql, large_row_b.sql, large_row_c.sql, large_row_buf2m.sql, small_row.sql, and large_csv_ctrl/dump.sql under /private/tmp/mo-dump-cont-20261020.o75VwQ/. In all three failing scripts, the INSERT header occurs twice. The passing controls returned forward_mismatch=0 and reverse_mismatch=0 in a per-column source/target comparison.

Code analysis

In cmd/mo-dump/main.go showInsert, the outer loop writes the INSERT INTO prefix before checking whether the pending row exceeds netBufferLength. On that overflow path, curBuf remains pending and the loop continues without resetting buf; the next iteration writes the prefix a second time before appending the row. This matches both the duplicate header and the fact that raising the buffer size fixes the export. The exporter success marker does not validate that the generated SQL is restorable.

Regression coverage

After a fix, add a mo-dump SQL round-trip test for rows just below, exactly at, and above netBufferLength, including a single oversized LOB and a following normal row. Assert one valid header per INSERT, exact restored bytes and row count, and correct nonzero exit if writing fails. No repository test or PR was added during this exploratory run.

Related

Activity

  1. added this to the MO-202610 milestone on Oct 20, 2026
  2. added
    kind/bug
    on Oct 20, 2026
  3. added theissue type on Oct 20, 2026
  4. Ariznawlll commented on Oct 21, 2026

    @Ariznawlll
    CollaboratorAuthor

    Independent reproduction + scope extension (v3.x @ b24d1b3, 2026-10-21, macOS arm64): the same double-header corruption reproduces with LONGBLOB (not just LONGTEXT), at 5 MiB:

    CREATE TABLE l (id INT PRIMARY KEY, b LONGBLOB);
    -- insert 5,242,880-byte payload via stdin (over argv limits)
    mo-dump -db blobt > dump.sql   # exit 0, MODUMP SUCCESS
    mysql < dump.sql
    ERROR 1064 (42000) at line 25: ... syntax error at line 1 column 29 near " INSERT INTO `l` VALUES (1,'yyyyyy..."
    

    Byte-level: );\nINSERT INTO lVALUES INSERT INTOl VALUES (1,'yyyy... — two headers, no separator, in-file successor statement corrupted. Partial restore confirmed: earlier table in the same dump (a 64 KB BLOB row) did restore before the failure — the DROP DATABASE at the top had already run, so the target DB is left partially loaded.

    Additional classifier data from the same sweep (all consistent with MySQL, for the record):

    • BLOB rejects at exactly 65,536 bytes with "Src length 65536 is larger than Dest length 65535" — 65,535 accepted. Correct MySQL BLOB cap, clean error.
    • MEDIUMBLOB/LONGBLOB/MEDIUMTEXT DDL all accepted; LONGBLOB stores/retrieves 5 MiB fine via SQL (5242880 length verified). So the engine handles large blobs; only the dump path corrupts them.

    This makes the blast radius: any schema using LONGBLOB/LONGTEXT columns ≥ net-buffer-length gives silent-unrestorable backups, and the multi-table dump leaves earlier tables restored while the offending one is dropped/empty.

  5. assigned and unassigned on Oct 22, 2026
  6. Ariznawlll commented on Oct 23, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 日期:2026-10-23,目标 main。
    • MatrixOne 最终重测时官方最新完整 SHA:1393cb552456adb1b84041ca07a215baed494efc,隔离干净源码和实际二进制嵌入 SHA / vcs.modified=false / 运行时 git_version() 一致。首次在 2b388dd1690f83e2e807d6809180336dae2a68eb 的 3/3 通过后 main 推进,关闭前门槛拦截了写入;重建后又完整执行 3/3,以下次数以最终重测计,不累加冒充覆盖。
    • mo_dump 官方 main:f228f16e97644a148e820f2c283e93fd177ec618,实际二进制完整 VCS 和干净源码一致。已读原问题、研发补充的 5 MiB LONGBLOB 场景、修复 #62 完整 diff/review。修复已 MERGED,merge 0ed6f92e4b30cabe935e7025229201265fd7bc38 在被测工具 SHA 祖先链中;不是在未合入版本提前转测。
    • Darwin/arm64、本地隔离 1 CN / 1 TN / 1 LogService、DISK-V2;真实 mo-dump CLI 导出、MySQL CLI 经 TCP/LOCAL INFILE 恢复,PyMySQL 独立逐值校验。未使用共享 TKE/128/129。

    原问题验证

    按正文创建 t(id INT PRIMARY KEY,payload LONGTEXT) 的等价 UUID 隔离库表,插入 (1,REPEAT('x',1049000)),使用默认 1 MiB 缓冲、-tbl 表级 SQL 导出,再恢复到独立预建目标库。

    连续 3/3:导出退出 0、有成功标记,无 VALUES INSERT INTO 重复头;真实恢复退出 0。恢复后唯一一行 id=1、payload 完整等于 1,049,000 个 x,不是只比较 LENGTH/COUNT。源数据保持不变。相同回归换用修复前工具,3/3 捕获原始表的重复 INSERT 头,且每次失败后库清理复核通过。

    Happy Path 覆盖

    1. 按实际 INSERT 前缀和 tuple 开销构造序列化行总长度为 buffer-1、buffer、buffer+1,在 1,024 / 1,048,576 bytes 两个缓冲阈值各测三种情况,每种 3/3 恢复全值一致。
    2. 原评论的 5,242,880-byte LONGBLOB 原规模实测 3/3,同时覆盖其后普通行、00FF275C0A 二进制(含非法 UTF-8/NUL/引号/反斜杠/LF)、SQL NULL、空 bytes。
    3. 连续两条超过默认缓冲的 LONGTEXT(1,049,000 / 1,049,001 bytes)、后续普通行、NULL、空字符串、重复 Unicode/emoji/单引号/反斜杠/CR/LF/Tab,以及空表;完整多表 SQL 导出恢复 3/3,每张表逐主键排序对比所有列值与 SHOW COLUMNS 元数据,不接受只恢复前一张表的部分结果。
    4. 默认缓冲的 1,000-byte 小行、原大行使用 2 MiB 缓冲、原大行 CSV/LOCAL INFILE 三类正常对照各 3/3。每轮 11 次真实导出/恢复,共 33 次,全部逐值/元数据/源不变检查通过。
    5. 字节序列化与输出缓冲问题不依赖分布式拓扑或海量行数;保留原大行阈值和 5 MiB 扩展场景,不宣称吞吐或分布式备份验收。

    Unhappy Path 覆盖

    1. 不存在的表、无效 -where 表达式,各 3/3 非零退出且不输出 MODUMP SUCCESS;失败前后目标原始表完整不变,所有源表保持一致。
    2. CLI 已开始输出 INSERT 后关闭本任务的管道消费者,各 3/3 在 30 秒退出界限内非零返回;源表全值不变,同一 SQL 连接 SELECT 1 仍正常。不把输出中断后的半份文件视为可恢复备份。
    3. 每轮 finally 清理源库/目标库并检查 catalog 计数 0,最终重测共 6 个库;临时文件目录与子进程清理完成。旧版反例另外三轮清理也检查通过。首次测试、旧版反例、最新 SHA 重测三次本任务服务均正常退出 0,SQL 端口已释放,服务日志未见 panic/fatal/race。
    4. 全 dump 恢复包含多条 DDL/DML,本测试不声称失败时全文件事务回滚;原子性结论仅限上述被拒绝导出未改动既有源/目标数据。

    白盒验证

    • 已核查修复在“没有输出、curBuf 仍持有超限行”的 continue 前重置仅含头部的 buf;下一轮只产生一个 INSERT 头。没有修改产品代码。
    • 完整 mo_dump 命令包 go test -count=3 ./cmd/mo-dump 通过,0.822s。首次漏传项目 CGo 库链接配置,编译阶段报 library 'mo' not found,尚未进入测试;补齐 Makefile 等价 CGo 参数后通过,不算产品失败。
    • 已有 Test_showInsertOversizedRow、TestShowInsertRows、TestShowInsertScanError、TestDumpExitStatus、TestGenOutputUnfinishedRows 执行 -race -count=3,通过,4.895s;覆盖既有缓冲清理、迭代/扫描错误及退出状态契约。没有新增 MO Go PR。
    • 修复前 clean SHA 324c33dbdc7075cd5d7beaafd1e15c76709dd442 同一用例 3/3 在原始表重复头断言处失败(恢复前拦截,当时 MO 服务为 2b388dd1690f83e2e807d6809180336dae2a68eb);不是假称旧版恢复成功。旧构建未嵌入 VCS 字段,来源由干净源码、直接构建记录及 SHA256 916712249f18de50fb5ce24a7499536cc364523c63aa74f9ad3a3804f17171cb 绑定,明确区别于新工具已核实的嵌入 SHA。

    回归测试

    • 独立 MOTR #272,官方 main 13a6aad987e93be1883daa54f08a63d4cc5fe5a2 起分支,head 462a1730c70c94e2c7f80fe65fa657de43e0085e,Open draft;未追加 select without from clause is not supported #247,未修改其他人的 PR。
    • issue_30638_modump_large_rows.py + 手写配对 .out + 五项离线契约。显式启用 MOTR_MODUMP_TESTS=1 和工具路径,最新 SHA 定向 --repeat 3 3/3 PASS、零 skip、12.43s。未配置工具时跳过,不把 skip 当产品覆盖。
    • MOTR 完整离线框架 433 项通过,33.716s。未跑全量 live 14_issue_regression/MOTR、对象存储、跨主机/分布式恢复、并发源 DML、崩溃恢复或性能基准。
    • 新 MOTR PR exact head 的 CI run 39901115825 已 success:Python 3.10/3.12/3.13 离线契约及 Go 协议/数值契约 4/4 success。这是离线框架 CI,不替代本地真实服务 3/3,不声称全量 live CI 通过。
    • 修复 head 没有 Actions 测试 workflow;Summary success/Mergify neutral 不作为测试 CI 通过证据。该工具相邻单列空字符串 CSV 丢行仍由 [Bug]: mo-dump CSV silently drops single-column empty-string rows on restore #30917 跟踪,本用例 CSV 对照是双列原始表,不声称修复该独立问题。

    测试证据

    • 本地 /tmp/mo-remaining-yvQVzl/motr-latest.log、service-latest.log、motr-final.log(首次 SHA)、framework.log、baseline.log、old-0.stderr 至 old-2.stderr、service.log、service-old.log;分别保留每轮 MOTR 判定、完整离线框架、旧版重复头断言与清理记录。
    • 最新构建下载 ONNX 时网络停滞,停止该次本任务构建,改用本任务已有 1.26.0 库并由 Makefile 再次验证 SHA256 30afadcfc3c704f7671f8430d6252956651c1972373901d2be629da2e6a4d8ee,与当前固定值一致;未跳过校验或修改源码。最终构建完成后才执行重测。
    • 上述独立回归 PR 的完整实现和配对输出可复查;旧版来源构建记录在 /tmp/mo-hourly-0408-r3IOMR/old-build.log。

    测试结论

    测试通过。

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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions