Skip to content

fix(import): bound repeated-import memory on 4.1.6 hotfix - #31166

Merged
XuPeng-SH merged 5 commits into
4.1.6-hotfixfrom
fix/4.1.6-hotfix20261021-import-memory
Oct 27, 2026
Merged

XuPeng-SH merged 5 commits into
4.1.6-hotfixfrom
fix/4.1.6-hotfix20261021-import-memory

Conversation

@aptend

@aptend aptend commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #26992 (large-table LOAD failures/OOM). The original customer incident is not claimed closed.

What this PR does / why we need it:

连续导入时,上一张表提交后,Writer、异步 IO、Pipeline 借用资源及 allocator 驻留仍会占用下一次分配所需的空间。固定表序实验中,stock v4.1.6 第一轮 39 张表成功,第二轮第 24 张表 OOM kill。本 PR 约束同时存活的导入工作集,并将预约释放与实际消费、任务结束及资源销毁对齐。

实现范围

  • 用实际容量约束 CSV raw/typed batch、Writer/索引/元数据和异步 IO;由同一进程协调输入/输出预约、保留数据和共享 IO workspace,压力下回收可释放的 Go/native/Arena 空间。候选单位和 DOP 按预算调整,初始等待可以取消。
  • CSV 将“最大合法行”与“当前预约的行宽”分开:初始行宽预算随候选批次大小缩放,并以现有读块为下限、合法行长为上限;超出已预约预算时,先原子增加完整 producer/输入/输出/IO 预约,再扩展缓冲。文件总大小或 LOCAL 身份不会直接迫使短行预约全局最大行。保留配置行长限制;执行中的扩容不带着下游依赖排队。混合写入元数据、join spill/skew 读取增长后的额度,纯 INSERT 帧仍遵守原有单位上限。
  • 保留目标 hotfix 的 durable terminal 协议,处理借用数据、部分发布、取消、Reset/Free 和重试代际;PartitionMultiUpdate 的完成行数保留到编译器读取,下一次 Prepare 才重置。
  • 导入 HashBuild/HashJoin 的预算及输出单位由 ImportMemory 作用域控制。CSV/merge 复用已有容量,增长时精确预测;Writer 几何搜索字节窗口;完整 owned vector 暖拷贝复用已有 area,窗口保留精确边界;字符串哈希迭代器保留有界小缓冲,避免短尾批反复分配。

准入适用于有完整内存契约的本地执行图。Prepared、远端图及未证明边界的算子/表达式整体保留 legacy 路径;不可达的分布式准入扩展已移除。没有客户库表名、Q9 编号、特定数据集分支或新增调优开关;没有修改目标分支的 wire/catalog 格式。设计见 import-memory-control.md。

目标 4.1.6-hotfix,基线 4a55b83aa2cf51144970a17fd269350c522eaeef(含 #30977);HEAD 75d9cd343d337a7efc6bf62b58234ab0d99ecf0e,共 5 个提交,author/committer 均为 aptend。

Review 修复与验证

  • JSON 准入意见:真实 CREATE/LOAD parser→planner→compiler、独立 coordinator、固定空闲 4 GiB 样本,覆盖 1 MiB LOCAL、12 MiB 普通短行 JSON CSV 的等待/不等待模式和 TEXT 对照。恢复旧准入代码时,四个 LOCAL/大文件用例均拒绝;修补后通过。运行时覆盖扩容前预约、取消/拒绝不发布部分额度、并发扩容不缩小预约、关闭与最后 owner 释放。
  • 实际 4 GiB 服务验证:12/12 场景通过。普通/LOCAL、1 MiB/12 MiB、自动提交/显式事务均完成并核对行数、NULL、列值和 JSON 内容;短行之后的宽行成功,超大行被内存边界拒绝后仍能继续导入。峰值约 1.52 GiB,OOM/重启均为 0。未修改产品阈值或计划统计。
  • checkptr 意见:UnionBatch 改为取有效切片元素地址,避免最后一次循环产生分配边界之外的指针,保留批量 header/area 拷贝;旧代码边界反例及修补后的普通/race 验证已留档。
  • 其余已处理意见:CSV 缺失字段仍遵守严格/宽松/LOCAL 语义;分区 affected rows 生命周期正确;fake Try 非阻塞且不依赖测试主机内存;修复整批暖拷贝和 256+1 行字符串哈希的多余开销;无符号物理样本采用饱和转换。
  • 本次 9 个受影响/直接消费包完整普通及 race 测试通过,0 跳过;并发扩容/关闭用例 race 连续 100 次通过;36 包增量 gofmt/golangci/vet 及新增消费方复查通过。既有公开 LOAD/external BVT 的 614 条通过记录属于 983d555043,没有重新标为本 HEAD 的运行。

上一 HEAD e5d4c87174 的 远端 UT仍有 5 个嵌入式集群启动/连接超时用例失败,已无此前的 checkptr 崩溃;这 5 个用例在当前源码下逐个本地 race 通过。远端超时的确切原因仍未确认,不能以本地通过替代完整 CI。CodeQL Java/JS 另有未提取到对应语言源码的 configuration error,未将其算作已修复。当前 HEAD 的远端 CI/人工复核仍需完成。

连续导入验收

中间版本 70c7567747 的五轮最终完成,但第三轮有一次扩容失败并被脚本自动重试,因此该次验收判定失败,未计为通过。定位到 64 MiB 批次仅预留 64 KiB 行宽预算,约 169 KiB 的正常行还需临时追加预约;现改为候选批次与行宽预算同步缩放,新增公开编译入口断言在旧代码上稳定失败。

使用原始 Amway 导入函数,函数未修改,外层固定表序连续调用。LOAD DATA LOCAL INFILE、parallel=false,保留 inline indexes。每轮 39 张有忠实 DDL 的表,1,386,204 行、26,449,821,357 CSV 字节;报告另 14 张表缺少忠实 DDL,不计入通过范围。

本地 CN/TN/Log 同进程,22 GiB 硬上限、swap=0、4 CPU quota、GOMAXPROCS=4、GOMEMLIMIT=8GiB,新私有目录。当前 75d9cd343d 连续 5/5 轮、195/195 次导入成功,同一 PID;无 OOM、重启、导入重试、外部强制 GC 或轮间刻意等待。采样 RSS 峰值 8.50 GiB,cgroup 峰值 12.96 GiB;五轮完整导入函数耗时分别 270.3 / 255.5 / 351.7 / 301.9 / 291.8 秒。事后当前/上一代行数、临时表、最大表的 B-tree/fulltext 索引及准入 owner 归零检查全部通过。导入刚完成时 I/W 及等待队列已归零,全进程共享 D 仍为 1.02 GiB;随后保持服务运行、未强制 GC,D 自然归零,再次进行的 129 项事后检查全部通过。首次检查失败的记录保留。构建源码、二进制哈希和验收 commit 对应关系已留档。

对照记录:stock v4.1.6 3c7eb8de7f 第一轮成功,第二轮第 24 张表 OOM kill(systemd 确认);上一修补版 983d555043 也完成 5 轮,采样峰值 RSS/cgroup 为 8.42/15.29 GiB。两份旧记录保持各自源码身份。

性能证据与限制

当前版本的整轮导入性能仍待确认:同机、同配置、同输入和表序,使用新私有目录追加的一轮 983d555043 对照耗时 245.7 秒,本 HEAD 第一轮为 270.3 秒,约 +10.0%。这是各一轮、非交错对照,不能单独判定原因,也未用背景任务解释来消除这项差异。

之前同一测试二进制中的 base/修改前/修改后交错基准,确认 UnionBatch 暖拷贝和字符串哈希局部成本恢复到 hotfix 基线附近。8192×32B UnionBatch 中位数为 13.416/22.526/13.477 µs;256+1 行 Find 为 3.196/12.688/3.222 µs,短批分配从约 256 次恢复到基线的 2 次。随后安全指针寻址的 8192 行对照为约 17.93→18.83 µs,0 B/op、0 allocs/op。这些是局部证据,不能替代整轮吞吐验证。

983d555043 的 TKE 40289352875已经完成,100G/1T 查询结果检查通过。统一采用 Runner 耗时、去掉 warmup,与同配置 hotfix1021 历史运行 39559943872 比较:

指标 hotfix1021 历史记录 983d 运行 差异
100G Q9 中位数 7.085 s 8.435 s +19.1%
1T Q9 中位数 92.144 s 97.153 s +5.4%
100G 每轮 22 题总时长中位数 83.709 s 89.415 s +6.8%
1T 每轮 22 题总时长中位数 994.717 s 1022.850 s +2.8%

该次 1T 的 3 个 Q9 时间窗内未检索到此前的 entering spill mode 日志;这不等于全运行无 spill 的完整证明。历史源码 ed9d8aacc7 与当前 hotfix 基线存在提交差异,且 1T 只有 2 个计时样本;仍不能将性能差异归因于本 PR,也不能宣布性能无回退。新 HEAD 的同配置 TKE 已触发:40328334381,结果待完成。 沿用 3 CN×14 CPU/55 GiB、TN 14 CPU/55 GiB 和原 cache/GOMEMLIMIT 配置;没有触发新的 hotfix1021 基线。

证据保存于实验机 evidence/review-fixes-20261023/hotfix20261021-integration/review-followup-20261026/json-admission-fix-20261026/;初次失败及 harness 修正记录保留,不计入通过范围。客户数据、profile 和原始日志未上传。

当前行的不可缩减预约确实不能容纳时,仍会返回有界内存错误;执行中扩容不会等待自己持有的下游资源。预约归零不等于全部 Go/native 对象都无泄漏,legacy SQL 不受完整工作集保证。未复现客户跨 CN 卡死的完整状态;单机导入也缺少新的同条件 stock 多轮吞吐对照,未据此宣称性能无回退。

Bound CSV input, writer/index buffers, retained allocations and IO workspaces by owned capacity. Reclaim idle arenas and native memory under physical pressure, preserve LOAD results and explicit-transaction progress, and resolve cgroup limits through visible mount roots.

Coalesce the original import-memory implementation and its lifecycle, admission and accounting corrections with their regression tests and design contract.
Integrate import budgets with the hotfix pipeline terminal protocol. Retain published and saved buffers until joined retirement, charge final pipeline metadata, and close cancellation, retry and remote control ownership paths.

Keep metadata-fixture initialization and deterministic pipeline/transport regression coverage with this lifecycle change.
Apply controlled output limits only to admitted imports and preserve ordinary join output behavior. Track retained batch capacity without rescanning it for each append, cover reset/copy failure ownership, and report hashbuild spill triggers.

Preserve the existing matched hotfix1021 performance-reference policy. The two later spill-policy experiments are excluded.
Keep one local manifest and admission entry point, with whole-statement fallback for remote graphs. Remove dormant control streams, capability discovery, token owners and their dedicated tests.

Derive ticket retirement from the root and live input/IO owners. Consolidate public LOAD setup and equivalent test cases while retaining active bounds, cancellation and joined cleanup oracles.
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Keep capacity forecasts on growth paths, reuse bounded key buffers, and
retain completed affected-row results through pipeline cleanup. Bound known
CSV inputs before parsing and propagate their producer limits into admission.
Make compiler fixtures deterministic and align errors and license headers
with repository checks.

Keep varlena header rebasing within valid elements under checkptr, covering
whole copies and partial copies at the destination allocation boundary.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复核最新 75d9cd343d,基线 4a55b83aa2。本轮未确认新的可复现代码阻塞;继续 Request Changes 的原因是此前约定的性能验收尚未闭环。

剩余验收项

  1. 请补齐精确 base/HEAD 的同配置、同输入、重复交错性能对照,覆盖连续 LOAD 和普通查询。PR 中的一轮旧头 245.7s / 新头 270.3s,以及历史 hotfix1021 的 TPCH 差异,目前都不足以归因,也不足以认定无回退。最新 TKE 40328334381 已完成,1G/10G/100G/1T 结果检查通过;100G 三轮总耗时 96.494/94.550/96.088s,1T 两轮 1059.826/1058.300s。日志中的性能判断门槛是总耗时相对历史不超过 +25%,不能替代本 PR 的性能验收。若对照差异稳定存在,再结合 profile 定位并修复。没有把这些历史差异标成已经证明的性能缺陷。
  2. 当前 UT 的明确失败信息是 self-hosted runner lost communication,Unit Testing 没有正常终态、后续诊断未执行,UT 日志不可下载。需恢复后完成当前 HEAD 的完整 UT;现有信息不能确定具体用例、OOM/网络根因或与 PR 的关系。此前另一 HEAD 的嵌入式超时不能套用到这次。

已验证修复与设计复核

  • JSON/LOCAL 最低预约与 checkptr 两条遗留代码问题已本地复核并更新 conversation;全部已有 inline threads 现已 resolved。其余旧代码问题的修复保持有效。
  • 统一进程准入、完整布局先预约再扩容、扩容不等待下游、借用资源按实际 owner 退休的方向合理。未知/远端/prepared 图整体 fallback,普通 shuffle 不做导入专用 forecast,没有新发现的重复状态机或需要立即删除的无效分支。
  • 本地 10 个相关包的 race 验证通过:rscthrottler/vector/csvparser 为完整包,其余为针对性选择。包括真实 LOAD 编译入口、增长拒绝/取消/关闭、spool/直接边终态、广播参与者失败、十种 join 语义及跨 chunk 重复键。最新远端 SCA、coverage、两组 BVT 通过。没有把这些局部测试宣称为全仓 UT 已通过。
  • 实现净增 11,596 行、测试净增 13,001 行、设计文档 +309 行,维护成本仍然很大;真实入口与独立 join oracle 有价值,但测试体量不替代性能证明。共享 mpool 记账也影响普通 alloc/free,本地同二进制微基准观察到额外纳秒级成本;它仅说明有公共路径成本,不能换算成 SQL 回退比例。

完整 PR 的发布验收仍不能给 PASS;待上述对照和当前 UT 闭环后再决定 approve。

@aptend

aptend commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

回复这轮 Request Changes,补齐最新结果,并明确本次验收决定。评审对象仍为 75d9cd343d337a7efc6bf62b58234ab0d99ecf0e。

性能对照与验收

沿用既定同配置 hotfix1021 历史基线:ed9d8aacc7 的 39559943872,与最新 75d9cd343d 的 40328334381 直接比较。两次均为 3 CN × 14 CPU/55 GiB、TN 14 CPU/55 GiB,沿用相同 cache/GOMEMLIMIT 配置。该参照的版本身份保持为 hotfix1021,精确 PR base 仍是 4a55b83aa2。

以下均已从原始 job 日志复算,单位为秒。LOAD 为 8 张表成功导入 SQL 的耗时合计;查询排除 warmup,累加全部正式计时轮次的全部 22 题,不使用中位数。

指标 hotfix1021 历史基线 最新 75d9cd3 耗时增加
100G LOAD:8 张表 276.669 315.077 13.88%
1T LOAD:8 张表 2557.006 2869.103 12.21%
100G 查询:3 轮、66 次 250.008 287.132 14.85%
1T 查询:2 轮、44 次 1989.433 2118.126 6.47%
查询合计:110 次 2239.441 2405.258 7.40%

本次明确接受表中的实际开销,认为它们在连续导入内存治理的合理范围内。当前 HEAD 已完成 22 GiB 限额下连续 5 轮、195 次导入,无 OOM、重启、导入重试或轮间刻意等待,峰值 RSS/cgroup 为 8.50/12.96 GiB;最新 TKE 的查询结果检查也已通过。结合这些收益与上面的完整耗时对照,性能项按此验收,不再要求追加精确 base/HEAD 的交错 TKE 实验。该决定基于实际差值及修复收益,不是仅引用 workflow 的 +25% 门槛。

UT 的处理范围

本次 UT runner OOM 按 4.1.6 旧 UT 流程问题独立处理,不作为本 PR 的阻塞项。两次失败 attempt 1、attempt 2 都已通过对应 runner pod 的历史监控确认 OOMKilled;第一轮 16 GiB 上限下 working set 达到 15.997 GiB,随后 runner 失联。

外层虽然调用 CI@main,但检出 PR 后执行的是 4.1.6 分支自身的 Makefile/optools/run_ut.sh;这些入口相对精确 base 没有改动,仍为全包统一并行的 race 流程,未包含 main 后续的分组调度、测试集群准入和分批进程回收。该流程治理单独推进,不将整套 main CI 优化回迁作为本 PR 的合入前提。这里是验收范围决定,未将中断的全仓 UT 记为通过;现有受影响包完整普通/race 验证,以及远端 SCA、coverage、两组 BVT 的通过记录继续保留各自覆盖范围。

上一轮代码问题已由 reviewer 复核,8 个 inline threads 均已 resolved。请基于当前 HEAD、以上性能对照和明确的验收决定重新评审。

@aptend
aptend requested a review from XuPeng-SH October 27, 2026 06:49

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — re-reviewed head 75d9cd343d337a7efc6bf62b58234ab0d99ecf0e against hotfix base 4a55b83aa2cf51144970a17fd269350c522eaeef. No subagents or production edits.

The eight historical inline issues are actually addressed in the current source, including short CSV rows, partition affected-row lifetime, nonblocking admission fixtures, short JSON LOAD admission, vector/hashmap fast-path costs, and checkptr-safe vector copying. No new reproducible implementation blocker was established in the additional ownership, cancellation, bounded-growth and spill-read checks.

The design has a coherent authority: the existing memory coordinator owns admission and input/output/IO promises; actual retained allocations stay charged to their owners until cleanup. Complete-graph eligibility and whole-statement legacy fallback avoid pretending unsupported/prepared/remote graphs are bounded. The change is substantial: implementation +12,559/-963, tests +13,183/-182, design +309. These are real maintenance costs, justified by the broader live-working-set guarantee rather than by test line count.

Validation: reused the unchanged head's previously verified local race results across ten affected packages (three full suites, seven focused selections), plus exact-head remote SCA, coverage, pessimistic/proxy BVT and TKE result checks. Added an independent local race/checkptr probe with 6,948 stream cases: every truncation offset, known/opaque readers, Go/native allocations, destination reuse/growth, NULL/empty/varlen values. Short reads all fail cleanly; successful reads preserve the fixed logical oracle; each cleanup leaves zero allocated bytes. Temporary probes/logs remain outside tracked source. This does not claim a new full-repository test run.

Performance closure follows the explicit owner decision: the measured historical-baseline LOAD +12–14% and query +6–15% costs are accepted for bounded repeated-import memory. That is an engineering tradeoff, not evidence of zero regression; the historical baseline is not the exact PR base. The previous vector/hashmap regressions remain fixed, while common allocator accounting still has measurable per-operation cost.

Whole-repository UT is still failed/interrupted. The author reports runner OOMKilled; I have not independently obtained the underlying pod metrics, and unchanged test scripts alone do not prove PR independence. This code approval does not mark UT green, waive CI Required, or authorize merging despite repository gates.

@XuPeng-SH
XuPeng-SH merged commit afb45de into 4.1.6-hotfix Oct 27, 2026
52 of 58 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/4.1.6-hotfix20261021-import-memory branch October 27, 2026 08:52
XuPeng-SH pushed a commit that referenced this pull request Nov 1, 2026
…ions (#31810)

## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #26992; performance follow-up to #31166.

## What this PR does / why we need it:

Bounded CSV imports can spend excessive time flushing small writer
windows and waiting for each upload. Array-valued fields also allocate a
normalized string and a temporary split slice for every value. This
change reduces those costs while retaining the existing admission and
cleanup guarantees.

- Separate writer batching from source framing, accounting for every
index projection and preserving the existing source/output-frame bounds.
- Reserve each encoding/upload peak within the shared W budget. Transfer
buffers, private pools and leases to existing SinkPool jobs; let
already-admitted borrowed uploads continue after returning the caller's
W. Keep synchronous fallback when another upload cannot be admitted,
stable MultiUpdate pool ownership, and joined error/cancel/Reset
cleanup.
- Scan array-literal token views with one result allocation, preserving
ASCII-space handling, dimension checks, float precision/result bits and
error text.

No new worker pool, tuning switch or dataset-specific threshold.
Persistent formats and ordinary join spill thresholds are unchanged.
[Consolidated
design](https://github.com/aptend/matrixone/blob/61eb095c019daef384d0eb1ecb119a057a023082/docs/design/import-memory-control.md).

### TKE evidence

Original Amway importer, 39 tables x 4 continuous rounds. Input hashes,
schema/indexes/order, pinned client image, Python/PyMySQL versions and
deployment settings match: 2 CNs, each 20 GiB/10 CPU, 2 GiB memory
cache, GOMEMLIMIT=16000MiB. Values below sum all 156 `import_seconds`,
excluding DDL and preparation.

| Measured source | Run | Total import time |
| --- | --- | ---: |
| Historical hotfix before memory admission, `ed9d8aa` | [40467595909,
attempt
2](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/40467595909/attempts/2)
| 1348.209 s |
| Historical bounded-memory hotfix, `75d9cd343d` | [40480188049, attempt
4](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/40480188049/attempts/4)
| 2092.413 s |
| Intermediate pipeline implementation, `cb4788b` |
[40843320353](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/40843320353)
| 1622.459 s |
| Complete optimization, `8ef38e7` |
[40891622421](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/40891622421)
| **1426.814 s** |

The complete optimization is **31.81% faster than the historical
bounded-memory hotfix** and **12.06% faster than the intermediate
pipeline implementation**. It remains 5.83% above the
pre-memory-admission historical time. These are sequential historical
comparisons, not a new execution of target `dc4e7ee070`.

Latest run: **156/156 imports and row-count checks passed**, zero
retries/OOM/restarts. Against the intermediate run, the two CNs'
combined sampled RSS peak was 3.49 -> 3.56 GiB. The comprehensive
table's round-2 array-parser cumulative allocation profile decreased
from 17.84 to 3.26 GiB; these are allocated bytes, not resident memory.

### Validation and source identity

- Local 22 GiB/no-swap acceptance: **5 continuous rounds, 195/195
successful imports, 6,931,020 verified rows**, same PID, no
retries/OOM/restarts or forced GC/inter-round pauses; I/D/W returned to
zero after every round. Full importer time: 1272.35 -> 1128.88 s versus
the intermediate implementation (-11.28%). Sampled RSS/cgroup peaks:
7.77/10.83 GiB.
- Owning-package and affected-consumer tests, incremental vet/lint
passed. Five affected lifecycle tests each passed `-race -count=100`;
both writer packages passed whole-package race runs. Array-parser
differential fuzzing passed 52,772 executions in 30 seconds.
- Target: `4.1.6-hotfix` at `dc4e7ee070`; delivery: `61eb095c01`, **5
commits**. Workload measurements above executed `8ef38e7`; the initial
`d866e8b5c0` delivery changed only documentation/history. The review fix
below changes Insert metadata framing and adds regression tests. Those
full native/TKE workloads have not been rerun on this framing-fix head;
their original source identities remain unchanged.

### Review fix: bounded Insert metadata frames

Completed uploads could be combined into one Insert metadata frame and
exceed the unchanged source-derived limit. Insert now spools one
complete object per frame for incremental collection and final Sync,
preserving all object/block metadata without increasing frame/I limits.

Fresh validation: a 15-object/512-block-per-object metadata burst
crosses the frame bound without allocating source rows; empty,
single-object and oversized-object rejection controls also pass.
Existing real-LocalFS tests cover incremental/final collection,
zero/ordinary D credits and cancellation. These assertions fail on the
previous code and pass with the fix. The affected pipeline test passed
`-race -count=100`; whole Insert race, normal Insert/colexec/MergeBlock
tests, vet and lint passed.
XuPeng-SH pushed a commit that referenced this pull request Nov 10, 2026
…32241)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #26992 and #32146. Follow up #31166 and #31810.

## What this PR does / why we need it:

Preserve bounded import memory, persisted object layout and publication
progress. Head `da633c5deb873932dfd728ad04a30a3886e54561` is based on
`4.1.6-hotfix@a5a8ed4`, with five
commits. [Maintained
design](https://github.com/aptend/matrixone/blob/da633c5deb873932dfd728ad04a30a3886e54561/docs/design/import-memory-control.md).
Paired release PR: #32065.

- Legacy partition EOF preflush retires all source D before replay,
avoiding sibling self-wait. Until a complete metadata frame is handed
off, the existing sinker/block-info/spool owns its successful objects.
Partial flush, cancellation and failed decode remove only unhanded
files; Free/Reset share one bounded cleanup deadline across partitions.
Compact cleanup names stay in the existing private spool, avoiding a
second object registry.
- Protected publication Apply observes an atomic worker TTL/notification
snapshot. Earlier/later renewal and unregister wake its existing
expiration observer; stale replies from removed registrations cannot
update a replacement. Exit cancels and joins the observer. Source-buffer
admission, fixed-name tombstone layout and accepted-worker ownership are
retained.
- INSERT/MultiUpdate keep admitted compact metadata in memory, migrating
unread records to the configured LOCAL spill service only on capacity
denial. Legacy/raw-delete output streams per frame with
delete-before-insert order. Files no longer use OS TMPDIR. Persistent
object and transaction protocols are retained; no new setting, worker
pool or polling interval is added.

4.1 retains its cancellable legacy D policy. It has no native
statement/CN spill-disk admission API; temporary-volume capacity remains
a deployment requirement. This PR does not backport the 4.2 spill-budget
framework.

Impact: 18 production Go files versus the release base; this correction
touches 8. Shared writer/admission and publication paths include
ordinary DML/publication; this is not a LOAD-only change. This
correction adds no planner, allocator hot-path or merge-policy change.

Validation:

- Physical LocalFS regressions cover late write failure/cancellation,
Reset, partial consumer handoff, successful INSERT handoff, failed
decode and successful-upload prefixes. Actual handed-off files remain;
producer-owned files are removed. Earlier original-behavior overlays
fail the ownership/TTL runtime oracles. The cleanup-deadline regression
also fails before sharing the deadline.
- Real worker/coordinator/FilterObject virtual-time tests cover expiry,
extension, shortening, unregister, parent cancellation and stale renewal
generations. The directly affected TTL/renewal tests pass 100
repetitions; final partition tests pass 100 repetitions per branch.
- Final `insert`, `multi_update`, and `colexec` owning packages pass
normal and race modes (266 named tests each). Unchanged
publication/ioutil code retains the full owning-package normal/race
evidence from this correction. Native binaries embed this final commit
and pass 20 SQL statements each: two partitions, 36,000 committed rows
plus same-transaction rows, exact counts/sums, DELETE, rollback/commit
and teardown. Test services are stopped and generated data is removed.
This is a functional control, not a SQL low-memory failure reproduction
or a current-head throughput result.
- Local SCA compares against latest fetched
`main@00da052`. Its incremental
selector selects `./...`, including tests and reverse dependencies; Go
1.26.4, CGO and built thirdparties artifacts are used. Repository-pinned
molint `222a0b8adf07` and golangci-lint v2.6.2 pass; lint reports zero
issues:

```sh
go vet -mod=readonly -p=2 ./...
go vet -mod=readonly -p=2 -vettool=/d/mo-worktrees/v42-import-memory-lab-20261103/bin/molint ./...
golangci-lint run --timeout=25m --concurrency=2 --new-from-rev=00da05219fb8dce0266de4efa7c4bbfac06491de -c .golangci.yml ./...
make err-check
```

License/header checks and native builds pass. New GitHub CI and
re-review are pending.

Historical acceptance keeps its original revision: `968a69d` completed
two continuous Amway rounds /78 imports (39 tables), 22-GiB cap, RSS HWM
7.789 GiB and cgroup peak 18.641 GiB. Earlier five-round acceptance is a
separate revision. No current-head full-workload performance claim is
made.
XuPeng-SH pushed a commit that referenced this pull request Nov 11, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #26992 and #32146. Port #31166 and #31810 together.

## What this PR does / why we need it:

Port #31166 and #31810 together while preserving native 4.2
allocation-owned HashBuild, SpillEngine, PipelineEdge, scheduling and
RETURNING behavior. Supported local CSV graphs reserve
producer/data/upload memory; unsupported graphs retain whole-statement
fallback. Head `9a2948051e43ea3ad5d49e5651dfa9e62a5f01ec` is based on
`4.2-dev@c0532d1`, with five commits.
[Maintained
design](https://github.com/aptend/matrixone/blob/9a2948051e43ea3ad5d49e5651dfa9e62a5f01ec/docs/design/import-memory-control.md).
Paired release PR: #32241.

- Legacy partition EOF preflush retires all source D before replay,
avoiding sibling self-wait. Until a complete metadata frame is handed
off, the existing sinker/block-info/spool owns its successful objects.
Partial flush, cancellation and failed decode remove only unhanded
files; Free/Reset share one bounded cleanup deadline across partitions.
Compact cleanup names stay in the existing private spool, avoiding a
second object registry.
- Protected publication Apply observes an atomic worker TTL/notification
snapshot. Earlier/later renewal and unregister wake its existing
expiration observer; stale replies from removed registrations cannot
update a replacement. Exit cancels and joins the observer. Source-buffer
admission, fixed-name tombstone layout and accepted-worker ownership are
retained.
- INSERT/MultiUpdate keep admitted compact metadata in memory, migrating
unread records to the configured LOCAL spill service only on capacity
denial. Legacy/raw-delete output streams per frame with
delete-before-insert order. Files no longer use OS TMPDIR. Persistent
object and transaction protocols are retained; no new setting, worker
pool or polling interval is added.

INSERT metadata, MultiUpdate metadata and transaction-local delete-key
deduplication reuse existing statement/CN spill-disk and FD
reservations. Dedup bucket storage is admitted before sizing the file,
each distinct RowID before append; duplicates need no growth.
Close/Reset/Free return the reservations. Regressions verify cumulative
rejection before writing, shared-file quota reuse, partial creation and
cancellation; removing admission fails both consumer oracles. The
explicit-transaction nonblocking guard and upstream
serialization-retention/grouping-key fixes remain.

Impact: 91 production Go files versus the release base; the latest dedup
correction touches 2 production files (+11/-6), one existing test file
and the maintained design. Shared writer/admission and publication paths
include ordinary DML/publication; this is not a LOAD-only change. This
correction adds no planner, allocator hot-path or merge-policy change.

Validation:

- Physical LocalFS regressions cover late write failure/cancellation,
Reset, partial consumer handoff, successful INSERT handoff, failed
decode and successful-upload prefixes. Actual handed-off files remain;
producer-owned files are removed. Earlier original-behavior overlays
fail the ownership/TTL runtime oracles. The cleanup-deadline regression
also fails before sharing the deadline.
- Real worker/coordinator/FilterObject virtual-time tests cover expiry,
extension, shortening, unregister, parent cancellation and stale renewal
generations. The directly affected TTL/renewal tests pass 100
repetitions; final partition tests pass 100 repetitions per branch.
- The final `multi_update` owning package passes normal and race modes
(150 named tests each). A pre-fix real delete-preparation test fails its
storage-ownership oracle; fixed tests cover bucket/record quota denial
before writing, duplicate lookups at capacity, shared metadata/dedup
charges, Reset refund and reuse. Unchanged
insert/colexec/publication/ioutil code retains source-valid normal/race
evidence. Native binaries embed this final commit and pass 20 SQL
statements each: two partitions, 36,000 committed rows plus
same-transaction rows, exact counts/sums, DELETE, rollback/commit and
teardown. Test services are stopped and generated data is removed. This
is a functional control, not a SQL low-memory failure reproduction or a
current-head throughput result.
- Local SCA compares against latest fetched
`main@61b5a4e`. Its incremental
selector selects `./...`, including tests and reverse dependencies; Go
1.26.4, CGO and built thirdparties artifacts are used. Repository-pinned
molint `222a0b8adf07` and golangci-lint v2.6.2 pass; lint reports zero
issues:

```sh
go vet -mod=readonly -p=2 ./...
go vet -mod=readonly -p=2 -vettool=/d/mo-worktrees/v42-import-memory-lab-20261103/bin/molint ./...
golangci-lint run --timeout=25m --concurrency=2 --new-from-rev=61b5a4ee202578d2b186559f49af94b7c12b85a9 -c .golangci.yml ./...
make err-check
```

License/header checks and native builds pass. New GitHub CI and
re-review are pending.

Historical workload evidence retains its original
revisions/configurations:

- [Amway baseline attempt
2](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/41761321029/attempts/2),
`10d204b876`, versus [candidate attempt
4](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/41763229702/attempts/4),
`67179b6eed`: identical workflow `93631633b7`, importer `35e18afa1b`,
inputs/schema/index/order; two CNs, each 10 CPU/20 GiB, cache 2 GiB,
GOMEMLIMIT 16000 MiB; TN 5 CPU/15 GiB. Both complete four rounds/156
row-count checks. Candidate completes 156 retry-free imports with zero
OOM/restarts; baseline completes 150 retry-free imports with seven
retries and six restarts/OOM in rounds 2–4. Highest observed single-CN
cgroup usage: 18.904 → 2.872 GiB; sampled RSS: 18.247 → 2.663 GiB. Clean
first-round importer calls: 379.434 → 368.488 s (-2.88%); four-round
total including baseline recovery: 2358.215 → 1469.192 s (-37.70%).
Calls include DDL/rename/validation. Clean-round S3 writes increase
about 865 → 3293 while bytes decrease 8.211 → 7.933 GiB. [Baseline
artifacts](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/41761321029/artifacts/13303009140)
/ [candidate
artifacts](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/41763229702/artifacts/13315437176).
- [TPCH
baseline](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/41586981094),
`10d204b876`, versus
[port](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/41586985050),
`dfb9dd56be`: identical workflow `968b31e224`, pinned clients, three CNs
×14 CPU/55 GiB with 12-GiB cache; TN 14 CPU/55 GiB with 5-GiB cache.
Both runs/result checks pass.

| TPCH runner total | Baseline | Port | Change |
| --- | ---: | ---: | ---: |
| 100G LOAD, 8 tables | 311.592 s | 347.026 s | +11.37% |
| 1T LOAD, 8 tables | 3468.715 s | 3130.165 s | -9.76% |
| 100G queries, all 3 measured rounds | 288.795 s | 302.525 s | +4.75% |
| 1T queries, all 2 measured rounds | 2100.224 s | 2127.282 s | +1.29% |

LOAD excludes DDL/preparation; query sums include all 22 queries and
exclude warmup. One sequential pair does not establish statistical
significance. TPCH combined three-CN RSS peak: 95.369 → 99.137 GiB;
working-set peak: 135.168 → 124.451 GiB (15-second sampling). Historical
local `dfb9dd56be` acceptance completed five continuous Amway rounds
/195 imports/6,931,020 rows on one PID under 22 GiB, zero
OOM/retries/restarts/forced GC/deliberate pauses. These are historical
acceptance results.

This branch had an error being deployed

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

Labels

kind/bug Something isn't working kind/enhancement size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants