-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(search): Simple multi-reader multi-writer mutex for hnsw index #6156
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
54f8826 to
3ba0698
Compare
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.
Review completed. 1 suggestion posted.
Comment augment review to trigger a new review at any time.
| } | ||
|
|
||
| vector<pair<float, GlobalDocId>> Knn(float* target, size_t k, std::optional<size_t> ef) { | ||
| world_.setEf(ef.value_or(kDefaultEfRuntime)); |
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.
Consider moving the world_.setEf(...) call inside the MRMWMutexLock scope; setEf mutates shared state and, as written, can race with concurrent reads/writes. (Also applies to the filtered Knn overload below.)
🤖 Was this useful? React with 👍 or 👎
| return mode == LockMode::kReadLock ? LockMode::kWriteLock : LockMode::kReadLock; | ||
| } | ||
|
|
||
| util::fb2::Mutex mutex_; |
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.
nit: you also contend on mutex_, though here maybe absl::SpinLock would fit better as you take it for a small period of time. you could use CondVarAny to be able to use locks with a different type.
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.
not the most important thing though.
Implementation of multi-reader multi-writer mutex that supports concurrent writes or reads but not a mix of reads and writes in same time. Unit test for testing MRMWMutex class. Signed-off-by: mkaruza <[email protected]>
45a7599 to
11e61f5
Compare
Implementation of multi-reader multi-writer mutex that supports concurrent writes or reads but not a mix of reads and writes in same time.
Unit test for testing MRMWMutex class.