Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Reproduced on 2f6fcc772175d0c0e80ad97aac6d44360c513347; all files referenced below are unchanged on 553e16f52b02d59e9ecc5e3c8862f2603e661f48 (main, 2026-11-11).
Other Environment Information
- Single-node MatrixOne (launch.toml),
[cn.frontend.iceberg] enable/enable-write/enable-delete/enable-dml = true,dml-max-memorynot set (default 256 MiB) - Iceberg REST catalog: Nessie, warehouse on MinIO
- Linux x86_64, 64 vCPU, 251 GB RAM (memory was not the limit)
- Related: [Bug]: Iceberg writer ignores write.parquet.compression-codec and writes uncompressed, plain-encoded Parquet (~14x larger files) #32466 (MO writes uncompressed Parquet, which makes files reach the target size sooner)
Actual Behavior
INSERT INTO <iceberg table> SELECT ... fails as soon as a single data file approaches the 128 MiB target file size:
ERROR 20400: ICEBERG_OBJECT_IO: Iceberg Parquet writer failed to encode rows
Nothing else appears in the client error or in the CN log, so the error looks like a Parquet encoding or data problem. It is neither: the real cause is the Iceberg DML memory budget (Iceberg DML memory limit exceeded), and that message is lost when it is wrapped.
Measured on an 18-column table (BIGINT, DOUBLE, DATE, DATETIME(6), INT, VARCHAR; identity partition on a DATE column; all rows in one or two partitions), source is a MO native table, about 210 bytes per row in the written Parquet:
| rows in one INSERT | default dml-max-memory (256 MiB) |
dml-max-memory = 2147483648 |
|---|---|---|
| 100,000 | OK (3.2 s) | OK (4.1 s) |
| 500,000 | OK (13.2 s) | OK (17.3 s) |
| 1,000,000 | FAIL failed to encode rows (16.7 s) |
OK (27.2 s) |
| 2,000,000 | FAIL failed to encode rows (21.9 s) |
OK (49.9 s) |
The only change between the two columns is dml-max-memory plus a CN restart. The same statement over the full 22M-row source also fails with the default setting.
Expected Behavior
- With default settings, an append INSERT of any size succeeds: the default memory budget must be able to hold at least one data file of the default target size, including the copy made at close.
- When the budget is exceeded, the error says so (for example
Iceberg DML memory limit exceeded [used_bytes=..., requested_bytes=..., limit_bytes=...]) and names the setting to change, instead offailed to encode rows.
Steps to Reproduce
The table in our test is wide; the SQL below is a minimal equivalent that puts more than 128 MiB of Parquet into one unpartitioned data file.
-- 1. Create the Iceberg table through the REST catalog (MO maps existing tables only), e.g.
-- POST /iceberg/v1/main%7Cwarehouse/namespaces/demo/tables
-- { "name": "t", "stage-create": false,
-- "schema": {"type":"struct","schema-id":0,"fields":[
-- {"id":1,"name":"id","required":false,"type":"long"},
-- {"id":2,"name":"s","required":false,"type":"string"}]},
-- "partition-spec": {"spec-id":0,"fields":[]},
-- "properties": {"format-version":"2"} }
-- 2. Map and write from MO with the default [cn.frontend.iceberg] settings
CREATE EXTERNAL TABLE t (id BIGINT, s VARCHAR(256)) ENGINE = ICEBERG
WITH ('catalog'='c','namespace'='demo','table'='t','ref'='main',
'read_mode'='merge_on_read','write_mode'='merge_on_read');
INSERT INTO t SELECT result, REPEAT('x', 200) FROM generate_series(1, 100000) g; -- ~20 MiB file: OK
INSERT INTO t SELECT result, REPEAT('x', 200) FROM generate_series(1, 1000000) g; -- ~200 MiB: ICEBERG_OBJECT_IO: ... failed to encode rows
-- 3. Add `dml-max-memory = 2147483648` under [cn.frontend.iceberg], restart the CN: the second INSERT succeeds.Additional information
Why a 128 MiB file cannot fit in a 256 MiB budget. The append path buffers every data file fully in memory and charges it to one budget:
- The budget is created with
DMLMaxMemory, 256 MiB by default:matrixone/pkg/sql/iceberg/append_runtime_factory.go
Lines 208 to 224 in 553e16f
appendWriteBudget := newDMLMemoryBudget( effectiveCfg.Write.DMLMaxMemory, metadata.ManifestListMemoryWeight(0, preserved), ) writer, err := icebergwritecore.NewFanoutParquetDataWriter(ctx, icebergwritecore.FanoutWriterConfig{ Schema: schema, PartitionSpec: spec, TableLocation: strings.TrimRight(strings.TrimSpace(tableMeta.Location), "/"), DataDir: appendDataDir(api.FirstNonBlankPreserveWhitespace(req.StatementID, req.IdempotencyKey), snapshotID), WriterID: writerID, TargetFileSizeBytes: f.opts.TargetFileSizeBytes, TimeZone: req.TimeZone, }, bufferedDataFileOutputFactory{ Writer: objectWriter, MemoryBudget: appendWriteBudget, RetainedMetadataBytes: retainedDMLDataFileMetadataBytesForSchema(schema, spec), }) matrixone/pkg/config/configuration.go
Line 544 in 553e16f
ip.DMLMaxMemory = 256 << 20
- The fanout writer closes a file only after
ApproxSize() >= TargetFileSizeBytes. That value is 128 MiB by default; the append path does not set it, and it does not read the table propertywrite.target-file-size-bytes:defaultTargetFileSizeBytes int64 = 128 * 1024 * 1024 matrixone/pkg/iceberg/write/fanout_writer.go
Line 133 in 553e16f
if active.writer.ApproxSize() >= w.cfg.TargetFileSizeBytes {
bufferedDataFileObject.Writegrows its buffer geometrically (64 KiB · 2ⁿ). It reserves the new capacity before releasing the old one. When the buffer is full at 128 MiB, it asks for 256 MiB while still holding 128 MiB, which exceeds the default budget:matrixone/pkg/sql/iceberg/dml_replacement_writer.go
Lines 185 to 201 in 553e16f
if oldCapacity <= math.MaxInt/2 && oldCapacity*2 > nextCapacity { nextCapacity = oldCapacity * 2 } if nextCapacity < 64<<10 { nextCapacity = 64 << 10 } // make+copy keeps the old backing array live until the copy completes. // Reserve the full new capacity first, then release the old capacity; // accounting only the delta would understate the real growth peak by // almost 2x for a geometrically growing buffer. if err := o.budget.reserve(o.ctx, int64(nextCapacity)); err != nil { return 0, err } next := make([]byte, len(o.data), nextCapacity) copy(next, o.data) o.data = next o.budget.release(int64(oldCapacity))
- Even with no growth step,
Close()reserves a second copy of the whole buffer (copyBytes) beforeWriteObject. A 128 MiB file therefore needs at least 256 MiB plus the per-file metadata reservation, which is already more than the default budget:matrixone/pkg/sql/iceberg/dml_replacement_writer.go
Lines 223 to 224 in 553e16f
copyBytes := int64(len(o.data)) if err := o.budget.reserve(o.ctx, copyBytes); err != nil {
So, with defaults, every data file that reaches the target size fails. Small statements succeed only because their files stay well below 128 MiB. Uncompressed Parquet (#32466) makes this more likely, because files are about 14x larger than they need to be.
Why the cause is hidden. The budget error is returned from Write on the output stream, so parquet-go returns it from GenericWriter.Write. ParquetDataWriter.WriteRows then wraps it as ErrObjectIO "failed to encode rows":
matrixone/pkg/iceberg/write/parquet_writer.go
Line 188 in 553e16f
return api.WrapError(api.ErrObjectIO, "Iceberg Parquet writer failed to encode rows", nil, err)
IcebergError.Error() prints only the code, message and fields, not Cause:
matrixone/pkg/iceberg/api/errors.go
Lines 75 to 102 in 553e16f
func (e *IcebergError) Error() string { if e == nil { return "" } var b strings.Builder b.WriteString(string(e.Code)) if e.Message != "" { b.WriteString(": ") b.WriteString(e.Message) } if len(e.Fields) > 0 { keys := make([]string, 0, len(e.Fields)) for k := range e.Fields { keys = append(keys, k) } sort.Strings(keys) b.WriteString(" [") for i, k := range keys { if i > 0 { b.WriteString(", ") } b.WriteString(k) b.WriteString("=") b.WriteString(e.Fields[k]) } b.WriteString("]") } return b.String()
ToMOErr returns the outer error unchanged because the inner cause is already a moerr:
matrixone/pkg/iceberg/api/errors.go
Line 130 in 553e16f
if stderrors.As(err, &mo) {
The user therefore sees only the outer message.
Possible directions (for the owners to decide):
- Make the default budget at least 2x the target file size plus headroom, or derive the target file size from the budget.
- Stream data files to object storage with multipart upload instead of buffering whole files. This also removes the extra copy at close.
- Honour
write.target-file-size-bytes. - Include
CauseinIcebergError.Error(), or do not wrap errors that come from the output sink.
Workaround: set [cn.frontend.iceberg] dml-max-memory high enough. The peak per open data file is about 3x the target size: old buffer + doubled buffer while growing, or doubled buffer + copy at close. That is ~384 MiB per partition file open at the same time; we used 2 GiB. Alternatively, split large INSERTs so that no single data file reaches about 128 MiB.
Activity
Fix Iceberg append memory pressure handling (#32523)
XuPeng-SH commentedon Nov 23, 2026
转测:#32523 已合入
main(42d1c888f6c301d2d974daa17e9d79370818d9de)。改动在共享写内存吃紧时提前轮转分区文件,并保留硬预算限制;真正超限时应给出可定位的 Iceberg DML 内存错误,而不是只报 Parquet 编码失败。历史候选
8074dfd0的单 CN、MinIO/Nessie 4 MiB 测试验证了多文件读回、真正超限时快照与原数据不变和清理。该结果未覆盖合入版本、原 256 MiB 默认预算下的 100 万/200 万行、原 2200 万行规模或生产并发。最终提交ffe916a8的 Actions 记录 中 adapter module tidy 通过、Iceberg E2E Local 跳过,不能当作完整 E2E 通过;#33077 的 Coverage UT runner 内存事件另行跟踪。请用合入的 main 在默认 256 MiB 下先跑原单/少分区宽表的 100 万和 200 万行,核实际读回、文件数及提交快照;再用确实超限的负向对照核错误里有预算上下文,快照/数据不变及清理。记录规模、耗时和峰值,未跑的原 2200 万行、取消和远程存储边界留作未验证。本次为交接,非验收结论。
Ariznawlll commentedon Dec 1, 2026
结论
测试不通过。 原先“预算错误被隐藏成 Parquet 编码失败”的问题已修复,小规模及两列大数据写入通过;但默认 256 MiB 预算下,18 列、双 DATE 分区、原生表来源的 2,200 万行 INSERT 连续两次失败,仍未满足本 Issue 的大规模 append 要求。失败后未发现部分提交。
关键证据
精确版本与部署
32ffdd4ac2722972be184af63906c8f23901e323,测试期间重新查询官方 main 仍为该 SHA。实际SELECT git_version()返回相同完整 SHA。42d1c888f6c301d2d974daa17e9d79370818d9de。本次只验收 main。dml-max-memory,采用默认 268435456 bytes。Parquet 显式设为uncompressed,避免压缩后的较小数据掩盖文件轮转/预算路径。通过的对照
两列
id BIGINT, s VARCHAR(256),s 为每行派生的 200 字节文本,分四次 append:每批验证行数、distinct id、ID 范围/总和、payload 总长度以及每行 payload 内容,错误行数均为 0。最终累计 25,100,000 行;独立读取对象存储中 103 个 Parquet 文件的 footer,物理行数也为 25,100,000,文件总字节 5,365,987,011,所有 column chunk 为 UNCOMPRESSED。
18 列双分区表的 1,000,000 行和 2,000,000 行 INSERT 分别用时 21.045 s / 41.953 s,新增 10 / 21 个文件。累计 3,000,000 行,另外 17 列逐列按 ID 派生表达式全量核对,错误数均为 0。
失败场景如何复现
创建 Iceberg v2 表,18 列为:id BIGINT、dt DATE、ts DATETIME(6)、tenant INT、4 个 BIGINT、3 个 DOUBLE、7 个 VARCHAR(32);以 dt 做 identity 分区。
write.parquet.compression-codec=uncompressed。创建相同结构的 MO 原生表 source。用
generate_series(1,22000000)生成数据:id=result;dt 依奇偶交替为两个日期;ts 为固定微秒时间;tenant=result%100;4 个 BIGINT=result×1..4;3 个 DOUBLE=(result%1000)/2、/4、/8;7 个字符串分别为left(md5(concat(cast(result as char),'-N')),20)。保持默认预算,执行:
第一次在已通过 1M/2M append 后执行,失败。确认 source 仍为 22,000,000 行、目标仍为 3,000,000 行,再原样执行第二次,同样失败。两次实际错误一致:
第二轮包含 INSERT 和随后状态检查总计 415.952 s,快照前后均为
1796141121852121090,目标表仍为 3,000,000 行。随后全量检查另外 17 列,错误数仍全为 0。代码核对与边界
retainedDMLDataFileMetadataBytesForSchema按列数预留每个数据文件的常驻元数据,当前 18 列/一个分区字段计算为:这与两次失败中的
requested_bytes完全一致。创建文件时保留该元数据预算;文件 Close 释放 payload buffer,但保留供 commit/abort 使用的 DataFile 元数据。文件轮转可以限制活动 payload,却不能消除随文件数量增长的保留元数据。此处是已有源码和错误数值相互印证的定位;未注入修改产品实现,也未把它描述为进程 OOM。两次失败后对象存储 wide 路径共看到 753 个 Parquet 对象,而成功快照只有此前 31 个文件。这里仅记录失败写入产生的未提交对象仍存在,不凭此另判“清理泄漏”;仍需研发核对 orphan 登记和回收策略。
低预算和原生测试
iceberg_e2e_local.go --low-budget-regression完整执行三轮,每轮 setup、轮转、真实拒绝、cleanup 均通过。拒绝错误含used_bytes=4173279, requested_bytes=65536, limit_bytes=4194304;快照和种子数据保持不变。之后已恢复默认配置再执行上述宽表复现。回归
已追加现有 MOTR main PR #404,提交
73480029379d142dcf40eb966fa306d1d16aff24,没有主库测试 PR。issue_32514_iceberg_budget.py:真实 SQL、逐列精确结果、快照和物理 Parquet 验证。QA32514_ROWS=100000,1000000,2000000,22000000或 workflow 的 rows 输入启用,失败直接报错,不改为预期成功。bb847b173dbc0a4f0374a3c7777930ecd760632a补齐 headers/libraries 环境,新 CI 已成功完成:默认百万行矩阵及低预算拒绝/清理三轮均通过。待解决点
请继续处理默认预算下已完成文件元数据累计导致的宽表大规模写入失败,或明确产品支持范围并调整可执行的验收契约。错误信息已经正确传播,不应再按旧的“编码错误”方向定位。修复后需原样重跑 22M 宽表、失败原子性和对象回收。
最终结论:测试不通过。未通过项:main 默认 256 MiB 预算下,18 列双分区的 22M 行 INSERT 连续两次超预算失败。已通过:错误详情传播、两列 22M、宽表 1M/2M、失败后数据/快照原子性、后续小写入及重启、三轮低预算套件和定向 race。MOTR 默认矩阵 CI 已通过,但不覆盖已失败的 22M 宽表专项;本 Issue 保持开放,转回原修复负责人继续处理。
fix(iceberg): reclaim unused append file metadata budget (#33646)