Skip to content

[Bug]: ETL merge builds unbounded whole-file LOAD SQL, causing packet-limit failures and high memory peaks #32411

Done

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Related issues were read, not classified from titles alone. #12489/#12682 increased the default packet limit from 16 MiB to 64 MiB; they did not introduce bounded ETL batches. #29797 addresses individual TEXT-field capacity, and #25505 addresses a different SQLFlusher.FlushBuffer allocation. None accurately tracks the whole-file buffering / single oversized LOAD / memory-amplification mechanism below.

Branch Name

v4.2.8 (runtime-confirmed). The same unchunked control flow remains in source-reviewed current main; main has not been runtime-retested.

Commit ID

  • Affected running release: 10d204b8763f19b2b37ba2147d1d4c1a7828d6d4.
  • Current main inspected through GitHub on 2026-11-09: e2459cc55f4b514893e19732743460bc5f16d552.

Other Environment Information

  • Kubernetes/Linux internal QA environment; CN memory limit 16 GiB, CPU limit 6 cores.
  • GOMEMLIMIT=10GiB, GOGC=100; FileService memory cache 2 GiB, disk cache 45 GiB.
  • Built-in ETL ingestion into system.statement_info; no customer SQL/data or private monitoring URLs are included here.
  • A cgroup OOMKilled / exit 137 occurred at 2026-11-09 00:01:12 UTC / 08:01:12 Asia/Shanghai. The previous process had run approximately 60.6 hours. This is incident context, not proof that this code path uniquely caused that kill, and not a claim of daily OOM frequency.

Actual Behavior

The built-in ETL merge buffers a complete report file, then constructs one escaped LOAD DATA INLINE SQL without a serialized-byte batch bound. Large files therefore produce packet-limit failures after substantial allocations, remain unimported, and are eligible for processing by later merge runs.

Observed error, explicitly associated with table=system.statement_info:

failed do write
packet for query is too large. Try adjusting the `Config.MaxAllowedPacket`

failed to upload file to MO
table=system.statement_info
packet for query is too large. Try adjusting the `Config.MaxAllowedPacket`

These failures were observed shortly before the OOM and again in the 2026-11-09 11:18 Asia/Shanghai audit. Two pre-OOM samples refer to different source files; this is not a claim that one file was retried in a tight loop. A narrow later 14:34-14:39 window returned no matching upload failures, so failure should not be described as continuously active at every instant.

Runtime allocation evidence

Two existing heap profiles were read by HTTP without gc=1 or forced GC, at 14:36:08 and 14:39:46 Asia/Shanghai:

Sampled Go heap attribution First profile Second profile
Total inuse_space 5,359.95 MiB 4,370.50 MiB
PushClient.replayCatalogCache cumulative 3,488.33 MiB 3,488.33 MiB
MergeTaskExecutorFactory -> LongRunETLMerge cumulative 1,170.32 MiB No longer a dominant retained subtree

The first ETL subtree includes CSV record/line reading (~726 MiB cumulative) and SliceCache.Flush -> bulkInsert (~443 MiB cumulative). Parent/child cumulative entries overlap and must not be added again. The catalog subtree is a separate high baseline, not part of the ETL defect.

The second profile reports approximately 1.63 TiB cumulative Go allocations, of which 81.63% is under the built-in ETL merge path. This is allocation churn since process start, not resident or leaked memory.

The exporter SQL-size histogram at 14:42:57 Asia/Shanghai reports 5,746 construction attempts since the current process started; 847 exceed 70,028,153 bytes (~66.8 MiB), including 266 exceeding 94,538,006 bytes. All observed attempts fit within the 127,626,309-byte histogram bucket. These are generated SQL attempts, not successful imports or distinct failed requests. The deployed source default packet limit is 64 MiB; the destination's runtime override was not queried.

Expected Behavior

  • Internal report ingestion should have an explicit bound on serialized SQL size and in-flight memory, independent of total source-file size.
  • Many individually valid report rows must not fail as one oversized SQL merely because their aggregate escaped representation exceeds the connection's packet budget.
  • A single row that cannot fit must have an explicit, observable handling policy; it must not trigger unbounded buffering or silent report loss.
  • Failure and retry must preserve audit-record completeness and idempotency.

Steps to Reproduce

Observed runtime path:

  1. Enable the standard internal statement-report exporter and ETL merge on the affected release.
  2. Have an unimported report CSV whose aggregate escaped representation exceeds the destination packet budget. The file can contain many valid small rows; an individually oversized TEXT value is not required.
  3. ETL reads the full file into SliceCache, escapes/re-encodes it, obtains a full CSV string, and formats one LOAD DATA INLINE SQL.
  4. The MySQL driver rejects the oversized packet after the large SQL/buffer has already been constructed; the source file is not deleted by the normal success path.
  5. A later merge run can select the retained file again, repeating work and memory pressure.

The QA logs, heap profiles and SQL-size histogram establish the path and observable failure. No synthetic generator, full incident-CSV replay, or deterministic OOM reproduction was run in QA.

Suggested isolated regression: generate a schema-valid internal CSV with individually valid fields but an aggregate encoded LOAD above a deliberately small test packet budget; invoke the real ETL path and assert bounded chunks, exact row contents and file lifecycle. This is a proposed test, not a claimed passing reproduction.

Additional information

Confirmed exact-version code facts

  1. Merge.doMergeFiles reads all remaining records into SliceCache before the single Flush. MaxFileSize controls grouping of files, not a hard limit or splitting boundary inside one file.
  2. SliceCache.Flush passes the complete row collection to WriteRowRecords. There is no serialized-byte partitioning here.
  3. bulkInsert mutates rows with escaping, writes a full CSV buffer, converts it to a string, formats a complete SQL string and calls Exec. These representations can coexist and amplify peak memory.
  4. putBuffer resets and pools the buffer without a capacity bound. This can retain a large buffer, but a pool entry is not by itself an unreachable-memory leak.
  5. Flush failure returns before normal source-file deletion. The outer loop waits 10 seconds and continues; it does not immediately retry the same file forever. Later runs may encounter the retained file.
  6. The running release uses go-sql-driver/mysql v1.8.1. Its writePacket checks pktLen > maxAllowedPacket and returns ErrPktTooLarge; the complete SQL and driver packet buffer have already been allocated by this point.

Current main retains the whole-file accumulation and single-SQL construction. Main's per-field diagnostic normalization does not impose a total batch-size bound. This is source validation only, not a main runtime result.

Impact and proof boundary

  • Confirmed defect: internal telemetry imports fail at the packet boundary, with substantial ETL memory peaks / allocation churn and retained source files.
  • Confirmed environment pressure: the same 16 GiB CN has ~3.4 GiB of sampled Go catalog-replay allocations plus separately budgeted FileService/native/runtime memory. This reduces headroom but does not establish a catalog leak.
  • Leading hypothesis, not proven: ETL peaks atop that baseline contributed to the particular 08:01 OOM. The exact allocation at the kill and a controlled counterfactual are missing.
  • Two no-GC profiles show substantial natural heap reduction. Do not label this a demonstrated permanent Go/off-heap leak, a specific Astra application bug, or a newly introduced 4.2.8 regression.
  • No evidence of business-table corruption is claimed. The directly affected records are internal statement reports; observability can be incomplete or delayed.

Fix / validation constraints

  • Bound batches by escaped, serialized SQL bytes, including syntax overhead, rather than only row count or raw file bytes. Consider reducing full-file buffering and large-buffer retention.
  • Do not resolve this solely by increasing max_allowed_packet; that does not bound memory and may move more work into server-side parsing/execution.
  • Preserve quotes, backslashes, multiline CSV, UTF-8 and report-field normalization semantics.
  • Chunking must also fix retry semantics: the current first-record-exists check treats the file as already imported. If chunk 1 commits and chunk 2 fails, a retry must not see the first row, skip the remainder and delete the source file. Test partial success, cancellation, restart and exactly-once/idempotent completion explicitly.
  • Keep source files recoverable until complete import; do not silently discard oversized rows/files.

Related work / duplicate search

Investigation was read-only. No cluster/configuration/data changes, forced GC, workload replay, or code fix was performed. Private profiles are retained locally; raw SQL, credentials, customer identifiers and private log links are intentionally omitted.

Activity

  1. added
    kind/bug
    on Nov 9, 2026
  2. added
    severity/s0
    ai-easy
    and removed on Nov 9, 2026
  3. Ariznawlll commented on Dec 1, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过。 #32411 的修复只合入 4.2-dev,本轮只在当时官方最新 4.2-dev@efbab93eb361eabddf1fb5c012e93bec094660c1 验证。超过服务器 64 MiB 单包限制的真实 ETL writer 导入完整成功;第一批已经写入事务后注入源读取错误,最终没有残留半个文件的数据。原生测试和新增 MOTR 双 CN CI 均通过。回归 PR 尚待合入。

    关键证据

    • 研发修复 MatrixOne PR #32991 合入 4.2-dev,merge SHA 6f5a836dda918059cab782e293b73fcd7a8a3a12。GitHub compare 确认本轮运行的 efbab93eb361eabddf1fb5c012e93bec094660c1 是后继;独立服务 SELECT git_version() 返回该完整 40 位 SHA。验收前后远端 4.2-dev 指向同一 SHA。没有把仅在 main 的修复或旧 4.2.8 镜像当作本轮结果。
    • 白盒:pkg/util/export/etl/db 和 pkg/util/export 中 7 个相关根测试各执行 3 次,合计 21/21;涵盖 CSV 转义长度计算、分批事务成功/失败/提交应答丢失/过大单行、连接及调用方取消、packet 查询错误、输入记录大小上限。两个包均 go test exit 0。本轮没有把普通测试说成 race 测试。
    • 代码边界核对:WriteMergeFile 读取 @@session.max_allowed_packet,单次 SQL 上限为包预算与 24 MiB 中较小者,目标分块为 4 MiB;多块使用同一事务。源读取、执行或提交失败时不走正常成功删除路径,错误后回滚。该边界直接针对旧路径的整文件 SQL 构造与半文件重试风险。

    场景 1:超过单包上限的完整导入

    1. 在上述独立 4.2-dev 服务创建本轮专用数据库和 id INT PRIMARY KEY, payload TEXT 表。通过生产 WriteMergeFile API 流式送入 9,000 行,每行含约 8 KiB 内容,并包含引号、反斜杠、逗号、中文和换行。
    2. 实测 @@session.max_allowed_packet = 67,108,864 字节;仅 payload 就有 9,000 × 8,192 = 73,728,000 字节,已超过单包限制,必须拆成多个 LOAD DATA INLINE。
    3. 实际输出:QA32411_PASS ... packetLimit=67108864 ... successRows=9000 payloadSamples=3 totalSourceBytesApprox=73728000;COUNT(*)=9000,第 0、511、8999 行 payload 均与输入逐字节一致。真实服务测试用时 5.26 秒;此数只记录测试运行,不作为生产性能基准。

    场景 2:第一块后读取失败的原子性

    1. 使用相同的真实 MO 服务和独立表,在源回调返回第 650 行之后注入 qa injected source-read failure。前 650 行约 5.3 MiB,超过 4 MiB 目标块,因此第一块已经向事务执行。
    2. WriteMergeFile 返回该注入错误;随后另一个 SQL 查询 SELECT COUNT(*) 得到 0,没有把前一块留下。对照成功表仍有完整 9,000 行。
    3. 结束时删除本轮专用数据库,复查数据库残留数为 0;测试未更改其他运行实例或用户数据。

    回归与 CI

    • 已把真实 MO writer 回归提交到现有 MOTR 4.2-dev PR #399,commit 7e1907ca1bb5276287406df0fe8f7a3ed7ea0e7b,没有新开 MatrixOne 主库测试 PR。新增测试在 CI run 46602894525 的 metadata-two-cn-42 job 中执行;独立 4.2-dev 构建、双 CN 版本检查、原有 9/9 MOTR 用例及新增 Verify issue 32411 aggregate packet chunking and atomic rollback on real MO step 均为 success,job 最终 success。失败时保留诊断、清理容器的步骤按条件执行;没有将 skipped 的失败诊断步骤计为测试通过。
    • 为保证 4.2-dev 回归每日运行,默认分支的定时入口追加到现有 MOTR main PR #374,commit 993c701,每天 19:10 UTC(北京时间次日 03:10)调用 MOTR 4.2-dev 的实际测试工作流。调度 YAML 已通过 actionlint。两个 PR 均合入之后该每日调度才会生效;目前不声称已经发生过定时运行。

    待解决点

    本轮已覆盖修复目标的单包边界、跨多块真实写入、内容正确性与错误回滚。没有重放历史 16 GiB CN 的整套生产遥测负载,也没有把 5.26 秒单机运行时间当作生产内存或吞吐性能结论;如需衡量生产 ETL 峰值,可另做环境观测,不影响本次已证实的功能修复边界。

    最终结论:测试通过,关闭 #32411。已完成项:最新 4.2-dev 上超过 64 MiB 单包的真实导入、首块后失败回滚、21 次相关原生检查及新增 MOTR 双 CN CI;回归 PR 已提交、待合入后开启每日调度。未通过项:无。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions