Skip to content

[Bug]: Bound oversized CN spill blocks and memory for large variable-length updates #32146

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

Observed on the deployed 4.2 build v4.2.6-71498157cc-2026-10-20. The CN merge paths were also inspected on main and 4.2-dev at the commits below.

Commit ID

  • Observed build: 71498157cc21f833b8e717f45d50d1f926be3134.
  • Code inspection: main@b27f3869e6f2552311fbbdda2f62b0ca31ec3a67 and 4.2-dev@88e5fb541768ff65e2220f520e7edd9647034635.

Other Environment Information

A CN executing a large UPDATE on a table with variable-length columns; a sorted CN S3 spill writes the updated data.

Actual Behavior

On the observed build, repeated executions failed during a sorted streaming spill. The captured stack goes through:

MultiUpdate.update_s3 -> s3WriterDelegate.append -> CNS3Writer.Write
-> Sinker.Write -> trySpillMergeSortStreaming -> BlockWriter.WriteBatch
-> objectWriterV1.addBlock -> WriteWithCompress -> WriteArena.CompressBuf

The stack shows a serialized column input of 1,107,036,297 bytes (about 1.031 GiB) and an LZ4 scratch bound of 1,111,377,631 bytes (about 1.035 GiB). The old CompressBuf rounded that bound up to 2,147,483,648 bytes, exceeding the mpool single-allocation limit, and the query failed with mpool memory allocation exceed limit with requested size 2147483648.

The CN subsequently reached its container memory limit and was OOM-killed. These events are correlated; the available evidence does not establish that this particular query alone caused the OOM, identify the large column, or determine whether the 1.031 GiB vector came from one row or multiple rows.

The rounding defect is already tracked by #32051 and fixed in main by #32052 and in 4.2-dev by #32081; the deployed build predates both fixes. Those changes also add byte-aware output to the TN merge/reshape paths. This issue concerns the separate CN sorted spill path and its memory behavior after those fixes, not a request to duplicate the rounding fix.

In the inspected main and 4.2-dev versions, Sinker.trySpillMergeSortStreaming calls mergeutil.MergeSortBatches; its output is flushed at BlockMaxRows (8192 rows) or at the end, rather than at a byte threshold. The current main version also has a disjoint-range fast path with a row-count boundary. A row limit does not bound the size of variable-length columns. The staging threshold is checked after adding a batch and is not itself a bound on the size of an individual output block.

Main also contains an optional chunked-column writer policy; its effective rollout and coverage for this CN path must be checked during validation. Source inspection identifies the remaining large-block risk; it does not establish that the exact old 2 GiB error or the OOM reproduces on current main or 4.2-dev.

Expected Behavior

CN spill and object writing should handle large or skewed variable-length input without an avoidable oversized block, excessive memory amplification, or failure solely due to speculative capacity growth. Correctness, row order and transactional semantics must be preserved. A single indivisible large row and real resource exhaustion need explicit, safe handling; a soft byte threshold alone cannot guarantee a hard memory bound.

Steps to Reproduce

Observed on the build listed above:

  1. Execute a large update against a table with variable-length columns and trigger a sorted CN spill.
  2. A spill reaches WriteWithCompress with a roughly 1.031 GiB serialized column.
  3. The old capacity rounding requests 2 GiB from mpool and the query fails.

The precise data distribution and minimal standalone SQL reproducer for this incident have not yet been established. On current branches, construct deterministic CN-sinker coverage with skewed variable-length values and instrument output block sizes and peak memory; separately test the applicable chunked-column policy. Do not treat the old-build failure as proof of the same failure on a fixed build.

Additional information

Investigate a byte-aware boundary in the existing CN output path, including both general and disjoint-range merges, without unnecessarily duplicating storage or execution paths. Evaluate the cost of checking size for ordinary rows and wide schemas. Account for input batches and serialization/compression scratch buffers, and verify whether oversized reusable buffers remain retained after success, cancellation, and errors on each branch.

Validation should cover values and ordering, update correctness, large/skewed values including a single oversized row, full and partial blocks, spill failure/cancellation, resource cleanup and retry, as well as normal-workload performance. Confirm what happens when the compression bound itself exceeds the allocator limit; changing the 2 GiB mpool limit alone is not a memory-bound solution.

Activity

  1. self-assigned this
    on Nov 4, 2026
  2. added
    kind/bug
    on Nov 4, 2026
  3. XuPeng-SH commented on Nov 6, 2026

    @XuPeng-SH
    ContributorAuthor

    QA 交接(main 的已合并范围,待验证)

    PR #32188 已合入 main,merge SHA 57e7871e500e6e3d35fd352a092ee41b03a979fc。CN data/tombstone spill 在复制前按 materialized bytes 分段,保留单个超大行及已有对象/块格式,配合 workspace publication/cleanup ownership;另含 reconnect acknowledgement 和 sequence expiry identity 修复。

    已读 issue 全评论及完整 PR 讨论。后续审查未留未完成的本 issue 开发项;旧部署 2 GiB 分配失败/OOM 不能直接归为当前版本反例,也没有证明该查询单独导致生产 OOM。

    真实证据归属:作者及早期审查报告拥有者包 normal/race、重复并发测试、一 CN SQL/回滚和受控内存/对象数对照;最新审查在对应 reviewed head 执行了5个 sequence 回归 normal/race及各100次 race,spill/reconnect 部分复用未变源代码的旧结果。一次小 tmpfs spill-budget 失败随后 full-package/isolated 重跑通过,触发未明。最终 head build 成功,UT/coverage/SCA/BVT 取消、CI Required 失败。以上均不是本轮执行;本轮没有本地实测或完整 CI 通过声明。

    请 @Ariznawlll 验证一般/不相交范围及 sorted/unsorted spill、宽变长与单超大行、数据顺序/事务更新、完整/末尾块、多对象/tombstone handoff、取消/失败/cleanup retry、reset/rebind和保留的早期事务语句,并复核 reconnect/sequence 边界。按真实存储记录性能、峰值和保留内存,不只记录逻辑阈值。

    边界:这是 materialized-run 软预算,不是 RSS/全 pipeline/arena 硬上限;单行可超限,FileService 取消需协作,失败的 unbound cleanup owner 被丢弃可能留孤儿,shared arena 可保留 scratch,更多对象有性能成本。崩溃恢复、多 CN、真实生产负载及历史部署效果未建立。本次转测不表示这些边界已验收,也不自动要求 4.2 backport。

  4. slyunnn commented on Nov 6, 2026

    @slyunnn

    Regression and extended verification for #32146 (2026-11-06)

    Verification Environment

    • MatrixOne main, frozen from the remote at the start of testing: b6c57d315c8d1df2aca40ab19dee72136e6f2f81, fix(disttae): preserve optimistic RC write dependencies across snapshot advances (fix(disttae): preserve optimistic RC write dependencies across snapshot advances #32174).
    • Clean native build, macOS/arm64, Go 1.27.1. Binary build information and git_version() at every SQL endpoint identified b6c57d315c; the owned service was restarted before the accepted runs. No MatrixOne tracked source or configuration was changed.
    • Local topology: 3 CN / 1 TN / 1 Log service / Proxy, with a common DISK-V2 SHARED store. Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, CN2 127.0.0.1:16002, and CN3 127.0.0.1:16003 were all reachable. Endpoint-specific execution is listed below.
    • Public SQL used PyMySQL text protocol and the existing Connector/J BVT runner. Mechanism, fault and resource tests ran against the same frozen source with the repository CGo wrapper. One-off probes used external Go overlays, leaving the source tree clean.

    What Was Covered

    • OK — Reconstructed the CN spill boundary from the reported risk; the incident has no standalone production SQL/data reproducer. Tested sorted/unsorted and general/disjoint-range spills, aliased/constant/short-constant values, borrowed windows, full blocks and the last partial block, and exact-budget/one-byte-over/indivisible-row boundaries. Persisted readback checks values, nulls, IDs and sort order.
    • OK — Existing cn_spill_byte_bound.sql passed 34/34 statements, twice at each of Proxy, CN1 and CN2. It checks multiple physical objects, update commit/rollback and variable-length-key delete/rollback. CN3 connectivity is separate from this BVT execution evidence.
    • OK — At the normal 128 MiB CN budget, real SQL on each of Proxy, CN1 and CN2 populated sorted and unsorted LONGTEXT tables with 1,024 rows of 192 KiB each (192 MiB per fixture). Each produced 2 initial objects. UPDATE visibility, rollback to original contents, commit and reads through all three endpoints passed.
    • OK — A real DISK-V2 sinker comparison with 2 rows of 96 MiB each produced 1 object without bounded runs versus 2 with bounded runs. Full payload readback passed. Observed operation-owned peak live bytes were 403111936 versus 201785344; this is a pool/resource observation, not process RSS or total query memory.
    • OK — A single 136 MiB row remained one correctly readable object, demonstrating the documented soft-budget exception. The bounded oversized-row probe released retained pool bytes on Reset; all probe modes reached 0 pool bytes after Close and input cleanup. The wide two-row bounded probe still retained 201785344 pool bytes after Reset, so Reset is not a general zero-retention guarantee.
    • OK — Exercised multi-object tombstone handoff, write/sort failure, cancellation, successful sibling draining, unpublished-object cleanup retry, missing-file confirmation, workspace ownership, reset/rebind and preservation of earlier transaction statements. Normal owning-package tests passed; objectio/ioutil and disttae full-package race runs passed. Three critical spill failure/cancel/reset cases each passed 100 separate in-process race repetitions.
    • OK — Actual reconnect integration verified rollback and a fresh successful transaction. Five sequence retry/expiry identity cases passed race mode and adaptive repeat stress (50 repetitions for terminal identity, 100 each for the other cases). Normal compile-package evidence was reused from the same unchanged commit.
    • OK — Existing WriteArena allocation-boundary and per-writer chunked-column rollout tests passed. The live SQL run used the default deployment policy; optional rollout combinations were not forced on this cluster.
    • OK — On the real local filesystem, an 8,192-row ordinary fixture was measured in alternating bounded/unbounded order for 4 rounds. Median Write/Sync time was approximately 7.92 ms bounded versus 7.14 ms unbounded. This small shared-host probe shows an observed cost, not a production performance SLO or a speedup claim.
    • Not covered — The historical 4.2 deployment, original unknown incident data/query distribution, production OOM causality, hard RSS bounds, crash recovery and a TKE production-load benchmark.

    Findings

    Fix: PR #32188, 57e7871e500e6e3d35fd352a092ee41b03a979fc, fix: bound CN spill runs by materialized bytes. The tested main contains this fix.

    The materialized-byte boundary is applied before copying ordinary CN data/tombstone spill runs. Correctness and transaction/failure ownership checks passed. The contract is a soft run budget: one indivisible row can exceed it, input/compression/shared-arena memory can remain significant, and FileService cancellation requires cooperation. This does not establish a hard bound for the entire pipeline or show that a historical production OOM had a single cause.

    MOTR / BVT Coverage

    Reused the maintained cn_spill_byte_bound.sql and owning-package regressions; no duplicate MOTR case was added. The live BVT/fault scenarios ran serially because they mutate fault points and the BVT runner performs database cleanup. Unit processes used independent fixtures; pipeline/concurrency paths were tested directly rather than inferred from runner -j.

    Large-data regression: required and completed locally at the relevant byte boundary, using 192 MiB SQL fixtures, the 2 × 96 MiB disk comparison and the indivisible 136 MiB row. More unrelated rows or an arbitrary TKE volume increase would not strengthen the byte-boundary assertion. Test databases were removed and the owned cluster shut down cleanly.

    Final Conclusion

    Fixed for the main CN spill materialized-run budget and lifecycle contract verified above. This conclusion does not assert historical 4.2 backport behavior, zero performance overhead or a hard process-memory/OOM guarantee.

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions