-
Notifications
You must be signed in to change notification settings - Fork 21
Improve HNSW concurrency: shared locks for read-only paths #904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…correctness - Upgrade per-node neighborsGuard from std::mutex to std::shared_mutex to allow concurrent read access during search operations. - Add lockNodeLinksShared/unlockNodeLinksShared methods and use them in all read-only paths: processCandidate, processCandidate_RangeSearch, greedySearchLevel, replaceEntryPoint, safeCollectAllNodeIncomingNeighbors, repairNodeConnections (read phases), getHNSWElementNeighbors, and the batch iterator. Write paths (mutuallyConnectNewElement, revisitNeighborConnections, mutuallyUpdateForRepairedNode) retain exclusive locks. - Make getElementIds const-correct across the HNSW class hierarchy. - Remove unused <iostream> include. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #904 +/- ##
==========================================
- Coverage 97.12% 97.10% -0.02%
==========================================
Files 129 129
Lines 7500 7488 -12
==========================================
- Hits 7284 7271 -13
- Misses 216 217 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/VecSim/algorithms/hnsw/hnsw.h
Outdated
|
|
||
| ElementGraphData *cur_element = getGraphDataByInternalId(curNodeId); | ||
| lockNodeLinks(cur_element); | ||
| lockNodeLinksShared(cur_element); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we actually use lock_guards here?
src/VecSim/algorithms/hnsw/hnsw.h
Outdated
|
|
||
| auto *cur_element = getGraphDataByInternalId(curNodeId); | ||
| lockNodeLinks(cur_element); | ||
| lockNodeLinksShared(cur_element); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here?
JoanFM
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, can we try to aim for having lock guards for more safety?
- Replace manual lock/unlock pairs with std::shared_lock/std::unique_lock in hnsw.h and hnsw_batch_iterator.h to make lock release scope-safe across early exits. - Deduplicate sorted node lock sets and guard against self-neighbor locking before acquiring paired locks, reducing deadlock/pathological lock risks without changing lock semantics.
Describe the changes in the pull request
lock audit:
Mark if applicable