Skip to content

[Bug]: DATA BRANCH CSV output ignores batch copy errors #26128

Closed

Description

@Ariznawlll

Summary

DATA BRANCH DIFF ... OUTPUT FILE does not propagate a batch-copy failure before it submits the CSV conversion task. The failed copy produces a nil batch, which the worker dereferences.

Revision

2eb7f523e5a10f352d3e258183ed8440510388de (main)

Reproduction

The failure is reproducible with a focused frontend white-box test:

  1. Build an off-heap text batch larger than a 1 MiB MPool limit.
  2. Call bat.Dup(limitedMP). It returns a non-nil error and a nil batch.
  3. Follow the same unchecked flow used in writeCSV: submit the nil result to constructByte.

The test passed 3/3 and observed the nil-batch dereference each time.

Actual behavior

At pkg/frontend/data_branch_output.go, the CSV path uses:

copied, _ := bat.Dup(ses.proc.Mp())

The returned error is discarded. constructByte subsequently accesses bat.RowCount() and dereferences the nil value.

Expected behavior

The batch-copy error should be returned through the existing cancellation/error path. No CSV worker should be started with a nil batch, and the statement should return a regular error after cleaning up its temporary output.

Notes

The ordinary export path in pkg/frontend/export.go checks the same bat.Dup error before scheduling conversion work.

Activity

  1. added this to the MO-202607 milestone on Jul 24, 2026
  2. added
    kind/bug
    on Jul 24, 2026
  3. added theissue type on Jul 24, 2026
  4. VioletQwQ-0 commented on Jul 29, 2026

    @VioletQwQ-0
    Collaborator

    PR #26149 merged as 2d0adac64ea6c72028c5443813428f84fbcd1575 (reviewed head 066b8da40d33606395db1e5028aa1dbf45bbd7b8). Focused error-path coverage and required product CI passed; merge-update-moc was post-merge synchronization only.

    QA handoff on main f6dab28046d70412cec132f0068840896852101c:

    • Exercise a successful DATA BRANCH CSV output path.
    • Induce a batch-copy/write failure after output has started.
    • Verify the statement reports the original failure and leaves no apparently successful or silently truncated result.

    Pass: success remains unchanged, and injected copy failure reaches the user with safe cleanup. Fail: false success, swallowed error, or partial output presented as complete.

  5. Ariznawlll commented on Jul 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 分支完成验证。

    测试版本:52ea9f874f492c368a20efef16b46ab8ced2de37

    测试过程:

    1. 通过专项错误注入测试,在 CSV batch 已构造但尚未提交时触发 copy 失败。
    2. 普通模式和 -race 模式各连续执行 3 轮,检查返回错误、batch submit 行为及 panic。
    3. 额外执行黑盒正常输出场景,数据包含 Unicode、逗号、单引号和换行。
    4. 将生成的 SQL patch 重新执行,并用双向 EXCEPT 对比恢复后的数据。

    测试结果:

    • copy 失败会在 submit 前原样返回,不再忽略错误,也没有 nil dereference/panic。
    • 失败 batch 不会被继续当作成功结果提交。
    • 正常 CSV 输出和重放成功。
    • 特殊字符及换行数据重放后与源数据一致,双向 EXCEPT 均为 0 行。
    • 专项普通及 -race 测试全部通过。

    说明:copy 失败点无法仅通过外部 SQL 稳定触发,因此失败分支使用确定性的白盒错误注入;正常输出和数据完整性使用黑盒 SQL 验证。

    结论:该 issue 描述的 batch copy error 被忽略问题已修复,本轮验证通过。

  6. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在 main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c 补充完成黑盒和白盒验证。

    黑盒验证:

    • MOTR 场景:issue_26128_data_branch_output_file.py
    • 数据包含逗号、双引号、反斜杠、中文和字段内真实换行符。
    • 执行 DATA BRANCH DIFF ... OUTPUT FILE,要求返回一个生成的 .sql 文件路径。
    • 对同一 diff 执行 OUTPUT AS,逐行检查 UPDATE、DELETE、INSERT 的精确内容。
    • 输出前后分别回读 source 和 branch,确认生成输出不会修改输入数据;同时确认 OUTPUT AS 结果是普通非 branch 表。

    结果:场景通过;本轮 Data Branch 全集 13/13 case、280/280 条 SQL/断言通过。

    白盒验证:

    go test ./pkg/frontend \
      -run '^TestSubmitCSVBatchForConversionReturnsCopyErrorBeforeSubmit$' \
      -count=1
    ok github.com/matrixorigin/matrixone/pkg/frontend
    

    白盒通过受限 MPool 注入 batch.Dup 失败,验证错误会在提交 CSV worker 前返回,不再把 nil batch 交给 worker。黑盒只验证支持的成功输出路径,不伪造内部内存错误。

    Unhappy path / 错误传播:

    • 使用受限 MPool 强制 batch.Dup 返回 error 和 nil batch。
    • 检查原始 copy error 在 submit worker 前返回,worker 不会接收到 nil batch,避免后续 nil-pointer panic。
    • 黑盒 difficult-value 数据同时包含 quote、comma、backslash、Unicode 和字段内换行,检查 CSV/SQL materialization 不截断或错误转义。
    • 输出前后对 source/branch 做精确回读,防止输出失败或输出生成修改业务数据。

    结论:内部 copy-error 传播及公开 OUTPUT FILE/OUTPUT AS 路径均验证通过,黑盒回归已加入 motr#69。

  7. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    Unhappy Path / Copy Error 专项验证

    测试版本:main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c

    白盒错误注入:

    1. 使用受限 MPool 强制 batch.Dup 返回 error 和 nil batch。
    2. 调用与 CSV output 相同的 batch submit 路径。
    3. 检查 copy error 在提交 worker 前直接返回。
    4. 确认不会把 nil batch 交给 worker,避免后续 nil-pointer panic。
    TestSubmitCSVBatchForConversionReturnsCopyErrorBeforeSubmit
    ok github.com/matrixorigin/matrixone/pkg/frontend
    

    黑盒边界数据:

    • comma、quote、backslash、Unicode、字段内真实换行;
    • 同时验证 OUTPUT FILE 和 OUTPUT AS;
    • 输出前后 source/branch 精确回读,防止输出生成修改业务数据。

    结果:内部 copy error 正确传播;公开输出路径没有截断或错误转义困难字符串。黑盒回归见 motr#69。

    补充覆盖 worker submit 失败路径:预先释放 worker pool 后提交已复制 batch,submit error 能够原样返回,临时 copy 被完整清理,目标 MPool 回到 0,没有 batch 泄漏或二次 panic。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions