diff --git a/Cargo.toml b/Cargo.toml index 076affe..a6fdb40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"] ahash = "0.8.11" bincode = "1.3.3" chashmap = { version = "2.2.2", optional = true } -clap = { version = "=4.5.11", features = ["derive"] } +clap = { version = "=4.5.13", features = ["derive"] } contrie = { version = "0.1.4", optional = true } core_affinity = "0.8.1" ctrlc = "3.4.4" @@ -32,13 +32,14 @@ hdrhistogram = "7.5.4" inventory = "0.3.15" log = "0.4.22" mio = { version = "1.0.1", features = ["net", "os-poll"] } -papaya = { version = "0.1.2", optional = true } +papaya = { version = "0.1.3", optional = true } parking_lot = "0.12.3" quanta = "0.12.3" rand = "0.8.5" +rocksdb = { version = "0.22.0", optional = true } scc = { version = "2.1.6", optional = true } serde = { version = "1.0.204", features = ["derive"] } -toml = "0.8.16" +toml = "0.8.19" zipf = "7.0.1" [features] @@ -47,6 +48,7 @@ contrie = ["dep:contrie"] dashmap = ["dep:dashmap"] flurry = ["dep:flurry"] papaya = ["dep:papaya"] +rocksdb = ["dep:rocksdb"] scc = ["dep:scc"] [profile.release-lto] diff --git a/src/stores.rs b/src/stores.rs index 26ccd8b..b67f739 100644 --- a/src/stores.rs +++ b/src/stores.rs @@ -133,6 +133,8 @@ pub mod null; #[cfg(feature = "papaya")] pub mod papaya; pub mod remote; +#[cfg(feature = "rocksdb")] +pub mod rocksdb; #[cfg(feature = "scc")] pub mod scc; diff --git a/src/stores/rocksdb.rs b/src/stores/rocksdb.rs new file mode 100644 index 0000000..8ef0205 --- /dev/null +++ b/src/stores/rocksdb.rs @@ -0,0 +1,66 @@ +//! Adapter implementation of [`rocksdb`]. +//! +//! ## Configuration Format +//! +//! ``` toml +//! [map] +//! name = "rocksdb" +//! path = "..." # path to the rocksdb data directory +//! ``` +//! +//! This store is [`KVMap`]. + +use crate::stores::{BenchKVMap, Registry}; +use crate::*; +use serde::Deserialize; +use rocksdb::DB; + +#[derive(Deserialize)] +pub struct RocksDBOpt { + path: String, +} + +#[derive(Clone)] +pub struct RocksDB { + db: Arc, +} + +impl RocksDB { + pub fn new(opt: &RocksDBOpt) -> Self { + let db = Arc::new(DB::open_default(&opt.path).unwrap()); + Self { db } + } + + pub fn new_benchkvmap(opt: &toml::Table) -> BenchKVMap { + let opt: RocksDBOpt = opt.clone().try_into().unwrap(); + BenchKVMap::Regular(Box::new(Self::new(&opt))) + } +} + +impl KVMap for RocksDB { + fn handle(&self) -> Box { + Box::new(self.clone()) + } +} + +impl KVMapHandle for RocksDB { + fn set(&mut self, key: &[u8], value: &[u8]) { + assert!(self.db.put(key, value).is_ok()); + } + + fn get(&mut self, key: &[u8]) -> Option> { + if let Ok(v) = self.db.get(key) { + v.map(|vec| vec.into_boxed_slice()) + } else { + None + } + } + + fn delete(&mut self, key: &[u8]) { + assert!(self.db.delete(key).is_ok()); + } +} + +inventory::submit! { + Registry::new("rocksdb", RocksDB::new_benchkvmap) +}