Introduce Mutex Map in IndexInfo to Ensure Thread Safety During Index Construction #2489
Closed
2 tasks done
Labels
enhancement
type enhancement
Search before asking
Motivation
In the context of index, the absence of a locking mechanism could lead to issues when multiple threads attempt to modify shared resources simultaneously.
[1] Original issue raised from HNSW #2481
[2] Marked TODO
kvrocks/src/server/redis_connection.cc
Lines 522 to 528 in 3408318
We might want to introduce locks to solve the problem.
Solution
Solution 1: Mutex (Straight-forward)
We can introduce a mutex map within each IndexInfo structure. This mutex map would contain a mutex for each field that requires protection against concurrent access.
Con
Solution 2: Queue
We can store the
Update
task for eachIndexInfo
field in a queue, and have a background thread to schedule tasks in order asynchronously. I'm not quite sure about how many number of threads would be appropriate, but can discuss further if everyone leans towards this solution.cc @PragmaTwice
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: