Repository navigation
Optimize RocksDB buffered wrapper with single Mutex - #5915
Conversation
| let ids_to_insert = pending_operations.inserted; | ||
| let ids_to_delete = pending_operations.deleted; |
There was a problem hiding this comment.
Nit: how about struct destructing here?
There was a problem hiding this comment.
very good point, it will please Andrey :)
There was a problem hiding this comment.
TIL. Thanks!
let PendingOperations { deleted, inserted } =
mem::take(&mut *self.pending_operations.lock());| #[derive(Debug, Default)] | ||
| struct PendingOperations { | ||
| deleted: HashSet<Vec<u8>>, | ||
| inserted: HashMap<Vec<u8>, Vec<u8>>, |
There was a problem hiding this comment.
do we even need parallel structures here? Wouldn't it be easier to represent as hashmap of enum?
There was a problem hiding this comment.
Do you mean something like this? 🤔
enum Operation {
Inserted(Vec<u8>),
Deleted,
}
type PendingOperations = HashMap<Vec<u8>, Operation>;But then we also have this situation. It will change behaviour if we override
There was a problem hiding this comment.
Yes.
Insertions have priority over deletions, so a delete entry can just be replaced. If we really want we can add the same debug assertion in a different place.
There was a problem hiding this comment.
I'd prefer just tackling the Mutex refactoring in the current PR.
Using a single data structure is a different transformation that should be done in isolation.
* Optimize RocksDB buffered wrapper with single Mutex * deconstruct struct to not foget field later
The two mutexes are always acquired together so they can be merged.