Skip to content

[Bug]: HNSW parallel CDC insert drops Add errors and corrupts model length #25629

Closed

Description

@Ariznawlll

Summary

The pure-INSERT HNSW CDC path discards every error returned by HnswModel.AddWithoutIncr. The CDC update returns success even when usearch rejects a row, while the pre-reserved logical Len counter remains incremented.

This can persist an HNSW index with missing rows and an incorrect model length, and allows the CDC task/watermark to advance past data that was not indexed.

Version

Commit: 7f7de555c

Code path

pkg/vectorindex/hnsw/sync.go in insertAllInParallel:

last, _, err := s.getLastModelAndIncrForSync(sqlproc, maxcap, &mu)
if err != nil {
    err_chan <- err
    return
}

// Len counter already incremented. Just add to last model
last.AddWithoutIncr(row.PKey, row.Vec)

The return value of AddWithoutIncr is ignored. getLastModelAndIncrForSync has already incremented last.Len before the physical add.

The sequential UPDATE/DELETE path checks Add and Remove errors correctly; the defect is specific to the parallel pure-INSERT path.

White-box reproduction

Create an empty 3-dimensional HNSW model and pass two pure CDC INSERT entries with the same primary key to insertAllInParallel:

cdc := &vectorindex.VectorIndexCdc[float32]{Data: []vectorindex.VectorIndexCdcEntry[float32]{
    {Type: vectorindex.CDC_INSERT, PKey: 1, Vec: []float32{1, 2, 3}},
    {Type: vectorindex.CDC_INSERT, PKey: 1, Vec: []float32{3, 2, 1}},
}}

err := syncer.insertAllInParallel(nil, 64, []int{-1, -1}, cdc)
physicalLen, _ := model.Index.Len()

Actual result

returned error=<nil> logical Len=2 physical Len=1

usearch rejects the duplicate physical key, but the HNSW CDC layer reports success and retains the extra logical reservation. A nil/invalid vector produces the same false-success behavior with logical Len=1, physical Len=0.

Expected result

  • Propagate every AddWithoutIncr error through err_chan and fail the CDC iteration.
  • Roll back the pre-reserved Len value when the physical add fails.
  • Do not save the model or advance CDC state after any row fails.
  • Make duplicate/replayed CDC entries idempotent or fail explicitly without corrupting model counters.

Distinction from existing issues

This issue is a deterministic error-swallowing and internal-count divergence in the parallel CDC writer, not normal convergence delay or prepared-plan invalidation.

Activity

  1. added this to the MO-202607 milestone on Jul 11, 2026
  2. added theissue type on Jul 11, 2026
  3. added
    kind/bug
    severity/s0
    and removed on Jul 12, 2026
  4. Ariznawlll commented on Jul 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 详细验证

    • 源码基线:origin/main@f1c0a92d882dbdad469ffd2c96f607796207c797。
    • 执行命令:
    go test ./pkg/vectorindex/hnsw \
      -run '^Test(SaveToFileNoFDLeak|SaveToFileCleanupOnError|SyncInsertDuplicateKeyFailsCleanly)$' \
      -count=3 -v

    本 issue 对应测试过程

    1. 对空 HNSW 模型构造两条主键同为 1000 的 CDC INSERT。
    2. 单线程同步写入,让 usearch 的重复 physical add 路径保持确定性。
    3. 断言 Update 必须显式返回错误,不能把重复键吞掉并报告成功。
    4. 读取 physical index size,断言预留槽位已经回滚,逻辑 Len 与物理大小一致。

    结果

    • TestSyncInsertDuplicateKeyFailsCleanly:PASS 3/3。
    • package:ok github.com/matrixorigin/matrixone/pkg/vectorindex/hnsw 0.534s。
    • 结论:重复键会干净失败且计数不漂移,最新 main 定向回归通过。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions