Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters:
- OS type:
- Others: code inspection of origin/main. No duplicate open issue for external NULL append, materializeOneRow, or object-writer unmatched column length.
Actual Behavior
CSV, JSONLINE, and Kafka external scans build off-heap batches (External.Prepare, pkg/sql/colexec/external/external.go around 252–263, vector.NewOffHeapVecWithType).
Two production paths discard the error from vector.AppendBytes and still return success:
materializeOneRowfills a missing trailing field with NULL and ignores the error (external.go1545), then returns nil.getColDatadoes the same for a NULL or empty field (external.go1593–1596).
AppendBytes of a NULL goes through appendOneFixedWithSource → extendWithBitmaps → growData → MPool.Grow(..., offHeap=true). For an off-heap block owned by that pool, Grow returns moerr.NewMPoolCapacityNoCtxf when the temporary peak exceeds GlobalCap or mp.Cap (pkg/common/mpool/mpool.go 1559–1568). A failed extend does not publish the row (vector.go appendOneFixedWithSource: length is updated only after extendWithBitmaps returns nil).
getOneRowData only rolls a partial row back when materializeOneRow returns an error (external.go 1434–1442). A swallowed append leaves err == nil, including in error-tolerant mode, so there is no rollback.
CsvReader.makeBatchRows (reader_csv.go 233–242) and KafkaReader.ReadBatch (reader_kafka.go 473–481) then set bat.SetRowCount(bat.Vecs[0].Length()) and return nil. External.Call publishes that batch (external.go 418–425).
Consequences when the failed append is a query-pool capacity error:
- If column 0 grew and a later NULL or missing field did not,
RowCount()includes the row and the later vector is shorter.insert_tableunions each vector by its ownLength()but sets the written batch's row count frominput.Batch.RowCount()(pkg/sql/colexec/insert/insert.go556–566).txnTable.Writekeeps that row count viaCopyBatch(pkg/sql/util/util.go44–67). objectWriterV1.addBlockis the only length check in the tree. On a mismatch itDebuglogs and continues, thenBlockHeader().SetRowsuses column 0's length (pkg/objectio/writer.go801–810 and 867). A later successful flush therefore persists the short column under the longer row count.- If the failed append is column 0,
RowCount()stays at the old length while later columns that did append are longer. The row is omitted from the published count, and those extra values ride along in the marshaled column.
Non-NULL conversions in getColData return the append error, so this is specific to NULL, empty, and missing trailing fields. Those are normal CSV and Kafka rows, not a corrupt file.
Expected Behavior
A capacity error from AppendBytes should fail materializeOneRow. The scan should not publish the batch, and INSERT / LOAD DATA should not write it. Error-tolerant mode should see that error and roll the row back, then fail the statement if the replacement row cannot be appended either.
Steps to Reproduce
White-box, on the commit above:
- Build an off-heap external batch with two columns the same way
External.Preparedoes. - Use a query
MPoolwhose cap is large enough for the first row and too small for the next geometricGrowof column 1. - Append one complete non-NULL row so both vectors have length 1 and column 1's buffer is full.
- Call
getOneRowDatawith a second CSV record whose column 0 is non-NULL and whose column 1 is NULL (or whose line is shorter than the attribute list). - Observe
getOneRowDatareturns nil,Vecs[0].Length()==2,Vecs[1].Length()==1. - Run that batch through
insert_table's union +SetRowCount(input.Batch.RowCount()), thenobjectWriterV1.addBlock. Observe a nil error, a debug "unmatched length" line, andBlockHeaderrows equal to 2 while column 1's vector length is 1.
The same getOneRowData path is used by LOAD DATA, external table scan, and Kafka scan.
Additional information
Not the same bug as #29256 (multi_update tombstone batches) or #29257 (CN sinker objects orphaned when a later error skips registration). This one returns success from the scan and the object writer accepts the mismatched lengths.
Activity
fix(external): propagate NULL append failures (#29342)
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
该问题依赖内部 reader 生命周期或 I/O 故障注入,公开 SQL 无法稳定制造目标失败点。已在最新 main 上运行对应定向测试
TestExternalNullAppendFailureIsReturned,连续 3 次通过。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
确认修复提交
ac46f1a09bfeee21a83cf511625b44d5fb7f1093是当前 main 的祖先,并直接执行该提交新增的定向测试,结果 3/3 PASS。回归测试
回归已落在 MatrixOne UT:
TestExternalNullAppendFailureIsReturned。未加入 MOTR,因为该场景必须注入内部 reader/I/O 失败,SQL 黑盒无法可靠触发;按覆盖矩阵应保留在 UT 层。测试证据
5be6cd90b501da225be591ffffe6000bf01f515eac46f1a09bfeee21a83cf511625b44d5fb7f1093测试结论
测试通过。