Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jul 10, 2024
1 parent 527ff74 commit ab3ff66
Show file tree
Hide file tree
Showing 69 changed files with 4,025 additions and 1,319 deletions.
61 changes: 28 additions & 33 deletions grovedb-version/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
use crate::version::GroveVersion;

pub mod version;
pub mod error;
pub mod version;

#[macro_export]
macro_rules! check_v0_with_cost {
($method:expr, $version:expr) => {
{
const EXPECTED_VERSION: u16 = 0;
if $version != EXPECTED_VERSION {
return Err(GroveVersionError::UnknownVersionMismatch {
method: $method.to_string(),
known_versions: vec![EXPECTED_VERSION],
received: $version,
}
.into())
.wrap_with_cost(OperationCost::default());
($method:expr, $version:expr) => {{
const EXPECTED_VERSION: u16 = 0;
if $version != EXPECTED_VERSION {
return Err(GroveVersionError::UnknownVersionMismatch {
method: $method.to_string(),
known_versions: vec![EXPECTED_VERSION],
received: $version,
}
.into())
.wrap_with_cost(OperationCost::default());
}
};
}};
}

#[macro_export]
macro_rules! check_v0 {
($method:expr, $version:expr) => {
{
const EXPECTED_VERSION: u16 = 0;
if $version != EXPECTED_VERSION {
return Err(GroveVersionError::UnknownVersionMismatch {
method: $method.to_string(),
known_versions: vec![EXPECTED_VERSION],
received: $version,
}
.into());
($method:expr, $version:expr) => {{
const EXPECTED_VERSION: u16 = 0;
if $version != EXPECTED_VERSION {
return Err(GroveVersionError::UnknownVersionMismatch {
method: $method.to_string(),
known_versions: vec![EXPECTED_VERSION],
received: $version,
}
.into());
}
};
}};
}

pub trait TryFromVersioned<T>: Sized {
Expand All @@ -54,7 +50,6 @@ pub trait TryIntoVersioned<T>: Sized {
fn try_into_versioned(self, grove_version: &GroveVersion) -> Result<T, Self::Error>;
}


impl<T, U> TryIntoVersioned<U> for T
where
U: TryFromVersioned<T>,
Expand All @@ -67,14 +62,14 @@ where
}
}

impl <T, U> TryFromVersioned<U> for T
where
impl<T, U> TryFromVersioned<U> for T
where
T: TryFrom<U>,
{
type Error = T::Error;
{
type Error = T::Error;

#[inline]
fn try_from_versioned(value: U, _grove_version: &GroveVersion) -> Result<Self, Self::Error> {
T::try_from(value)
}
#[inline]
fn try_from_versioned(value: U, _grove_version: &GroveVersion) -> Result<Self, Self::Error> {
T::try_from(value)
}
}
2 changes: 1 addition & 1 deletion grovedb-version/src/version/grovedb_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ pub struct GroveDBElementMethodVersions {
pub serialize: FeatureVersion,
pub serialized_size: FeatureVersion,
pub deserialize: FeatureVersion,
}
}
6 changes: 3 additions & 3 deletions grovedb-version/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub mod grovedb_versions;
pub mod v1;

pub use versioned_feature_core::*;
use crate::version::grovedb_versions::GroveDBVersions;
use crate::version::v1::GROVE_V1;

use crate::version::{grovedb_versions::GroveDBVersions, v1::GROVE_V1};

#[derive(Clone, Debug, Default)]
pub struct GroveVersion {
Expand All @@ -19,4 +19,4 @@ impl GroveVersion {
}
}

pub const GROVE_VERSIONS: &[GroveVersion] = &[GROVE_V1];
pub const GROVE_VERSIONS: &[GroveVersion] = &[GROVE_V1];
13 changes: 10 additions & 3 deletions grovedb-version/src/version/v1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use crate::version::grovedb_versions::{GroveDBOperationsAverageCaseVersions, GroveDBOperationsDeleteUpTreeVersions, GroveDBOperationsDeleteVersions, GroveDBOperationsGetVersions, GroveDBOperationsInsertVersions, GroveDBOperationsQueryVersions, GroveDBOperationsVersions, GroveDBOperationsWorstCaseVersions, GroveDBVersions};
use crate::version::GroveVersion;
use crate::version::{
grovedb_versions::{
GroveDBOperationsAverageCaseVersions, GroveDBOperationsDeleteUpTreeVersions,
GroveDBOperationsDeleteVersions, GroveDBOperationsGetVersions,
GroveDBOperationsInsertVersions, GroveDBOperationsQueryVersions, GroveDBOperationsVersions,
GroveDBOperationsWorstCaseVersions, GroveDBVersions,
},
GroveVersion,
};

pub const GROVE_V1: GroveVersion = GroveVersion {
protocol_version: 0,
Expand Down Expand Up @@ -85,4 +92,4 @@ pub const GROVE_V1: GroveVersion = GroveVersion {
},
},
},
};
};
52 changes: 40 additions & 12 deletions grovedb/benches/insertion_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ pub fn insertion_benchmark_without_transaction(c: &mut Criterion) {
let dir = TempDir::new().unwrap();
let db = GroveDb::open(dir.path()).unwrap();
let test_leaf: &[u8] = b"leaf1";
db.insert(EMPTY_PATH, test_leaf, Element::empty_tree(), None, None, grove_version)
.unwrap()
.unwrap();
db.insert(
EMPTY_PATH,
test_leaf,
Element::empty_tree(),
None,
None,
grove_version,
)
.unwrap()
.unwrap();
let keys = std::iter::repeat_with(|| rand::thread_rng().gen::<[u8; 32]>()).take(N_ITEMS);

c.bench_function("scalars insertion without transaction", |b| {
Expand Down Expand Up @@ -80,9 +87,16 @@ pub fn insertion_benchmark_with_transaction(c: &mut Criterion) {
let dir = TempDir::new().unwrap();
let db = GroveDb::open(dir.path()).unwrap();
let test_leaf: &[u8] = b"leaf1";
db.insert(EMPTY_PATH, test_leaf, Element::empty_tree(), None, None, grove_version)
.unwrap()
.unwrap();
db.insert(
EMPTY_PATH,
test_leaf,
Element::empty_tree(),
None,
None,
grove_version,
)
.unwrap()
.unwrap();
let keys = std::iter::repeat_with(|| rand::thread_rng().gen::<[u8; 32]>()).take(N_ITEMS);

c.bench_function("scalars insertion with transaction", |b| {
Expand Down Expand Up @@ -115,9 +129,16 @@ pub fn root_leaf_insertion_benchmark_without_transaction(c: &mut Criterion) {
c.bench_function("root leaves insertion without transaction", |b| {
b.iter(|| {
for k in keys.clone() {
db.insert(EMPTY_PATH, &k, Element::empty_tree(), None, None, grove_version)
.unwrap()
.unwrap();
db.insert(
EMPTY_PATH,
&k,
Element::empty_tree(),
None,
None,
grove_version,
)
.unwrap()
.unwrap();
}
})
});
Expand All @@ -134,9 +155,16 @@ pub fn root_leaf_insertion_benchmark_with_transaction(c: &mut Criterion) {
b.iter(|| {
let tx = db.start_transaction();
for k in keys.clone() {
db.insert(EMPTY_PATH, &k, Element::empty_tree(), None, Some(&tx), grove_version)
.unwrap()
.unwrap();
db.insert(
EMPTY_PATH,
&k,
Element::empty_tree(),
None,
Some(&tx),
grove_version,
)
.unwrap()
.unwrap();
}
db.commit_transaction(tx).unwrap().unwrap();
})
Expand Down
58 changes: 44 additions & 14 deletions grovedb/src/batch/estimated_costs/average_case_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use grovedb_merk::{
};
#[cfg(feature = "full")]
use grovedb_storage::rocksdb_storage::RocksDbStorage;
use grovedb_version::version::GroveVersion;
#[cfg(feature = "full")]
use itertools::Itertools;
use grovedb_version::version::GroveVersion;

use crate::Element;
#[cfg(feature = "full")]
use crate::{
Expand Down Expand Up @@ -110,9 +111,12 @@ impl Op {
propagate_if_input(),
grove_version,
),
Op::Delete => {
GroveDb::average_case_merk_delete_element(key, layer_element_estimates, propagate, grove_version)
}
Op::Delete => GroveDb::average_case_merk_delete_element(
key,
layer_element_estimates,
propagate,
grove_version,
),
Op::DeleteTree => GroveDb::average_case_merk_delete_tree(
key,
false,
Expand Down Expand Up @@ -251,7 +255,11 @@ impl<G, SR> TreeCache<G, SR> for AverageCaseTreeCacheKnownPaths {
Ok(([0u8; 32], None, None)).wrap_with_cost(cost)
}

fn update_base_merk_root_key(&mut self, _root_key: Option<Vec<u8>>, grove_version: &GroveVersion) -> CostResult<(), Error> {
fn update_base_merk_root_key(
&mut self,
_root_key: Option<Vec<u8>>,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
let mut cost = OperationCost::default();
cost.seek_count += 1;
let base_path = KeyInfoPath(vec![]);
Expand Down Expand Up @@ -291,6 +299,7 @@ mod tests {
EstimatedSumTrees::{NoSumTrees, SomeSumTrees},
};
use grovedb_version::version::GroveVersion;

use crate::{
batch::{
estimated_costs::EstimatedCostsType::AverageCaseCostsType, key_info::KeyInfo,
Expand Down Expand Up @@ -504,9 +513,16 @@ mod tests {
let db = make_empty_grovedb();
let tx = db.start_transaction();

db.insert(EMPTY_PATH, b"0", Element::empty_tree(), None, Some(&tx), grove_version)
.unwrap()
.expect("successful root tree leaf insert");
db.insert(
EMPTY_PATH,
b"0",
Element::empty_tree(),
None,
Some(&tx),
grove_version,
)
.unwrap()
.expect("successful root tree leaf insert");

let ops = vec![GroveDbOp::insert_op(
vec![],
Expand Down Expand Up @@ -583,9 +599,16 @@ mod tests {
let db = make_empty_grovedb();
let tx = db.start_transaction();

db.insert(EMPTY_PATH, b"0", Element::empty_tree(), None, Some(&tx), grove_version)
.unwrap()
.expect("successful root tree leaf insert");
db.insert(
EMPTY_PATH,
b"0",
Element::empty_tree(),
None,
Some(&tx),
grove_version,
)
.unwrap()
.expect("successful root tree leaf insert");

let ops = vec![GroveDbOp::insert_op(
vec![b"0".to_vec()],
Expand Down Expand Up @@ -734,9 +757,16 @@ mod tests {
let db = make_empty_grovedb();
let tx = db.start_transaction();

db.insert(EMPTY_PATH, b"keyb", Element::empty_tree(), None, Some(&tx), grove_version)
.unwrap()
.expect("successful root tree leaf insert");
db.insert(
EMPTY_PATH,
b"keyb",
Element::empty_tree(),
None,
Some(&tx),
grove_version,
)
.unwrap()
.expect("successful root tree leaf insert");

let ops = vec![GroveDbOp::insert_op(
vec![],
Expand Down
Loading

0 comments on commit ab3ff66

Please sign in to comment.