Skip to content

[Bug]: mo-dump reports success after export query is canceled and silently omits rows #30574

Closed
matrixorigin/mo_dump
#57

Description

@Ariznawlll

问题

导出进行中取消其源端 SELECT 后,mo-dump 仍以退出码 0 结束,并在不完整 SQL 文件末尾写入 MODUMP SUCCESS。脚本也能无报错地恢复,但只包含源表的一部分行;仅看退出码、成功标记和导入是否成功,都无法发现数据丢失。

环境

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

复现

CREATE DATABASE dump_probe;
CREATE TABLE dump_probe.t (id INT PRIMARY KEY, payload VARCHAR(220));
INSERT INTO dump_probe.t
SELECT result, LPAD(CAST(result AS CHAR), 200, 'x')
FROM generate_series(1, 200000) g;
SELECT COUNT(*) FROM dump_probe.t; -- 200000

执行 mo-dump ... -db dump_probe -net-buffer-length 16384 > dump.sql,通过限速 stdout 保持导出流仍在运行;在另一连接的 SHOW PROCESSLIST 中确认正在执行的是这次导出的 select * from dump_probe.t,再执行 KILL QUERY <该连接 ID>。本地三次均在查询仍活动时取消,且导出文件在取消前已开始包含 INSERT 数据。三次分别使用独立新建的 200,000 行源库。

运行 mo-dump 退出码 文件末尾 导入该文件后的行数
1 0 MODUMP SUCCESS 19,932
2 0 MODUMP SUCCESS 104,401
3 0 MODUMP SUCCESS 94,482

三份文件均导入到新建的独立目标库,导入退出码 0。源表取消后仍有 200,000 行、SUM(id)=20000100000,连接保持可用。未取消的相同 200,000 行、相同 16 KiB 分块设置对照导出和导入均成功,目标为 200,000 行、SUM(id)=20000100000、总文本长度 40,000,000 字节。不是生成数据或恢复工具的问题。

白盒定位

cmd/mo-dump/main.go 的 showInsert 在 r.Next() 返回 false 后没有检查 r.Err(),而是直接返回 nil(约 :539-616);genOutput 因此向上报告成功,main 的 defer 写入 MODUMP SUCCESS(约 :72-96)。查询取消会让迭代提前结束,但被误认为正常 EOF。toCsv 也缺少末尾 r.Err() 检查,不过一次 CSV 导出取消对照明确返回 Error 1317: context canceled、退出 1、没有成功标记;所以本 issue 只报告已验证的 SQL 导出路径,不推断 CSV 同样出错。

预期:源端读取中断必须使导出返回非零并且不得写入成功标记。已有 #30558 是并发事务下跨表快照不一致,根因和触发条件不同。已检索 MatrixOne/mo_dump 的 open/closed issue、相关 PR 和兼容性限制文档,未找到相同问题。

Activity

  1. added this to the MO-202610 milestone on Oct 19, 2026
  2. added
    kind/bug
    severity/s1
    on Oct 19, 2026
  3. added theissue type on Oct 19, 2026
  4. removed
    severity/s1
    on Oct 19, 2026
  5. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充跨 CN 生命周期边界(同一根因,不另开单):在固定 main 75ff736835c3d00d40dc00a0a1d3b11129388e5b 的隔离双 CN 上,三份各 200,000 行/40 MB 的独立源表通过第二 CN 正在执行 SELECT * 导出;SHOW PROCESSLIST 确认查询仍活动时停止仅第二 CN。三次客户端均记录 unexpected EOF,但 mo-dump 都退出 0 并写 MODUMP SUCCESS;将各自脚本导入第一 CN 也都退出 0,却只恢复 76,150 / 84,276 / 95,847 行。三份源表在第一 CN 上仍各 200,000 行,后续连接正常。未中断的第二 CN → 第一 CN 20,000 行 SQL/CSV 对照均完整一致。该结果把本 issue 的 Rows.Err() 漏检扩展到 CN 消失场景;成功标记绝不能作为完整备份依据。

  6. added
    severity/s0
    and removed on Oct 20, 2026
  7. assigned and unassigned on Oct 22, 2026
  8. slyunnn commented on Oct 22, 2026

    @slyunnn

    Regression and extended verification for #30574 (2026-10-22)

    Verification Environment

    • MatrixOne: freshly fetched origin/main, 75ae9a79d626622e6ccec0bcb28412f5fcf84c7f — fix(frontend): escape CSV values before OUTFILE framing (#30719). Clean source and actual binary identity matched; Go 1.27.1, Linux/arm64, TYPECHECK=1. Runtime identity was also checked after CN2 restart.
    • mo_dump: latest fetched origin/main, f228f16e97644a148e820f2c283e93fd177ec618 — Merge pull request #59 from ck89119/issue-30573-main. The tested native binary was built with Go 1.26.5 on macOS/arm64. Old-tool baseline: 324c33dbdc7075cd5d7beaafd1e15c76709dd442.
    • Final topology: 2 CN / 1 TN / 1 Log service / Proxy, using task-owned local DISK-V2 storage. One container runs LOG/TN/CN1 and the actual Proxy module with -with-proxy; CN2 runs as a separate process/container, allowing CN2-only termination without stopping CN1/TN/LOG/Proxy.
    • Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, and CN2 127.0.0.1:16002 were connected and actually used for original cancellation and normal SQL/CSV round trips. An earlier built-in TCP-forwarder run was superseded by a complete rerun through the real Proxy topology.
    • Protocol: mo-dump uses the MySQL driver's text result stream; MySQL CLI 9.7.1 restores with COM_QUERY, --binary-mode=1, and LOCAL INFILE for CSV. Binary prepared statements are not involved.

    What Was Covered

    • OK — Original fixture: 200,000 rows, 200 payload bytes per row, and -net-buffer-length 16384. Interruption was gated on already-emitted INSERT data and the exact active export SELECT observed in SHOW PROCESSLIST, not a fixed sleep.
    • OK — Old-tool negative baseline through all three endpoints: KILL QUERY still resulted in exit 0 and MODUMP SUCCESS. Restoring those apparently successful files returned exit 0 but only 19,932, 29,872, and 39,812 rows, respectively.
    • OK — Fixed-tool cancellation through all three endpoints: exit 1, error 1317 / context canceled, and no MODUMP SUCCESS.
    • OK — Uninterrupted fixed-tool SQL and CSV exports restored completely in all 6 endpoint/mode combinations: COUNT(*)=200000, SUM(id)=20000100000, total payload length 40000000, and 0 payload/formula mismatches. Source data remained unchanged.
    • OK — Comment-requested CN lifecycle boundary: after streaming began and CN2's export query was confirmed active, only the task-owned CN2 container was terminated. Old tool logged unexpected EOF but returned exit 0 with a success marker; its partial file ultimately restored only 27,375 rows. Fixed tool returned exit 1, reported invalid connection, and emitted no success marker.
    • OK — While CN2 was stopped, CN1 remained queryable and retained all source rows and expected aggregates. CN2 was restarted and its version/data checked. Subsequent uninterrupted CN2-export → CN1-restore SQL and CSV controls both passed on their first restore attempts.
    • OK — Focused existing tests covered normal EOF, empty results, chunk boundaries, cancellation before/after rows, read/scan/write errors, CSV flush errors, pooled-buffer reset, physical connection cleanup, bounded bad-connection retries and actual subprocess exit/success markers. The unfinished-result fixture verifies cleanup without waiting for server EOF and successful connection reuse via PING.
    • OK — TestGenOutputUnfinishedRows and TestGenOutputBadConnRetry each passed 100 focused repetitions under -race; the full owning command package also passed under -race.
    • OK — Endpoint jobs ran concurrently with separate source/target databases and files. CN2 failure/restart ran serially with exclusive fault ownership. Test-created databases were removed and all three endpoints were healthy afterward. No engine-parallelism claim is made.
    • Failed — A separate post-CN2-loss restore failed at line 4, CREATE DATABASE, with 20702, lock table bind changed. The old partial-file restore succeeded on a second, explicitly recorded attempt after CN2 restart. This was not counted as uninterrupted failover availability; later full recovery controls passed without retries. Standalone SQL follow-up (2026-10-23) reproduced catalog DDL failures without mo_dump; the relationship to [Bug]: DROP DATABASE fails with lock table bind changed after controlled 3 CN to 1 CN scale-down #29447's controlled scale-down root cause remains unconfirmed.
    • Not covered — Live CSV cancellation/CN-loss injection (CSV error propagation was unit-tested), cross-table concurrent-transaction snapshot consistency, sustained network blackholes, TKE execution and performance/soak testing.

    Findings

    The fix is mo_dump PR #57, fix: fail dump exports on source row iteration errors, merged as 2384b168d497f652a540f6bfd931f478c2af0077 and included in the tested tool head.

    SQL/CSV iteration now checks Rows.Err(). Failed exports close the physical query connection before closing unread rows; pre-result bad-connection retries remain bounded, and partial result streams are not retried. Both real KILL QUERY and CN2 disappearance now fail visibly instead of certifying incomplete output.

    Already-written partial files are not rolled back and must not be treated as complete backups. The separate 20702 DDL observation is tracked with additional evidence under #29447. It is not part of this tool error-signaling acceptance; its exact root cause and equivalence to the existing scale-down issue are still unconfirmed. This verification does not assert seamless database failover.

    MOTR / BVT Coverage

    The merged fix already contains deterministic row-error, cleanup, retry, driver-protocol and CLI-exit regressions. This run supplements them with actual MatrixOne streaming export/restore and CN2-only failure evidence. No duplicate SQL-only MOTR case was added: it would not execute the external serializer or its exit-status contract. No new regression commit, push or weekly PR update was required. Product source and existing Docker configuration/data directories were not modified; the additional topology used temporary task-owned configuration/data.

    Final Conclusion

    Fixed for #30574: canceled or disconnected SQL exports no longer return false success on the verified versions, including the CN2-disappearance boundary.

    Large-data/streaming regression was required and executed locally using the original 200,000-row / 40 MB fixture to keep a real result stream in flight under output backpressure. Minimal deterministic unit fixtures cover individual row/chunk/error boundaries. Further arbitrary volume, a TKE run or a throughput target is unnecessary for this specific error-propagation contract.

    No issue-state change was performed by this verification.

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