Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: big sum trees and count trees #348

Merged
merged 33 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0885d05
aggregate sum tree types
QuantumExplorer Jan 7, 2025
b3e287b
more work
QuantumExplorer Jan 7, 2025
a414fa2
more work
QuantumExplorer Jan 7, 2025
1483e18
more work
QuantumExplorer Jan 7, 2025
cac1b37
fmt
QuantumExplorer Jan 8, 2025
a46c4da
fixes and tests
QuantumExplorer Jan 8, 2025
3f6705f
added count sum tree
QuantumExplorer Jan 8, 2025
1ba42f5
fixes
QuantumExplorer Jan 9, 2025
7d91f00
more work
QuantumExplorer Jan 9, 2025
e2d68fb
cleanup
QuantumExplorer Jan 9, 2025
85aeb8c
cleanup
QuantumExplorer Jan 9, 2025
64f26bf
cleanup
QuantumExplorer Jan 9, 2025
35c64c3
fix
QuantumExplorer Jan 9, 2025
2417f7a
fix
QuantumExplorer Jan 9, 2025
558bd55
added helpers
QuantumExplorer Jan 10, 2025
263dcd5
more fixes
QuantumExplorer Jan 10, 2025
a25cc07
better error when key not found
QuantumExplorer Jan 12, 2025
4375da5
feat: append error context (#353)
fominok Jan 14, 2025
8860e6b
Merge remote-tracking branch 'origin/develop' into feat/bigSumTrees
fominok Jan 15, 2025
384894f
merge fixes
fominok Jan 15, 2025
9e313f4
Merge branch 'develop' into feat/bigSumTrees
QuantumExplorer Jan 16, 2025
cee2f29
Merge branch 'feat/bigSumTrees' of github.com:dashevo/grovedb into fe…
QuantumExplorer Jan 16, 2025
20705a3
fixes
QuantumExplorer Jan 16, 2025
28ceab5
fixes
QuantumExplorer Jan 16, 2025
fcfee9e
fixes
QuantumExplorer Jan 16, 2025
7760e04
fixes
QuantumExplorer Jan 16, 2025
867b476
fixes
QuantumExplorer Jan 16, 2025
4005e34
more refactoring
QuantumExplorer Jan 16, 2025
d36c2e8
more refactoring
QuantumExplorer Jan 16, 2025
2f14efb
more refactoring
QuantumExplorer Jan 16, 2025
7dbf367
more refactoring
QuantumExplorer Jan 16, 2025
d8ae2d9
more refactoring
QuantumExplorer Jan 16, 2025
b7e0cb2
fix
fominok Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion grovedb-version/src/version/merk_versions.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
use versioned_feature_core::FeatureVersion;

#[derive(Clone, Debug, Default)]
pub struct MerkVersions {}
pub struct MerkVersions {
pub average_case_costs: MerkAverageCaseCostsVersions,
}

#[derive(Clone, Debug, Default)]
pub struct MerkAverageCaseCostsVersions {
pub add_average_case_merk_propagate: FeatureVersion,
}
11 changes: 9 additions & 2 deletions grovedb-version/src/version/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pub mod grovedb_versions;
pub mod merk_versions;
pub mod v1;
pub mod v2;

pub use versioned_feature_core::*;

use crate::version::{
grovedb_versions::GroveDBVersions, merk_versions::MerkVersions, v1::GROVE_V1,
grovedb_versions::GroveDBVersions, merk_versions::MerkVersions, v1::GROVE_V1, v2::GROVE_V2,
};

#[derive(Clone, Debug, Default)]
Expand All @@ -16,11 +17,17 @@ pub struct GroveVersion {
}

impl GroveVersion {
pub fn first<'a>() -> &'a Self {
GROVE_VERSIONS
.first()
.expect("expected to have a platform version")
}

pub fn latest<'a>() -> &'a Self {
GROVE_VERSIONS
.last()
.expect("expected to have a platform version")
}
}

pub const GROVE_VERSIONS: &[GroveVersion] = &[GROVE_V1];
pub const GROVE_VERSIONS: &[GroveVersion] = &[GROVE_V1, GROVE_V2];
8 changes: 6 additions & 2 deletions grovedb-version/src/version/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::version::{
GroveDBOperationsWorstCaseVersions, GroveDBPathQueryMethodVersions,
GroveDBReplicationVersions, GroveDBVersions,
},
merk_versions::MerkVersions,
merk_versions::{MerkAverageCaseCostsVersions, MerkVersions},
GroveVersion,
};

Expand Down Expand Up @@ -184,5 +184,9 @@ pub const GROVE_V1: GroveVersion = GroveVersion {
apply_chunk: 0,
},
},
merk_versions: MerkVersions {},
merk_versions: MerkVersions {
average_case_costs: MerkAverageCaseCostsVersions {
add_average_case_merk_propagate: 0,
},
},
};
192 changes: 192 additions & 0 deletions grovedb-version/src/version/v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
use crate::version::{
grovedb_versions::{
GroveDBApplyBatchVersions, GroveDBElementMethodVersions,
GroveDBOperationsAverageCaseVersions, GroveDBOperationsDeleteUpTreeVersions,
GroveDBOperationsDeleteVersions, GroveDBOperationsGetVersions,
GroveDBOperationsInsertVersions, GroveDBOperationsProofVersions,
GroveDBOperationsQueryVersions, GroveDBOperationsVersions,
GroveDBOperationsWorstCaseVersions, GroveDBPathQueryMethodVersions,
GroveDBReplicationVersions, GroveDBVersions,
},
merk_versions::{MerkAverageCaseCostsVersions, MerkVersions},
GroveVersion,
};

pub const GROVE_V2: GroveVersion = GroveVersion {
protocol_version: 0,
grovedb_versions: GroveDBVersions {
apply_batch: GroveDBApplyBatchVersions {
apply_batch_structure: 0,
apply_body: 0,
continue_partial_apply_body: 0,
apply_operations_without_batching: 0,
apply_batch: 0,
apply_partial_batch: 0,
open_batch_transactional_merk_at_path: 0,
open_batch_merk_at_path: 0,
apply_batch_with_element_flags_update: 0,
apply_partial_batch_with_element_flags_update: 0,
estimated_case_operations_for_batch: 0,
},
element: GroveDBElementMethodVersions {
delete: 0,
delete_with_sectioned_removal_bytes: 0,
delete_into_batch_operations: 0,
element_at_key_already_exists: 0,
get: 0,
get_optional: 0,
get_from_storage: 0,
get_optional_from_storage: 1,
get_with_absolute_refs: 0,
get_value_hash: 0,
get_specialized_cost: 0,
value_defined_cost: 0,
value_defined_cost_for_serialized_value: 0,
specialized_costs_for_key_value: 0,
required_item_space: 0,
insert: 0,
insert_into_batch_operations: 0,
insert_if_not_exists: 0,
insert_if_not_exists_into_batch_operations: 0,
insert_if_changed_value: 0,
insert_if_changed_value_into_batch_operations: 0,
insert_reference: 0,
insert_reference_into_batch_operations: 0,
insert_subtree: 0,
insert_subtree_into_batch_operations: 0,
get_query: 0,
get_query_values: 0,
get_query_apply_function: 0,
get_path_query: 0,
get_sized_query: 0,
path_query_push: 0,
query_item: 0,
basic_push: 0,
serialize: 0,
serialized_size: 0,
deserialize: 0,
},
operations: GroveDBOperationsVersions {
get: GroveDBOperationsGetVersions {
get: 0,
get_caching_optional: 0,
follow_reference: 0,
get_raw: 0,
get_raw_caching_optional: 0,
get_raw_optional: 0,
get_raw_optional_caching_optional: 0,
has_raw: 0,
check_subtree_exists_invalid_path: 0,
average_case_for_has_raw: 0,
average_case_for_has_raw_tree: 0,
average_case_for_get_raw: 0,
average_case_for_get: 0,
average_case_for_get_tree: 0,
worst_case_for_has_raw: 0,
worst_case_for_get_raw: 0,
worst_case_for_get: 0,
is_empty_tree: 0,
},
insert: GroveDBOperationsInsertVersions {
insert: 0,
insert_on_transaction: 0,
insert_without_transaction: 0,
add_element_on_transaction: 0,
add_element_without_transaction: 0,
insert_if_not_exists: 0,
insert_if_not_exists_return_existing_element: 0,
insert_if_changed_value: 0,
},
delete: GroveDBOperationsDeleteVersions {
delete: 0,
clear_subtree: 0,
delete_with_sectional_storage_function: 0,
delete_if_empty_tree: 0,
delete_if_empty_tree_with_sectional_storage_function: 0,
delete_operation_for_delete_internal: 0,
delete_internal_on_transaction: 0,
delete_internal_without_transaction: 0,
average_case_delete_operation_for_delete: 0,
worst_case_delete_operation_for_delete: 0,
},
delete_up_tree: GroveDBOperationsDeleteUpTreeVersions {
delete_up_tree_while_empty: 0,
delete_up_tree_while_empty_with_sectional_storage: 0,
delete_operations_for_delete_up_tree_while_empty: 0,
add_delete_operations_for_delete_up_tree_while_empty: 0,
average_case_delete_operations_for_delete_up_tree_while_empty: 0,
worst_case_delete_operations_for_delete_up_tree_while_empty: 0,
},
query: GroveDBOperationsQueryVersions {
query_encoded_many: 0,
query_many_raw: 0,
get_proved_path_query: 0,
query: 0,
query_item_value: 0,
query_item_value_or_sum: 0,
query_sums: 0,
query_raw: 0,
query_keys_optional: 0,
query_raw_keys_optional: 0,
follow_element: 0,
},
proof: GroveDBOperationsProofVersions {
prove_query: 0,
prove_query_many: 0,
verify_query_with_options: 0,
verify_query_raw: 0,
verify_layer_proof: 0,
verify_query: 0,
verify_subset_query: 0,
verify_query_with_absence_proof: 0,
verify_subset_query_with_absence_proof: 0,
verify_query_with_chained_path_queries: 0,
},
average_case: GroveDBOperationsAverageCaseVersions {
add_average_case_get_merk_at_path: 0,
average_case_merk_replace_tree: 1, // changed
average_case_merk_insert_tree: 0,
average_case_merk_delete_tree: 0,
average_case_merk_insert_element: 0,
average_case_merk_replace_element: 0,
average_case_merk_patch_element: 0,
average_case_merk_delete_element: 0,
add_average_case_has_raw_cost: 0,
add_average_case_has_raw_tree_cost: 0,
add_average_case_get_raw_cost: 0,
add_average_case_get_raw_tree_cost: 0,
add_average_case_get_cost: 0,
},
worst_case: GroveDBOperationsWorstCaseVersions {
add_worst_case_get_merk_at_path: 0,
worst_case_merk_replace_tree: 0,
worst_case_merk_insert_tree: 0,
worst_case_merk_delete_tree: 0,
worst_case_merk_insert_element: 0,
worst_case_merk_replace_element: 0,
worst_case_merk_patch_element: 0,
worst_case_merk_delete_element: 0,
add_worst_case_has_raw_cost: 0,
add_worst_case_get_raw_tree_cost: 0,
add_worst_case_get_raw_cost: 0,
add_worst_case_get_cost: 0,
},
},
path_query_methods: GroveDBPathQueryMethodVersions {
terminal_keys: 0,
merge: 0,
query_items_at_path: 0,
},
replication: GroveDBReplicationVersions {
get_subtrees_metadata: 0,
fetch_chunk: 0,
start_snapshot_syncing: 0,
apply_chunk: 0,
},
},
merk_versions: MerkVersions {
average_case_costs: MerkAverageCaseCostsVersions {
add_average_case_merk_propagate: 1,
},
},
};
2 changes: 1 addition & 1 deletion grovedb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ name = "insertion_benchmark"
harness = false

[features]
default = ["full"]
default = ["full", "estimated_costs"]
proof_debug = ["grovedb-merk/proof_debug"]
serde = ["dep:serde", "grovedb-merk/serde", "indexmap/serde"]
full = [
Expand Down
15 changes: 6 additions & 9 deletions grovedb/src/batch/batch_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use nohash_hasher::IntMap;
#[cfg(feature = "full")]
use crate::{
batch::{key_info::KeyInfo, GroveOp, KeyInfoPath, QualifiedGroveDbOp, TreeCache},
Element, ElementFlags, Error,
ElementFlags, Error,
};

#[cfg(feature = "full")]
Expand Down Expand Up @@ -124,17 +124,14 @@ where
| GroveOp::InsertOrReplace { element }
| GroveOp::Replace { element }
| GroveOp::Patch { element, .. } => {
if let Element::Tree(..) = element {
cost_return_on_error!(&mut cost, merk_tree_cache.insert(&op, false));
} else if let Element::SumTree(..) = element {
cost_return_on_error!(&mut cost, merk_tree_cache.insert(&op, true));
if let Some(tree_type) = element.tree_type() {
cost_return_on_error!(&mut cost, merk_tree_cache.insert(&op, tree_type));
}
Ok(())
}
GroveOp::RefreshReference { .. }
| GroveOp::Delete
| GroveOp::DeleteTree
| GroveOp::DeleteSumTree => Ok(()),
GroveOp::RefreshReference { .. } | GroveOp::Delete | GroveOp::DeleteTree(_) => {
Ok(())
}
GroveOp::ReplaceTreeRootKey { .. } | GroveOp::InsertTreeWithRootHash { .. } => {
Err(Error::InvalidBatchOperation(
"replace and insert tree hash are internal operations only",
Expand Down
Loading
Loading