From 0bd512a14ca26c89a0c71e29c4c6e72cf1b247ee Mon Sep 17 00:00:00 2001 From: Tpt Date: Sat, 23 Oct 2021 19:09:34 +0200 Subject: [PATCH] Avoids using API without column families --- lib/src/storage/mod.rs | 14 +++++---- lib/src/storage/rocksdb_backend.rs | 46 ------------------------------ 2 files changed, 8 insertions(+), 52 deletions(-) diff --git a/lib/src/storage/mod.rs b/lib/src/storage/mod.rs index d4d965cb..c36ed77c 100644 --- a/lib/src/storage/mod.rs +++ b/lib/src/storage/mod.rs @@ -33,6 +33,7 @@ const DSPO_CF: &str = "dspo"; const DPOS_CF: &str = "dpos"; const DOSP_CF: &str = "dosp"; const GRAPHS_CF: &str = "graphs"; +const DEFAULT_CF: &str = "default"; const COLUMN_FAMILIES: [&str; 11] = [ ID2STR_CF, SPOG_CF, POSG_CF, OSPG_CF, GSPO_CF, GPOS_CF, GOSP_CF, DSPO_CF, DPOS_CF, DOSP_CF, @@ -42,7 +43,8 @@ const COLUMN_FAMILIES: [&str; 11] = [ /// Low level storage primitives #[derive(Clone)] pub struct Storage { - default: Db, + db: Db, + default: Tree, id2str: Tree, spog: Tree, posg: Tree, @@ -68,6 +70,7 @@ impl Storage { fn setup(db: Db) -> std::io::Result { let this = Self { + default: db.open_tree(DEFAULT_CF)?, id2str: db.open_tree(ID2STR_CF)?, spog: db.open_tree(SPOG_CF)?, posg: db.open_tree(POSG_CF)?, @@ -79,7 +82,7 @@ impl Storage { dpos: db.open_tree(DPOS_CF)?, dosp: db.open_tree(DOSP_CF)?, graphs: db.open_tree(GRAPHS_CF)?, - default: db, + db, }; let mut version = this.ensure_version()?; @@ -93,7 +96,7 @@ impl Storage { } version = 1; this.set_version(version)?; - this.default.flush()?; + this.db.flush()?; } if version == 1 { // We migrate to v2 @@ -108,7 +111,7 @@ impl Storage { iter.status()?; version = 2; this.set_version(version)?; - this.default.flush()?; + this.db.flush()?; } match version { @@ -652,8 +655,7 @@ impl Storage { #[cfg(not(target_arch = "wasm32"))] pub fn flush(&self) -> std::io::Result<()> { - self.default.flush()?; - Ok(()) + self.db.flush() } pub fn get_str(&self, key: &StrHash) -> std::io::Result> { diff --git a/lib/src/storage/rocksdb_backend.rs b/lib/src/storage/rocksdb_backend.rs index 1837c4f1..85689f29 100644 --- a/lib/src/storage/rocksdb_backend.rs +++ b/lib/src/storage/rocksdb_backend.rs @@ -196,52 +196,6 @@ impl Db { r } } - - pub fn get(&self, key: &[u8]) -> Result>> { - unsafe { - let options = rocksdb_readoptions_create(); - assert!( - !options.is_null(), - "rocksdb_readoptions_create returned null" - ); - let r = ffi_result!(rocksdb_get_pinned( - self.0.db, - options, - key.as_ptr() as *const c_char, - key.len() - )); - rocksdb_readoptions_destroy(options); - let slice = r?; - Ok(if slice.is_null() { - None - } else { - Some(PinnableSlice { - slice, - lifetime: PhantomData::default(), - }) - }) - } - } - - pub fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> { - unsafe { - let options = rocksdb_writeoptions_create(); - assert!( - !options.is_null(), - "rocksdb_writeoptions_create returned null" - ); - let r = ffi_result!(rocksdb_put( - self.0.db, - options, - key.as_ptr() as *const c_char, - key.len(), - value.as_ptr() as *const c_char, - value.len(), - )); - rocksdb_writeoptions_destroy(options); - r - } - } } #[derive(Clone)]