Skip to content

Commit

Permalink
chore(drive): log grovedb operations
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Sep 30, 2023
1 parent ed354ca commit bded523
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use grovedb::batch::{BatchApplyOptions, GroveDbOp};
use grovedb::TransactionArg;
use grovedb_costs::storage_cost::removal::StorageRemovedBytes::BasicStorageRemoval;
use grovedb_costs::storage_cost::transition::OperationStorageTransitionType;
use tracing::Level;

impl Drive {
/// Applies the given groveDB operations batch and gets and passes the costs to `push_drive_operation_result`.
Expand Down Expand Up @@ -42,6 +43,13 @@ impl Drive {
}
}

// Clone batch only if we log them
let maybe_ops_for_logs = if tracing::event_enabled!(Level::TRACE) {
Some(ops.clone())
} else {
None
};

let cost_context = self.grove.apply_batch_with_element_flags_update(
ops.operations,
Some(BatchApplyOptions {
Expand Down Expand Up @@ -140,6 +148,22 @@ impl Drive {
},
transaction,
);

if tracing::event_enabled!(Level::TRACE) && cost_context.value.is_ok() {
let root_hash = self
.grove
.root_hash(transaction)
.unwrap()
.map_err(Error::GroveDB)?;

tracing::trace!(
ops = ?maybe_ops_for_logs.unwrap(),
root_hash = ?root_hash,
is_transactional = transaction.is_some(),
"apply grovedb batch",
);
}

push_drive_operation_result(cost_context, drive_operations)
}
}
30 changes: 28 additions & 2 deletions packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::error::Error;
use grovedb::operations::delete::ClearOptions;
use grovedb::TransactionArg;
use grovedb_path::SubtreePath;
use tracing::Level;

impl Drive {
/// Pushes the `OperationCost` of deleting an element in groveDB to `drive_operations`.
Expand All @@ -16,10 +17,35 @@ impl Drive {
allow_deleting_subtrees: false,
trying_to_clear_with_subtrees_returns_error: false,
};

let maybe_path_for_logs = if tracing::event_enabled!(Level::TRACE) {
Some(path.clone())
} else {
None
};

// we will always return true if there is no error when we don't check for subtrees
self.grove
let result = self
.grove
.clear_subtree(path, Some(options), transaction)
.map_err(Error::GroveDB)
.map(|_| ())
.map(|_| ());

if tracing::event_enabled!(Level::TRACE) && result.is_ok() {
let root_hash = self
.grove
.root_hash(transaction)
.unwrap()
.map_err(Error::GroveDB)?;

tracing::trace!(
path = ?maybe_path_for_logs.unwrap().to_vec(),
root_hash = ?root_hash,
is_transactional = transaction.is_some(),
"grovedb clear",
);
}

result
}
}

0 comments on commit bded523

Please sign in to comment.