Skip to content

[Bug]: mo-dump CSV ignores final flush error and silently restores truncated values #30628

Closed
matrixorigin/mo_dump
#58

Description

@Ariznawlll

问题

mo-dump -csv 的最后一行写入磁盘失败时,进程仍返回 0,脚本仍输出 MODUMP SUCCESS 和 LOAD DATA LOCAL INFILE。恢复该 CSV 也可返回 0,但字段内容已静默截短。备份/恢复的退出码、成功标记和行数均不足以发现数据损坏。

环境

  • MatrixOne 官方 main:7c146f4adbf068dd0c06b377157cfb7d7698b1eb,macOS arm64,隔离的单 LOG/TN/CN,本地前端 6001。@@version 显示 8.0.30-MatrixOne-v1.3.0(该字符串不是源码 SHA)。
  • mo-dump 官方 main:324c33dbdc7075cd5d7beaafd1e15c76709dd442。
  • 另在 MatrixOne 75ff736835c3d00d40dc00a0a1d3b11129388e5b 的独立集群复现;两个集群与用户原始工作区隔离。

最小复现

CREATE DATABASE dump_probe;
CREATE TABLE dump_probe.t (id INT PRIMARY KEY, payload TEXT);
INSERT INTO dump_probe.t VALUES (1, REPEAT('x', 1200));
SELECT LENGTH(payload) FROM dump_probe.t; -- 1200

在新的空目录运行(本地测试账号的口令通过环境变量提供;不要将真实口令写进脚本):

( ulimit -f 1; trap '' XFSZ; mo-dump -u root -p "$MO_TEST_PASSWORD" -db dump_probe -csv ) | tee dump.sql
echo "${PIPESTATUS[0]}"   # 0
wc -c -l dump_probe_t.csv # 0 lines, 1024 bytes; normal control: 1 line, 1203 bytes

ulimit -f 1 仅限制 mo-dump 进程的文件大小(本机 1 KiB),trap 使最后一行的文件写入返回错误,避免进程被信号直接终止;stdout/tee 和数据库服务不受该限制。脚本包含 LOAD DATA LOCAL INFILE 与 MODUMP SUCCESS。把脚本中的数据库名重定向为新的空目标库后用开启 LOCAL INFILE 的客户端导入;不要覆盖源库。

实际结果

路径 导出退出码/标记 CSV 大小 导入退出码 恢复行数 恢复 LENGTH(payload)
无写入限制对照 0 / SUCCESS 1203 0 1 1200
最后一行写入失败,独立运行 A 0 / SUCCESS 1024 0 1 1022
同上,独立运行 B 0 / SUCCESS 1024 0 1 1022
同上,独立运行 C 0 / SUCCESS 1024 0 1 1022

三次完整导出脚本→替换库名→导入新库的管道阶段退出码均为 0 0 0,结果仍是 1 行、长度 1022;源端始终为 1200,之后 SELECT 1 正常。另一组 100 行/最后一行 400 字节的样本也 3/3:成功导入后最后一行只有 289 字节,整表文本总长从 20200 变 20089。反向对照:100 行样本在第 5 行附近遇到更早的相同限额时,mo-dump 明确报 file too large、退出 1、无 SUCCESS;问题集中在最后一次 flush 没有下一次写入来暴露错误。

预期

CSV 文件任何写入/刷新/关闭失败均使导出非零退出,且不得输出成功标记或可被误认为完整备份的恢复脚本。恢复后数据应与源一致;不能用行数相同替代值校验。

白盒定位

在 mo_dump cmd/mo-dump/main.go:687-695,toCsvLine 调用 csvWriter.Flush() 后没有检查 csvWriter.Error(),而是返回此前 Write 的 nil。最后一行的 flush 失败因此被吞掉;:618-636 还忽略 f.Close() 的错误。应覆盖最后一次 flush 与 close 的失败传播。

去重和回归建议

已查 MatrixOne/mo_dump 的 open/closed issue、相关 PR 及 mysql-compatibility-contract。#30574 是源端查询取消后的 SQL Rows.Err() 漏检;本问题是 CSV 目标文件最终写入错误,触发和代码路径不同。mo_dump #44/#45 属值编码问题,也不同。

建议先用失败 io.Writer 做 mo-dump UT(只在末行 Flush 报错),再以可控文件限额做端到端导出/导入回归,断言退出码、成功标记、文件完整性和恢复值。本次仅测试并提报,未新增仓库用例或 PR。

Activity

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

    @slyunnn

    Regression and extended verification for #30628 (2026-10-27)

    Verification Environment

    • MatrixOne latest main: 2465dae7a4ada1b277113cca5afff6fe10149b96 — refactor: consolidate unused code and bookkeeping cleanup (#31348); rebuilt binary git_version() was 2465dae7a4 on all routes.
    • mo-dump latest main: d9d6375512620f12ff371b8602cc1d10d6f6caa0 — fix: make SQL/CSV dump scripts restore-safe (#30596 #30598 #30587 #30590 #30628 #30481) (#58). Associated fix: mo_dump PR #58.
    • Isolated topology: 2 CN / 1 TN / 1 Log service / Proxy. Container endpoints Proxy 6001, CN1 16001, CN2 16002 were mapped to host 6601, 16601, 16602; all three were connected and tested independently.
    • Export used the mo-dump MySQL driver; normal CSV restore used native mysql 9.7.1 over the MySQL text protocol with LOCAL INFILE enabled. The macOS file-size limit was applied only to the test mo-dump process.

    What Was Covered

    • OK — Source fixture contained one TEXT payload of length 1200 bytes on each route.
    • OK — A 1024-byte process file-size limit caused the final CSV write/flush to fail on Proxy, CN1, and CN2. The partial CSV was 1024 bytes, mo-dump exited 1, and stdout contained neither MODUMP SUCCESS nor a LOAD DATA statement.
    • OK — An unrestricted control export and native-client restore completed with exit 0; the restored payload length was exactly 1200 on all 3 routes.
    • Not covered — Hardware disk-full/ENOSPC injection and a close-only failure. The targeted final-flush boundary and normal control were exercised directly.

    Findings

    The original false-success path no longer reproduces. This issue depends on a final buffer/flush boundary, so a minimal stable 1200-byte row with a 1024-byte file limit was required and used. Large-data regression required: No additional large dataset; arbitrary row growth would add cost without exercising a different boundary.

    MOTR / BVT Coverage

    The owning mo_dump repository's full make test passed at the tested commit, including final-flush error tests. The live process-level failure and normal restore controls above passed on all 3 routes. No duplicate SQL-only MOTR case was added: file write failure propagation, CLI exit status, and success-marker absence are the key assertions.

    Final Conclusion

    Fixed for #30628's final-flush false-success path on the tested revisions. No issue-specific PR was created.

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions