Skip to content

fix(hnsw): backport parallel add synchronization to 0.16#1807

Merged
wxyucs merged 1 commit into0.16from
cp-1802-to-0.16
Apr 10, 2026
Merged

fix(hnsw): backport parallel add synchronization to 0.16#1807
wxyucs merged 1 commit into0.16from
cp-1802-to-0.16

Conversation

@inabao
Copy link
Copy Markdown
Collaborator

@inabao inabao commented Apr 9, 2026

Summary

  • backport PR fix(hnsw): synchronize parallel add graph updates #1802 to 0.16 to fix concurrent HNSW insert races that can drop neighbor updates
  • preserve the lock-order and hidden-until-linked behavior so TSAN-reported inversions and partially visible inserts are avoided on 0.16
  • resolve the 0.16 header conflict by keeping the branch's existing size_t API while porting the no-lock helper declarations

Test Plan

  • cherry-pick commit 7b89a7aa39dd88a836fcee6e5afd6ac0b8389026
  • conflict resolution in src/algorithm/hnswlib/hnswalg.h

Prevent concurrent inserts from dropping neighbor updates by making neighbor-side read-modify-write atomic, keep new points invisible until linking completes, and align lock ordering to remove the TSAN-reported inversion.

Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
(cherry picked from commit 7b89a7a)
@inabao inabao requested a review from wxyucs as a code owner April 9, 2026 04:01
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces thread-safety improvements and refactors locking mechanisms within the HNSW algorithm. Specifically, it adds "NoLock" variants for neighbor management functions to allow for more granular control over locking. It also adds a mutex to protect the random level generator and ensures consistent lock ordering in the "addPoint" method to prevent potential deadlocks. I have no feedback to provide.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.

@@            Coverage Diff             @@
##             0.16    #1807      +/-   ##
==========================================
- Coverage   92.16%   91.98%   -0.19%     
==========================================
  Files         295      295              
  Lines       15718    15734      +16     
==========================================
- Hits        14487    14473      -14     
- Misses       1231     1261      +30     
Flag Coverage Δ
cpp 91.98% <95.83%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 92.77% <ø> (+0.11%) ⬆️
datacell 91.67% <ø> (-0.55%) ⬇️
index 91.06% <95.83%> (-0.12%) ⬇️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 463691f...8cfd46e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@wxyucs wxyucs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@wxyucs wxyucs added version/0.15 kind/bug Something isn't working labels Apr 10, 2026
@wxyucs wxyucs merged commit 8f816da into 0.16 Apr 10, 2026
34 of 39 checks passed
@wxyucs wxyucs deleted the cp-1802-to-0.16 branch April 10, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M version/0.16

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants