Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
fominok committed Nov 28, 2024
1 parent 131e9a5 commit 8da0d5a
Show file tree
Hide file tree
Showing 2 changed files with 361 additions and 39 deletions.
79 changes: 41 additions & 38 deletions grovedb/src/merk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct CachedMerk<'db> {
merk: TxMerk<'db>,
}

// type UpdatedReferences<'b, B> = RefCell<HashSet<(SubtreePath<'b, B>, Vec<u8>)>>;
// type UpdatedReferences<'b, B> = RefCell<HashSet<(SubtreePath<'b, B>,
// Vec<u8>)>>;

/// Helper struct to split `MerkCache` into independent parts to allow splitting
/// borrows, meaning a dependency on the storage part that shall have a certain
Expand Down Expand Up @@ -219,18 +220,18 @@ impl<'db, 'b, B: AsRef<[u8]>> MerkCache<'db, 'b, B> {
// .value_hash(&self.version)
// );

// // The insertion of a reference requires that its hash value be equal to the
// // hash value of the item in the end of the reference's chain:
// let [mut merk] = cost_return_on_error!(&mut cost, self.get_multi_mut([path]));
// cost_return_on_error!(
// // The insertion of a reference requires that its hash value be equal to
// the // hash value of the item in the end of the reference's chain:
// let [mut merk] = cost_return_on_error!(&mut cost,
// self.get_multi_mut([path])); cost_return_on_error!(
// &mut cost,
// merk.insert_internal(key, ref_element.0.clone(), options, Some(value_hash))
// );
// merk.insert_internal(key, ref_element.0.clone(), options,
// Some(value_hash)) );

// let version = self.version.clone(); // TODO

// // The closest referenced item's backward references list of the chain shall be
// // updated with a new entry:
// // The closest referenced item's backward references list of the chain
// shall be // updated with a new entry:
// let [mut closest_merk] = cost_return_on_error!(
// &mut cost,
// self.get_multi_mut([follow_reference_result.first_path])
Expand All @@ -247,8 +248,8 @@ impl<'db, 'b, B: AsRef<[u8]>> MerkCache<'db, 'b, B> {
// // Updated backward references information:
// closest_element = cost_return_on_error_no_add!(
// cost,
// closest_element.referenced_from(ref_element.to_ref_path(), cascade_on_update)
// );
// closest_element.referenced_from(ref_element.to_ref_path(),
// cascade_on_update) );
// // And write it back:
// cost_return_on_error!(
// &mut cost,
Expand Down Expand Up @@ -330,23 +331,23 @@ struct FollowReferenceResult<'b, B> {
last_element: Element,
}

// /// A wrapper type to ensure `Element` is a reference wherever it is required.
// pub(crate) struct ReferenceElement(Element);
// /// A wrapper type to ensure `Element` is a reference wherever it is
// required. pub(crate) struct ReferenceElement(Element);

// impl ReferenceElement {
// fn get_ref_path(&self) -> &ReferencePathType {
// match &self.0 {
// Element::Reference(ref_path, ..) | Element::BidirectionalReference(ref_path, ..) => {
// ref_path
// Element::Reference(ref_path, ..) |
// Element::BidirectionalReference(ref_path, ..) => { ref_path
// }
// _ => unreachable!(),
// }
// }

// fn to_ref_path(self) -> ReferencePathType {
// match self.0 {
// Element::Reference(ref_path, ..) | Element::BidirectionalReference(ref_path, ..) => {
// ref_path
// Element::Reference(ref_path, ..) |
// Element::BidirectionalReference(ref_path, ..) => { ref_path
// }
// _ => unreachable!(),
// }
Expand All @@ -358,8 +359,8 @@ struct FollowReferenceResult<'b, B> {

// fn try_from(value: Element) -> Result<Self, Self::Error> {
// match value {
// element @ Element::Reference(..) | element @ Element::BidirectionalReference(..) => {
// Ok(Self(element))
// element @ Element::Reference(..) | element @
// Element::BidirectionalReference(..) => { Ok(Self(element))
// }
// _ => Err(()),
// }
Expand All @@ -374,15 +375,16 @@ struct FollowReferenceResult<'b, B> {

// fn try_from(value: Element) -> Result<Self, Self::Error> {
// match value {
// Element::Reference(..) | Element::BidirectionalReference(..) => Err(()),
// element => Ok(Self(element)),
// Element::Reference(..) | Element::BidirectionalReference(..) =>
// Err(()), element => Ok(Self(element)),
// }
// }
// }

/// Handle to a cached Merk.
pub(crate) struct MerkHandle<'db, 'c> {

Check warning on line 385 in grovedb/src/merk_cache.rs

View workflow job for this annotation

GitHub Actions / clippy

struct `MerkHandle` is never constructed

warning: struct `MerkHandle` is never constructed --> grovedb/src/merk_cache.rs:385:19 | 385 | pub(crate) struct MerkHandle<'db, 'c> { | ^^^^^^^^^^
/// Reference to an opened Merk tree with transactional batch storage context
/// Reference to an opened Merk tree with transactional batch storage
/// context
merk: &'c mut TxMerk<'db>,
version: &'db GroveVersion,
/// Mark this subtree as a subject to propagate
Expand Down Expand Up @@ -413,8 +415,8 @@ impl<'db, 'c> Deref for MerkHandle<'db, 'c> {
}
}

/// This type represents changes made to a particular element, a difference between its initial
/// state and eventual state
/// This type represents changes made to a particular element, a difference
/// between its initial state and eventual state
enum Delta {

Check warning on line 420 in grovedb/src/merk_cache.rs

View workflow job for this annotation

GitHub Actions / clippy

enum `Delta` is never used

warning: enum `Delta` is never used --> grovedb/src/merk_cache.rs:420:6 | 420 | enum Delta { | ^^^^^
AddItem,
RemoveItem {
Expand Down Expand Up @@ -595,7 +597,7 @@ impl<'db, 'c> MerkHandle<'db, 'c> {
if value.is_some() {
Err(Error::InvalidCodeExecution(
"a tree should be empty at the moment of insertion when not using \
batches",
batches",
))
.wrap_with_cost(Default::default())
} else {
Expand All @@ -621,19 +623,19 @@ impl<'db, 'c> MerkHandle<'db, 'c> {
// ) -> CostResult<(), Error> {
// let mut costs = Default::default();

// // In case the item that was changed has been referenced, we indicate that
// // references should be propagated after
// // In case the item that was changed has been referenced, we indicate
// that // references should be propagated after
// if cost_return_on_error!(
// &mut costs,
// match element {
// Element::Item(..)
// | Element::SumItem(..)
// | Element::ItemWithBackwardsReferences(..)
// | Element::SumItemWithBackwardsReferences(..) => element
// .insert_if_changed_value(self.merk, key, options, self.version)
// .map_ok(|r| r.0),
// Element::Reference(..) | Element::BidirectionalReference(..) => element
// .insert_reference(
// .insert_if_changed_value(self.merk, key, options,
// self.version) .map_ok(|r| r.0),
// Element::Reference(..) | Element::BidirectionalReference(..) =>
// element .insert_reference(
// self.merk,
// key,
// referenced_value_hash.expect("todo"),
Expand All @@ -643,14 +645,14 @@ impl<'db, 'c> MerkHandle<'db, 'c> {
// Element::Tree(ref value, ..) | Element::SumTree(ref value, ..) =>
// if value.is_some() {
// Err(Error::InvalidCodeExecution(
// "a tree should be empty at the moment of insertion when not using \
// batches",
// "a tree should be empty at the moment of insertion
// when not using \ batches",
// ))
// .wrap_with_cost(Default::default())
// } else {
// element
// .insert_subtree(self.merk, key, NULL_HASH, options, self.version)
// .map_ok(|_| false)
// .insert_subtree(self.merk, key, NULL_HASH, options,
// self.version) .map_ok(|_| false)
// },
// }
// ) {
Expand Down Expand Up @@ -815,7 +817,8 @@ mod tests {
// .insert_reference(
// SubtreePath::from(&[TEST_LEAF, b"innertree"]),
// b"ayy",
// Element::new_reference(ReferencePathType::AbsolutePathReference(vec![
//
// Element::new_reference(ReferencePathType::AbsolutePathReference(vec![
// ANOTHER_TEST_LEAF.to_vec(),
// b"innertree2".to_vec(),
// b"k3".to_vec(),
Expand All @@ -831,8 +834,8 @@ mod tests {
// assert!(cache.updated_references.borrow().is_empty());

// let [mut subtree] = cache
// .get_multi_mut([SubtreePath::from(&[ANOTHER_TEST_LEAF, b"innertree2"])])
// .unwrap()
// .get_multi_mut([SubtreePath::from(&[ANOTHER_TEST_LEAF,
// b"innertree2"])]) .unwrap()
// .unwrap();

// subtree
Expand Down
Loading

0 comments on commit 8da0d5a

Please sign in to comment.