Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jul 10, 2024
1 parent b3f6c29 commit 9c08bc8
Show file tree
Hide file tree
Showing 11 changed files with 433 additions and 193 deletions.
18 changes: 17 additions & 1 deletion grovedb-version/src/version/grovedb_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@ use versioned_feature_core::FeatureVersion;

#[derive(Clone, Debug, Default)]
pub struct GroveDBVersions {
pub apply_batch: GroveDBApplyBatchVersions,
pub element: GroveDBElementMethodVersions,
pub operations: GroveDBOperationsVersions,
}

#[derive(Clone, Debug, Default)]
pub struct GroveDBApplyBatchVersions {
pub apply_batch_structure: FeatureVersion,
pub apply_body: FeatureVersion,
pub continue_partial_apply_body: FeatureVersion,
pub apply_operations_without_batching: FeatureVersion,
pub apply_batch: FeatureVersion,
pub apply_partial_batch: FeatureVersion,
pub open_batch_transactional_merk_at_path: FeatureVersion,
pub open_batch_merk_at_path: FeatureVersion,
pub apply_batch_with_element_flags_update: FeatureVersion,
pub apply_partial_batch_with_element_flags_update: FeatureVersion,
pub estimated_case_operations_for_batch: FeatureVersion,
}

#[derive(Clone, Debug, Default)]
pub struct GroveDBOperationsVersions {
pub get: GroveDBOperationsGetVersions,
Expand Down Expand Up @@ -156,7 +173,6 @@ pub struct GroveDBElementMethodVersions {
pub get_path_query: FeatureVersion,
pub get_sized_query: FeatureVersion,
pub path_query_push: FeatureVersion,
pub subquery_paths_and_value_for_sized_query: FeatureVersion,
pub query_item: FeatureVersion,
pub basic_push: FeatureVersion,
pub serialize: FeatureVersion,
Expand Down
52 changes: 52 additions & 0 deletions grovedb-version/src/version/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,62 @@ use crate::version::{
},
GroveVersion,
};
use crate::version::grovedb_versions::{GroveDBApplyBatchVersions, GroveDBElementMethodVersions};

pub const GROVE_V1: 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: 0,
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,
Expand Down
107 changes: 79 additions & 28 deletions grovedb/src/batch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
// MIT LICENSE
//
// Copyright (c) 2021 Dash Core Group
//
// Permission is hereby granted, free of charge, to any
// person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the
// Software without restriction, including without
// limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

//! Apply multiple GroveDB operations atomically.

mod batch_structure;
Expand Down Expand Up @@ -91,8 +63,10 @@ use grovedb_version::version::GroveVersion;
use grovedb_visualize::{Drawer, Visualize};
use integer_encoding::VarInt;
use itertools::Itertools;
use grovedb_version::check_v0_with_cost;
use key_info::{KeyInfo, KeyInfo::KnownKey};
pub use options::BatchApplyOptions;
use grovedb_version::error::GroveVersionError;

pub use crate::batch::batch_structure::{OpsByLevelPath, OpsByPath};
#[cfg(feature = "estimated_costs")]
Expand Down Expand Up @@ -1444,6 +1418,13 @@ impl GroveDb {
u32,
) -> Result<(StorageRemovedBytes, StorageRemovedBytes), Error>,
{
check_v0_with_cost!(
"apply_batch_structure",
grove_version
.grovedb_versions
.apply_batch
.apply_batch_structure
);
let mut cost = OperationCost::default();
let BatchStructure {
mut ops_by_level_paths,
Expand Down Expand Up @@ -1654,6 +1635,13 @@ impl GroveDb {
get_merk_fn: impl FnMut(&[Vec<u8>], bool) -> CostResult<Merk<S>, Error>,
grove_version: &GroveVersion,
) -> CostResult<Option<OpsByLevelPath>, Error> {
check_v0_with_cost!(
"apply_body",
grove_version
.grovedb_versions
.apply_batch
.apply_body
);
let mut cost = OperationCost::default();
let batch_structure = cost_return_on_error!(
&mut cost,
Expand Down Expand Up @@ -1695,6 +1683,13 @@ impl GroveDb {
get_merk_fn: impl FnMut(&[Vec<u8>], bool) -> CostResult<Merk<S>, Error>,
grove_version: &GroveVersion,
) -> CostResult<Option<OpsByLevelPath>, Error> {
check_v0_with_cost!(
"continue_partial_apply_body",
grove_version
.grovedb_versions
.apply_batch
.continue_partial_apply_body
);
let mut cost = OperationCost::default();
let batch_structure = cost_return_on_error!(
&mut cost,
Expand All @@ -1721,6 +1716,13 @@ impl GroveDb {
transaction: TransactionArg,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"apply_operations_without_batching",
grove_version
.grovedb_versions
.apply_batch
.apply_operations_without_batching
);
let mut cost = OperationCost::default();
for op in ops.into_iter() {
match op.op {
Expand Down Expand Up @@ -1768,6 +1770,13 @@ impl GroveDb {
transaction: TransactionArg,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"apply_batch",
grove_version
.grovedb_versions
.apply_batch
.apply_batch
);
self.apply_batch_with_element_flags_update(
ops,
batch_apply_options,
Expand Down Expand Up @@ -1795,6 +1804,13 @@ impl GroveDb {
transaction: TransactionArg,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"apply_partial_batch",
grove_version
.grovedb_versions
.apply_batch
.apply_partial_batch
);
self.apply_partial_batch_with_element_flags_update(
ops,
batch_apply_options,
Expand All @@ -1821,6 +1837,13 @@ impl GroveDb {
new_merk: bool,
grove_version: &GroveVersion,
) -> CostResult<Merk<PrefixedRocksDbTransactionContext<'db>>, Error> {
check_v0_with_cost!(
"open_batch_transactional_merk_at_path",
grove_version
.grovedb_versions
.apply_batch
.open_batch_transactional_merk_at_path
);
let mut cost = OperationCost::default();
let storage = self
.db
Expand Down Expand Up @@ -1901,6 +1924,13 @@ impl GroveDb {
new_merk: bool,
grove_version: &GroveVersion,
) -> CostResult<Merk<PrefixedRocksDbStorageContext>, Error> {
check_v0_with_cost!(
"open_batch_merk_at_path",
grove_version
.grovedb_versions
.apply_batch
.open_batch_merk_at_path
);
let mut local_cost = OperationCost::default();
let storage = self
.db
Expand Down Expand Up @@ -1976,6 +2006,13 @@ impl GroveDb {
transaction: TransactionArg,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"apply_batch_with_element_flags_update",
grove_version
.grovedb_versions
.apply_batch
.apply_batch_with_element_flags_update
);
let mut cost = OperationCost::default();

if ops.is_empty() {
Expand Down Expand Up @@ -2101,6 +2138,13 @@ impl GroveDb {
transaction: TransactionArg,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"apply_partial_batch_with_element_flags_update",
grove_version
.grovedb_versions
.apply_batch
.apply_partial_batch_with_element_flags_update
);
let mut cost = OperationCost::default();

if ops.is_empty() {
Expand Down Expand Up @@ -2338,6 +2382,13 @@ impl GroveDb {
>,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"estimated_case_operations_for_batch",
grove_version
.grovedb_versions
.apply_batch
.estimated_case_operations_for_batch
);
let mut cost = OperationCost::default();

if ops.is_empty() {
Expand Down
29 changes: 28 additions & 1 deletion grovedb/src/element/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ use grovedb_costs::{storage_cost::removal::StorageRemovedBytes, CostResult, Cost
use grovedb_merk::{BatchEntry, Error as MerkError, Merk, MerkOptions, Op};
#[cfg(feature = "full")]
use grovedb_storage::StorageContext;
#[cfg(feature = "full")]
use grovedb_version::check_v0_with_cost;
#[cfg(feature = "full")]
use grovedb_version::version::GroveVersion;

#[cfg(feature = "full")]
use grovedb_costs::OperationCost;
#[cfg(feature = "full")]
use crate::{Element, Error};
#[cfg(feature = "full")]
use grovedb_version::error::GroveVersionError;

impl Element {
#[cfg(feature = "full")]
Expand All @@ -23,6 +29,13 @@ impl Element {
is_sum: bool,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"delete",
grove_version
.grovedb_versions
.element
.delete
);
let op = match (is_sum, is_layered) {
(true, true) => Op::DeleteLayeredMaybeSpecialized,
(true, false) => Op::DeleteMaybeSpecialized,
Expand Down Expand Up @@ -63,6 +76,13 @@ impl Element {
>,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"delete_with_sectioned_removal_bytes",
grove_version
.grovedb_versions
.element
.delete_with_sectioned_removal_bytes
);
let op = match (is_in_sum_tree, is_layered) {
(true, true) => Op::DeleteLayeredMaybeSpecialized,
(true, false) => Op::DeleteMaybeSpecialized,
Expand Down Expand Up @@ -96,6 +116,13 @@ impl Element {
batch_operations: &mut Vec<BatchEntry<K>>,
grove_version: &GroveVersion,
) -> CostResult<(), Error> {
check_v0_with_cost!(
"delete_into_batch_operations",
grove_version
.grovedb_versions
.element
.delete_into_batch_operations
);
let op = match (is_sum, is_layered) {
(true, true) => Op::DeleteLayeredMaybeSpecialized,
(true, false) => Op::DeleteMaybeSpecialized,
Expand Down
Loading

0 comments on commit 9c08bc8

Please sign in to comment.