From 04d384720040cf409ebc0ba28886a56fe2180bf0 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 4 Jan 2025 17:28:26 +0100 Subject: [PATCH] cargo fmt --- src/db/fjall_adapter.rs | 70 +++++++++++++++++++++++++---------------- src/db/open.rs | 20 ++++++------ src/util/config.rs | 4 +-- 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/db/fjall_adapter.rs b/src/db/fjall_adapter.rs index 3094d64f..57b540c1 100644 --- a/src/db/fjall_adapter.rs +++ b/src/db/fjall_adapter.rs @@ -5,8 +5,8 @@ use std::path::PathBuf; use std::sync::{Arc, RwLock}; use fjall::{ - PartitionCreateOptions, PersistMode, TransactionalKeyspace, - TransactionalPartitionHandle, WriteTransaction, + PartitionCreateOptions, PersistMode, TransactionalKeyspace, TransactionalPartitionHandle, + WriteTransaction, }; use crate::{ @@ -183,13 +183,13 @@ impl IDb for FjallDb { fn iter(&self, tree_idx: usize) -> Result> { let tree = self.get_tree(tree_idx)?; let tx = self.keyspace.read_tx(); - Ok(Box::new(tx.iter(&tree).map(iterator_remap))) + Ok(Box::new(tx.iter(&tree).map(iterator_remap))) } fn iter_rev(&self, tree_idx: usize) -> Result> { let tree = self.get_tree(tree_idx)?; let tx = self.keyspace.read_tx(); - Ok(Box::new(tx.iter(&tree).rev().map(iterator_remap))) + Ok(Box::new(tx.iter(&tree).rev().map(iterator_remap))) } fn range<'r>( @@ -200,7 +200,10 @@ impl IDb for FjallDb { ) -> Result> { let tree = self.get_tree(tree_idx)?; let tx = self.keyspace.read_tx(); - Ok(Box::new(tx.range::<&'r [u8], ByteRefRangeBound>(&tree, (low, high)).map(iterator_remap))) + Ok(Box::new( + tx.range::<&'r [u8], ByteRefRangeBound>(&tree, (low, high)) + .map(iterator_remap), + )) } fn range_rev<'r>( &self, @@ -210,7 +213,11 @@ impl IDb for FjallDb { ) -> Result> { let tree = self.get_tree(tree_idx)?; let tx = self.keyspace.read_tx(); - Ok(Box::new(tx.range::<&'r [u8], ByteRefRangeBound>(&tree, (low, high)).rev().map(iterator_remap))) + Ok(Box::new( + tx.range::<&'r [u8], ByteRefRangeBound>(&tree, (low, high)) + .rev() + .map(iterator_remap), + )) } // ---- @@ -288,11 +295,11 @@ impl<'a> ITx for FjallTx<'a> { fn iter(&self, tree_idx: usize) -> TxOpResult> { let tree = self.get_tree(tree_idx)?.clone(); - Ok(Box::new(self.tx.iter(&tree).map(iterator_remap_tx))) + Ok(Box::new(self.tx.iter(&tree).map(iterator_remap_tx))) } fn iter_rev(&self, tree_idx: usize) -> TxOpResult> { let tree = self.get_tree(tree_idx)?.clone(); - Ok(Box::new(self.tx.iter(&tree).rev().map(iterator_remap_tx))) + Ok(Box::new(self.tx.iter(&tree).rev().map(iterator_remap_tx))) } fn range<'r>( @@ -302,9 +309,13 @@ impl<'a> ITx for FjallTx<'a> { high: Bound<&'r [u8]>, ) -> TxOpResult> { let tree = self.get_tree(tree_idx)?; - let low = clone_bound(low); - let high = clone_bound(high); - Ok(Box::new(self.tx.range::, ByteVecRangeBounds>(&tree, (low, high)).map(iterator_remap_tx))) + let low = clone_bound(low); + let high = clone_bound(high); + Ok(Box::new( + self.tx + .range::, ByteVecRangeBounds>(&tree, (low, high)) + .map(iterator_remap_tx), + )) } fn range_rev<'r>( &self, @@ -313,22 +324,27 @@ impl<'a> ITx for FjallTx<'a> { high: Bound<&'r [u8]>, ) -> TxOpResult> { let tree = self.get_tree(tree_idx)?; - let low = clone_bound(low); - let high = clone_bound(high); - Ok(Box::new(self.tx.range::, ByteVecRangeBounds>(&tree, (low, high)).rev().map(iterator_remap_tx))) + let low = clone_bound(low); + let high = clone_bound(high); + Ok(Box::new( + self.tx + .range::, ByteVecRangeBounds>(&tree, (low, high)) + .rev() + .map(iterator_remap_tx), + )) } } // -- maps fjall's (k, v) to ours fn iterator_remap(r: fjall::Result<(fjall::Slice, fjall::Slice)>) -> Result<(Value, Value)> { - r.map(|(k, v)| (k.to_vec(), v.to_vec())) - .map_err(|e| e.into()) + r.map(|(k, v)| (k.to_vec(), v.to_vec())) + .map_err(|e| e.into()) } fn iterator_remap_tx(r: fjall::Result<(fjall::Slice, fjall::Slice)>) -> TxOpResult<(Value, Value)> { - r.map(|(k, v)| (k.to_vec(), v.to_vec())) - .map_err(|e| e.into()) + r.map(|(k, v)| (k.to_vec(), v.to_vec())) + .map_err(|e| e.into()) } // -- utils to deal with Garage's tightness on Bound lifetimes @@ -337,14 +353,14 @@ type ByteVecBound = Bound>; type ByteVecRangeBounds = (ByteVecBound, ByteVecBound); fn clone_bound(bound: Bound<&[u8]>) -> ByteVecBound { - let value = match bound { - Bound::Excluded(v) | Bound::Included(v) => v.to_vec(), - Bound::Unbounded => vec!(), - }; + let value = match bound { + Bound::Excluded(v) | Bound::Included(v) => v.to_vec(), + Bound::Unbounded => vec![], + }; - match bound { - Bound::Included(_) => Bound::Included(value), - Bound::Excluded(_) => Bound::Excluded(value), - Bound::Unbounded => Bound::Unbounded, - } + match bound { + Bound::Included(_) => Bound::Included(value), + Bound::Excluded(_) => Bound::Excluded(value), + Bound::Unbounded => Bound::Unbounded, + } } diff --git a/src/db/open.rs b/src/db/open.rs index a6ec7b00..83ae1f93 100644 --- a/src/db/open.rs +++ b/src/db/open.rs @@ -1,6 +1,6 @@ +use std::convert::TryInto; use std::path::PathBuf; use std::sync::Arc; -use std::convert::TryInto; use crate::{Db, Error, Result}; @@ -56,7 +56,7 @@ impl std::str::FromStr for Engine { pub struct OpenOpt { pub fsync: bool, pub lmdb_map_size: Option, - pub fjall_block_cache_size: Option, + pub fjall_block_cache_size: Option, } impl Default for OpenOpt { @@ -64,7 +64,7 @@ impl Default for OpenOpt { Self { fsync: false, lmdb_map_size: None, - fjall_block_cache_size: None, + fjall_block_cache_size: None, } } } @@ -125,12 +125,14 @@ pub fn open_db(path: &PathBuf, engine: Engine, opt: &OpenOpt) -> Result { #[cfg(feature = "fjall")] Engine::Fjall => { info!("Opening Fjall database at: {}", path.display()); - let fsync_ms = opt.fsync.then(|| 1000 as u16); - let mut config = fjall::Config::new(path).fsync_ms(fsync_ms); - if let Some(block_cache_size) = opt.fjall_block_cache_size { - let block_cache = Arc::new(fjall::BlockCache::with_capacity_bytes(block_cache_size.try_into().unwrap())); - config = config.block_cache(block_cache); - } + let fsync_ms = opt.fsync.then(|| 1000 as u16); + let mut config = fjall::Config::new(path).fsync_ms(fsync_ms); + if let Some(block_cache_size) = opt.fjall_block_cache_size { + let block_cache = Arc::new(fjall::BlockCache::with_capacity_bytes( + block_cache_size.try_into().unwrap(), + )); + config = config.block_cache(block_cache); + } let keyspace = config.open_transactional()?; Ok(crate::fjall_adapter::FjallDb::init(path, keyspace)) } diff --git a/src/util/config.rs b/src/util/config.rs index afdd8374..c17f3ce0 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -115,8 +115,8 @@ pub struct Config { #[serde(deserialize_with = "deserialize_capacity", default)] pub lmdb_map_size: usize, - /// Fjall block cache size - #[serde(deserialize_with = "deserialize_capacity", default)] + /// Fjall block cache size + #[serde(deserialize_with = "deserialize_capacity", default)] pub fjall_block_cache_size: usize, // -- APIs