Repository navigation
vector-store: separate concurrent insert/search operations - #339
Conversation
According to unum-cloud/USearch#697 (comment) there are 3 operation families. What is the 3rd one in our case or we don't have such? |
The 3rd family (remove, resize) is handled separately as exclusive (not concurrent) operations. |
There was a problem hiding this comment.
Pull request overview
This PR addresses concurrency crashes in the usearch vector index by implementing a mechanism to separate concurrent insert and search operations into two distinct operation families, preventing them from running simultaneously. According to the USearch library constraints, only operations within the same family (insert/add or search/count) can run concurrently.
Changes:
- Introduces an
Operationenum to categorize operations as either Insert or Search - Adds synchronization fields to
IndexState:current_operation(tracks active family) andoperations(counts active tasks) - Implements
wait_for_operation()to enforce operation family separation before spawning tasks - Adds
finish_operation()cleanup calls in both tokio and rayon task paths
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
While testing we can see seldom crashes in usearch running concurrent_add_and_search test. The crash is in the search path. According to scylladb#330 and unum-cloud/USearch#697 we can run concurrently only one family of operations: add/insert is the first, search/count is the second. This patch introduces two family operations: insert and search. The commit introduces Operation type to synchronise between them. Each operation needs to get permit to proceed, and getting the permit is an async task (it could wait if the operation is different than requested). The Permit contains counter and notifier - in Drop if counter decreses to 0 the listener will be notified. Fixes: VECTOR-474
|
Changelog for f2a3262
range diff |
7f1d247 to
f2a3262
Compare
knowack1
left a comment
There was a problem hiding this comment.
Interesting solution—I like it! By the way, while reading the unum-cloud/USearch#697 (comment) comment, I hadn't noticed that constraint, but I see it now. Thanks!
Requesting changes, as I think there is one synchronization issue related to capacity, please take a look.
Operation synchroniziation struct introduced in a previous commit opened a possibility to get rid of tokio rwlock. The same functionality (semaphore for exclusive access to the usearch index) could be now reached by using the Operation struct. Operation::permit_* functions are now responsible for waiting until operation could be done concurrently or exclusively. The commit refactors Operation by adding two separate functions: permit_for_message and permit_for_reserve, for additional operation (reserve) which is dynamically checked during add operation. The commit refactors reserve operation to allow running spawn directly in dispatch_task. needs_more_capacity function is now run directly in dispatch_task to limit needs for Arc::clone and to be able to use &mut operation. The commit refactors needs_more_capacity function to use keys.len() without asking idx for count() (to be able to check count during concurrent add/remove operation). The commit removes not needed newtype Semaphore as there is no more tokio RwLock.
f2a3262 to
fcd5eb9
Compare
While testing we can see seldom crash in usearch running concurrent_add_and_search test. The crash is in the search path.
According to #330 and unum-cloud/USearch#697 we can run concurrently only one family of operations: add/insert is the first, search/count is the second. This patch introduces two family operations: insert and search. Each operation increases counter for operations as a flag that some task is running and decreases it at finish.
I've run 4000 times the concurrent_add_and_search test without crash.
Fixes: VECTOR-474