Skip to content

Commit

Permalink
store: use optimized get/set in scc
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 181b1e4
Author: Changgyoo Park <[email protected]>
Date:   Thu Aug 15 19:39:35 2024 +0200

    Fix `set`

commit c963e28
Author: Changgyoo Park <[email protected]>
Date:   Thu Aug 15 17:36:14 2024 +0200

    More fix

commit 0c2fad2
Author: Changgyoo Park <[email protected]>
Date:   Thu Aug 15 17:14:37 2024 +0200

    store: use a more optimized get method in scc.rs

    Replace scc::HashMap::get with scc::HashMap::read as scc::HashMap::get
    acquires exclusive locks for entry modification whereas
    scc::HashMap::read acquires shared locks and is more suitable for
    read-heavy workloads.

Co-authored-by: Changgyoo Park <[email protected]>
  • Loading branch information
nerdroychan and changgyoopark-db committed Aug 15, 2024
1 parent 7219bca commit 595a5bb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/stores/scc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ impl KVMap for SccHashMap {

impl KVMapHandle for SccHashMap {
fn set(&mut self, key: &[u8], value: &[u8]) {
if let Err(_) = self.0.insert(key.into(), value.into()) {
assert!(self.0.update(key, |_, v| *v = value.into()).is_some());
match self.0.entry(key.into()) {
scc::hash_map::Entry::Occupied(mut o) => {
*o.get_mut() = value.into();
}
scc::hash_map::Entry::Vacant(v) => {
v.insert_entry(value.into());
}
}
}

fn get(&mut self, key: &[u8]) -> Option<Box<[u8]>> {
match self.0.get(key) {
Some(r) => Some(r.clone()),
None => None,
}
self.0.read(key, |_, r| r.clone())
}

fn delete(&mut self, key: &[u8]) {
Expand Down

0 comments on commit 595a5bb

Please sign in to comment.