You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: BranchHashmap ItemCount remains stale after PopByVectorsStream callback error #26081
BranchHashmap.PopByVectorsStream removes matching in-memory entries before invoking its callback. If the callback returns an error, the method returns immediately without applying removedTotal to shard.items.
The removed row is no longer returned by GetByVectors, but ItemCount() still includes it. This leaves the hashmap's public count inconsistent with its actual contents after an error in a real Data Branch callback such as row decoding or batch construction.
Tested on main commit 2eb7f523e5a10f352d3e258183ed8440510388de.
Reproduction
Create a one-shard BranchHashmap.
Insert one row through PutByVectors and verify ItemCount() == 1.
Call PopByVectorsStream for that key with a callback that returns an error.
Query the key with GetByVectors and read ItemCount().
This was reproduced in 3 consecutive runs with a focused unit test.
Actual result
PopByVectorsStream returns the callback error.
GetByVectors reports that the row no longer exists.
ItemCount() incorrectly remains 1.
The returned removed count is 0, even though the row has already been removed.
Expected result
The bookkeeping and returned removal count should remain consistent with the entries already removed before the callback error is returned, or the removal should be rolled back.
Code path
pkg/frontend/databranchutils/branch_hashmap.go, PopByVectorsStream: the callback error branch returns before atomic.AddInt64(&shard.items, -removedTotal) and before adding removedTotal to totalRemoved.
PR #26116 merged as 6e79915d1e3eeaee56b3ebe4a66989fca75f3c3d (reviewed head a4beba2b7692de59ba3d0dc2ede8e5cd57dbe017). The repaired in-memory/spill truth table, race tests, and required CI passed.
QA handoff on main f6dab28046d70412cec132f0068840896852101c:
For in-memory and spilled storage, insert multiple rows with the same key and fail the callback after the first delivered row.
Verify callback count, returned removal count, ItemCount, and retained later rows agree at the same per-row boundary.
Verify retry can retrieve the rows that were never delivered.
Pass: only delivered rows are removed/accounted and undelivered rows remain retrievable in both backends. Fail: silent row loss, stale ItemCount, inconsistent counts, or backend-dependent behavior.
PR #26116 merged as 6e79915d1e3eeaee56b3ebe4a66989fca75f3c3d (reviewed head a4beba2b7692de59ba3d0dc2ede8e5cd57dbe017). The repaired in-memory/spill truth table, race tests, and required CI passed.
QA handoff on main f6dab28046d70412cec132f0068840896852101c:
For in-memory and spilled storage, insert multiple rows with the same key and fail the callback after the first delivered row.
Verify callback count, returned removal count, ItemCount, and retained later rows agree at the same per-row boundary.
Verify retry can retrieve the rows that were never delivered.
Pass: only delivered rows are removed/accounted and undelivered rows remain retrievable in both backends. Fail: silent row loss, stale ItemCount, inconsistent counts, or backend-dependent behavior.
go test ./pkg/frontend/databranchutils \
-run '^(TestBranchHashmapPopByVectorsStream(InMemory|Spilled)(CallbackError)?)$' \
-count=1
ok github.com/matrixorigin/matrixone/pkg/frontend/databranchutils
Activity
Ariznawlll commentedon Jul 27, 2026
补充同键多行场景:插入 key=1 的两行记录后,调用
PopByVectorsStream(..., removeAll=true, callback),并让 callback 在收到第一行时返回错误。连续 3 轮结果一致:
PopByVectorsStream返回的 removed 数为 0;GetByVectors(key=1)已无剩余行,说明两行都已在回调前移除。因此该路径除计数未汇总外,还会出现“已移除但未交付给 callback”的记录。建议在回调错误时同步已完成的计数,并明确采用逐行移除/交付或可恢复的处理方式,避免多行结果半途丢失。
fix(frontend): keep stream pop count on callback error (#26116)
VioletQwQ-0 commentedon Jul 29, 2026
PR #26116 merged as
6e79915d1e3eeaee56b3ebe4a66989fca75f3c3d(reviewed heada4beba2b7692de59ba3d0dc2ede8e5cd57dbe017). The repaired in-memory/spill truth table, race tests, and required CI passed.QA handoff on main
f6dab28046d70412cec132f0068840896852101c:Pass: only delivered rows are removed/accounted and undelivered rows remain retrievable in both backends. Fail: silent row loss, stale ItemCount, inconsistent counts, or backend-dependent behavior.
VioletQwQ-0 commentedon Jul 29, 2026
PR #26116 merged as
6e79915d1e3eeaee56b3ebe4a66989fca75f3c3d(reviewed heada4beba2b7692de59ba3d0dc2ede8e5cd57dbe017). The repaired in-memory/spill truth table, race tests, and required CI passed.QA handoff on main
f6dab28046d70412cec132f0068840896852101c:Pass: only delivered rows are removed/accounted and undelivered rows remain retrievable in both backends. Fail: silent row loss, stale ItemCount, inconsistent counts, or backend-dependent behavior.
Ariznawlll commentedon Jul 29, 2026
已在最新
main分支完成专项验证。测试版本:
52ea9f874f492c368a20efef16b46ab8ced2de37测试过程:
BranchHashmap。ItemCount和剩余数据。-race模式各连续执行 3 轮。测试结果:
ItemCount、removal count 和实际剩余行数一致。-race各 3 轮全部通过,未发现数据竞争。结论:该问题在上述最新 main commit 上验证通过。
Ariznawlll commentedon Jul 30, 2026
已在
main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c补充完成黑盒和白盒验证。黑盒验证:
10000/10000/10000。结果:场景通过;本轮 Data Branch 全集
13/13case、280/280条 SQL/断言通过。此前该 bulk 场景连续执行3/3也全部通过。白盒验证:
白盒分别覆盖 memory/spill 正常路径和 callback error 注入,验证已经移除的行会同步更新
ItemCount和返回计数。黑盒场景不伪造内部 callback failure,只验证公开数据面的大批量计数与结果正确性。Unhappy path / 错误注入:
结论:原 callback-error 计数路径及公开 bulk consumer 路径均验证通过,黑盒回归已加入 motr#69。
Ariznawlll commentedon Jul 30, 2026
Unhappy Path 专项验证
测试版本:
main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c白盒错误注入:
ItemCount和 returned removed count。白盒测试返回
ok。黑盒数据异常组合:
结果:内部 callback-error 计数一致;黑盒 bulk 场景通过,并曾连续执行
3/3通过。回归见 motr#69。fix(frontend): keep stream pop count on callback error (matrixorigin#…
fix(frontend): keep stream pop count on callback error (matrixorigin#…
fix(frontend): keep stream pop count on callback error (matrixorigin#…