-
Notifications
You must be signed in to change notification settings - Fork 467
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
feat(search): Support mutex to guarantee index update thread safety #2491
Conversation
@@ -52,21 +53,28 @@ struct FieldInfo { | |||
|
|||
struct IndexInfo { | |||
using FieldMap = std::map<std::string, FieldInfo>; | |||
using MutexMap = std::map<std::string, std::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.
Maybe we can put mutexes into IndexUpdater
s instead of IndexInfo
s?
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.
Sure, this makes more sense <3
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.
While trying to move the exact same piece of code into IndexUpdater
s, I encountered the following errors:
‘constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const std::__cxx11::basic_string<char>; _T2 = std::mutex]’ is implicitly deleted because the default definition would be ill-formed:
314 | constexpr pair(const pair&) = default; ///< Copy constructor
I suspect that this is caused by IndexUpdater
s are usually created on stacks, which causes std::map
doing some underlying copies and deletions, while IndexInfo
s are allocated on heap so doesn't have the issue.
I tried to wrap std::mutex
into a unique_ptr
but the compiler will report the same error.
I'm not quite sure what I can do at this point, may leave it as it is, and try to benchmark first. But feel free to let me know if you think there is anything I missed, or any workaround you can think of. @PragmaTwice <3
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.
Sorry for the delayed response.
I checked the related code, and I think there's two methods to solve it:
- keep mutex maps inside
GlobalIndexer
, and add a raw pointer intoIndexUpdater
to access them; - follow the current way and modify methods like
void Add(IndexUpdater updater)
toAdd(std::unqiue_ptr<IndexUpdater>)
.
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.
All good all good, thanks for sharing your solution!
Might be a bit busy these two weeks, will be back to work on it during mid October.
Tried the benchmark framework today, which took more than one hour to upload, but didn't even finish. I thought there was something wrong and killed the process, but after double-checking the redis benchmark here, seems like it also took redis 1.5 hours. |
@Beihao-Zhou Do you know if theres a place where you can configure your compute for kvrocks? |
Thanks a lot for pointing this out! I thought I was bottlenecked by lock itself so didn't try different config options, will look into them! |
Apology for the late update! Was busy with relocation for the past two weeks. Quick Update: |
I'll take this task and submit a patch for it : ) |
Thanks a ton!! Was too distracted by work these days.... My apology 😭 |
Closes #2489
Summary
This PR fixes the concurrency issue mentioned in #2481, however, this is now pretty slow for uploading operation and bounded by the computational resources from my local laptop. I'll set up the same instance capacity as mentioned in the post and benchmark.