Skip to content

[Bug]: multi_update S3 delete flush drops tombstone rows when off-heap append fails and still returns success #29256

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

66da387

Other Environment Information

  • Found by reading origin/main at the commit above. Not reproduced with a live SQL session.
  • Hardware parameters: code inspection
  • OS type: n/a
  • Others: cross-check of the CN multi_update S3 delete flush against the in-memory delete path

Actual Behavior

multi_update's S3 delete flush can commit a DELETE or UPDATE that omits tombstone rows, and still return success.

prepareDeleteBatches marks a row offset in the block bitmap before appending it, then discards both append errors:

// pkg/sql/colexec/multi_update/s3writer_delegate.go
bitmap.Add(uint64(rowOffset))
vector.AppendFixed(block.bat.GetVector(RowIDIdx), rowID, false, proc.GetMPool())
block.bat.GetVector(PkIdx).UnionOne(bat.GetVector(PkIdx), int64(i), proc.GetMPool())
block.bat.SetRowCount(block.bat.Vecs[0].Length())

The tombstone batch is off-heap (newDeleteBatch → batch.NewOffHeap / vector.NewOffHeapVecWithType in pkg/sql/colexec/multi_update/delete.go). Off-heap growth goes through MPool.alloc / MPool.Grow, which return moerr.NewMPoolCapacityNoCtxf when GlobalCap, mp.Cap(), or the physical allocator rejects the grow (pkg/common/mpool/mpool.go). That failure does not require a ~2GiB on-heap allocation.

On that capacity error the row is not published:

  • AppendFixed → appendOneFixedWithSource returns from extendWithBitmaps before publishSingleAppend (pkg/container/vector/vector.go). Vector length stays unchanged.
  • UnionOne returns from the same extendWithBitmaps check before setLengthAfterExtend (vector.go). PK length stays unchanged.
  • SetRowCount then uses Vecs[0].Length(), which does not include the failed row.
  • The offset is already in bitmap, so a later row in the same block cannot retry it.
  • prepareDeleteBatches returns (retBatchs, nil).

sortAndSync treats that nil error as success and uploads the short batch. flushTailAndWriteToOutput copies it into the output batch. MultiUpdate.update then calls source.Delete on that batch (pkg/sql/colexec/multi_update/multi_update.go). The statement succeeds.

If every append in a block fails, BatchSet.Push drops the empty batch (rowCount == 0 returns nil in pkg/container/batch/batch_set.go) and sortAndSyncOneTable returns immediately on len(bats) == 0. No tombstone object is written, and the error is still nil.

The in-memory delete path does the opposite: deleteOne returns the UnionOne / UnionBatch error (pkg/sql/colexec/multi_update/delete.go). Only the S3 assembly path ignores it.

A later S3 Write/Sync error can still abort the statement. The defect is the control flow that returns success with a tombstone shorter than the rows that were supposed to be deleted. Those rows stay visible.

Expected Behavior

An off-heap append or union failure while building a tombstone batch must fail the statement. The row offset must not be committed to the bitmap unless both the rowid and pk appends succeed. The tombstone handed to source.Delete must contain every non-null rowid that this statement intended to delete.

Steps to Reproduce

Code path on main @ 66da3877e9. No live cluster run.

  1. Run a DELETE or UPDATE whose plan uses MultiUpdate.update_s3 (pkg/sql/colexec/multi_update/multi_update.go). flushTailAndWriteToOutput always calls sortAndSync → prepareDeleteBatches, including for small delete batches.
  2. Force proc.GetMPool() off-heap growth to fail while prepareDeleteBatches appends a committed-block row (GlobalCap / mp.Cap() / physical allocator). newDeleteBlockData builds that batch with NewOffHeap.
  3. Observe prepareDeleteBatches return nil after bitmap.Add, with Vecs[0].Length() unchanged for the failed row.
  4. Observe source.Delete receive the shorter batch (or no batch, if every append failed and BatchSet.Push dropped it) and the statement return success.
  5. Read the target rows back. Rows whose append failed are still visible.

Additional information

  • If the rowid AppendFixed succeeds and only the pk UnionOne fails, SetRowCount(Vecs[0].Length()) counts a row the pk vector does not contain. That mismatch can panic later or write a bad pk. The proven silent case is both appends failing in extendWithBitmaps, which leaves both lengths unchanged.
  • Not the same as #25204. That issue is workspaceSize accounting plus async fs.Delete logging for objects that already entered txn.writes. This bug never fails the statement, so rollback GC is not involved.
  • Not the in-memory collectBatchInfo path under pkg/sql/colexec/deletion, which builds an on-heap batch. This report is only the off-heap S3 tombstone assembly in multi_update.

Activity

  1. added
    kind/bug
    on Sep 22, 2026
  2. added this to the MO-202609 milestone on Sep 23, 2026
  3. added theissue type on Sep 23, 2026
  4. self-assigned this
    on Sep 23, 2026
  5. added a commit that references this issue on Sep 24, 2026
    6397d6b
  6. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地源码定向 UT(Go 1.26.5,macOS arm64)
    • 测试日期:2026-09-27

    原问题验证

    该问题依赖内部 reader 生命周期或 I/O 故障注入,公开 SQL 无法稳定制造目标失败点。已在最新 main 上运行对应定向测试 TestPrepareDeleteBatchesAppendFailure,连续 3 次通过。

    Happy Path 覆盖

    1. multi_update 正常构建 S3 delete/tombstone batch。

    Unhappy Path 覆盖

    1. off-heap append 注错后立即 abort,未丢 tombstone 后错误返回成功。

    白盒验证

    确认修复提交 6397d6bc29f28f00407d44ed450eb1c87fe686a8 是当前 main 的祖先,并直接执行该提交新增的定向测试,结果 3/3 PASS。

    回归测试

    回归已落在 MatrixOne UT:TestPrepareDeleteBatchesAppendFailure。未加入 MOTR,因为该场景必须注入内部 reader/I/O 失败,SQL 黑盒无法可靠触发;按覆盖矩阵应保留在 UT 层。

    测试证据

    • MatrixOne main commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 修复提交:6397d6bc29f28f00407d44ed450eb1c87fe686a8
    • 定向 Go 测试:3/3 PASS

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions