From 6fe0ea05b80a87cf02182396b029620132ee0855 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 17 Mar 2024 02:04:05 -0400 Subject: [PATCH] add remove_batch with transaction to database abstraction. adjusted to make building sqlite happy again Signed-off-by: Jason Volk Signed-off-by: strawberry --- src/database/abstraction.rs | 4 ++++ src/database/abstraction/rocksdb.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/database/abstraction.rs b/src/database/abstraction.rs index dd331ed3..fdf93089 100644 --- a/src/database/abstraction.rs +++ b/src/database/abstraction.rs @@ -43,6 +43,10 @@ pub(crate) trait KvTree: Send + Sync { fn remove(&self, key: &[u8]) -> Result<()>; + #[allow(dead_code)] + #[cfg(feature = "rocksdb")] + fn remove_batch(&self, _iter: &mut dyn Iterator>) -> Result<()> { unimplemented!() } + fn iter<'a>(&'a self) -> Box, Vec)> + 'a>; fn iter_from<'a>(&'a self, from: &[u8], backwards: bool) -> Box, Vec)> + 'a>; diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index 584c6e70..729c34d2 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -251,6 +251,18 @@ impl KvTree for RocksDbEngineTree<'_> { Ok(self.db.rocks.delete_cf_opt(&self.cf(), key, &writeoptions)?) } + fn remove_batch(&self, iter: &mut dyn Iterator>) -> Result<()> { + let writeoptions = rust_rocksdb::WriteOptions::default(); + + let mut batch = WriteBatchWithTransaction::::default(); + + for key in iter { + batch.delete_cf(&self.cf(), key); + } + + Ok(self.db.rocks.write_opt(batch, &writeoptions)?) + } + fn iter<'a>(&'a self) -> Box, Vec)> + 'a> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true);