remove sled, upgrade rocksdb and rusqlite to conduit's version

This commit is contained in:
Jonathan de Jong 2024-05-04 12:01:34 +02:00
parent 7cc4616fbf
commit 6ee110e5ba
10 changed files with 127 additions and 363 deletions

View file

@ -10,12 +10,20 @@ itertools = "0.10.1"
thiserror = "1.0.26"
anyhow = "1.0.42"
sled = { version = "0.34.6", features = ["compression", "no_metrics"], optional = true }
rusqlite = { version = "0.25.3", features = ["bundled"], optional = true }
rusqlite = { version = "0.31", features = ["bundled"], optional = true }
heed = { git = "https://github.com/timokoesters/heed.git", rev = "f6f825da7fb2c758867e05ad973ef800a6fe1d5d", optional = true }
rocksdb = { version = "0.17.0", features = ["multi-threaded-cf", "zstd"], optional = true }
persy = { version = "1.2", optional = true }
[dependencies.rocksdb]
package = "rust-rocksdb"
version = "0.25"
optional = true
features = [
"multi-threaded-cf",
"zstd",
"lz4",
]
[features]
default = []

View file

@ -4,8 +4,6 @@ pub mod heed;
pub mod persy;
#[cfg(feature = "rocksdb")]
pub mod rocksdb;
#[cfg(feature = "sled")]
pub mod sled;
#[cfg(feature = "sqlite")]
pub mod sqlite;

View file

@ -131,7 +131,10 @@ impl super::SegmentIter for RocksDBCFIter<'_> {
.db
.rocks
.iterator_cf(&self.0.cf(), rocksdb::IteratorMode::Start)
.map(|(k, v)| (Vec::from(k), Vec::from(v))),
.map(|r| {
let (k, v) = r.expect("we expect rocksdb to give us good rows only");
(Vec::from(k), Vec::from(v))
}),
)
}
}

View file

@ -1,73 +0,0 @@
use super::{Database, KVIter, Segment, SegmentIter};
use itertools::Itertools;
use sled::{Batch, Config, Db, Result, Tree};
use std::path::Path;
pub fn new_db<P: AsRef<Path>>(path: P) -> Result<Db> {
Config::default().path(path).use_compression(true).open()
}
pub struct SledDB(Db);
impl SledDB {
pub fn new(db: Db) -> Self {
Self(db)
}
}
const SLED_DEFAULT: &[u8] = "__sled__default".as_bytes();
impl Database for SledDB {
fn names<'a>(&'a self) -> Vec<Vec<u8>> {
self.0
.tree_names()
.into_iter()
.filter(|v| v != SLED_DEFAULT)
.map(|v| v.to_vec())
.collect_vec()
}
fn segment(&mut self, name: Vec<u8>) -> Option<Box<dyn Segment>> {
self.0
.open_tree(name)
.ok()
.map(|t| -> Box<dyn Segment> { Box::new(t) })
}
fn flush(&mut self) {
self.0.flush().unwrap();
}
}
impl Segment for Tree {
fn batch_insert(
&mut self,
batch: Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + '_>,
) -> anyhow::Result<()> {
let mut sled_batch = Batch::default();
for (k, v) in batch {
sled_batch.insert(k, v)
}
self.apply_batch(sled_batch).map_err(Into::into)
}
fn get_iter<'a>(&'a mut self) -> Box<dyn super::SegmentIter + 'a> {
Box::new(SledTreeIter(self))
}
}
struct SledTreeIter<'a>(&'a mut Tree);
impl SegmentIter for SledTreeIter<'_> {
fn iter<'a>(&'a mut self) -> KVIter<'a> {
Box::new(self.0.iter().filter_map(|r| {
if let Ok(t) = r {
Some((t.0.to_vec(), t.1.to_vec()))
} else {
None
}
}))
}
}