Skip to content

Commit 1c65a16

Browse files
[Storage] Add qmdb::any tracing (#3737)
Co-authored-by: Roberto Bayardo <roberto@commonware.xyz>
1 parent 731b453 commit 1c65a16

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

storage/src/qmdb/any/batch.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,16 @@ where
981981
Operation<F, update::Unordered<K, V>>: Codec,
982982
{
983983
/// Resolve mutations into operations, merkleize, and return an `Arc<MerkleizedBatch>`.
984+
#[allow(clippy::type_complexity)]
985+
#[tracing::instrument(
986+
name = "qmdb::any::batch::merkleize",
987+
level = "info",
988+
skip_all,
989+
fields(
990+
variant = "unordered",
991+
mutations = self.mutations.len() as u64,
992+
),
993+
)]
984994
pub async fn merkleize<E, C, I, const N: usize>(
985995
self,
986996
db: &Db<F, E, C, I, H, update::Unordered<K, V>, N, S>,
@@ -1143,6 +1153,16 @@ where
11431153
Operation<F, update::Ordered<K, V>>: Codec,
11441154
{
11451155
/// Resolve mutations into operations, merkleize, and return an `Arc<MerkleizedBatch>`.
1156+
#[allow(clippy::type_complexity)]
1157+
#[tracing::instrument(
1158+
name = "qmdb::any::batch::merkleize",
1159+
level = "info",
1160+
skip_all,
1161+
fields(
1162+
variant = "ordered",
1163+
mutations = self.mutations.len() as u64,
1164+
),
1165+
)]
11461166
pub async fn merkleize<E, C, I, const N: usize>(
11471167
self,
11481168
db: &Db<F, E, C, I, H, update::Ordered<K, V>, N, S>,
@@ -1508,6 +1528,17 @@ where
15081528
/// All uncommitted ancestors in the chain must be kept alive until the child (or any
15091529
/// descendant) is merkleized. Dropping an uncommitted ancestor causes data
15101530
/// loss detected at `apply_batch` time.
1531+
#[tracing::instrument(
1532+
name = "qmdb::any::batch::new",
1533+
level = "debug",
1534+
skip_all,
1535+
fields(
1536+
source = "batch",
1537+
base_size = self.bounds.base_size,
1538+
total_size = self.bounds.total_size,
1539+
ancestor_batches = self.ancestor_diffs.len() as u64,
1540+
),
1541+
)]
15111542
pub fn new_batch<H>(self: &Arc<Self>) -> UnmerkleizedBatch<F, H, U, S>
15121543
where
15131544
H: Hasher<Digest = D>,
@@ -1616,6 +1647,17 @@ where
16161647
Operation<F, U>: Codec,
16171648
{
16181649
/// Create a new speculative batch of operations with this database as its parent.
1650+
#[tracing::instrument(
1651+
name = "qmdb::any::batch::new",
1652+
level = "debug",
1653+
skip_all,
1654+
fields(
1655+
source = "db",
1656+
base_size = *self.last_commit_loc + 1,
1657+
inactivity_floor = *self.inactivity_floor_loc,
1658+
active_keys = self.active_keys as u64,
1659+
),
1660+
)]
16191661
pub fn new_batch(&self) -> UnmerkleizedBatch<F, H, U, S> {
16201662
// The DB is always committed, so journal size = last_commit_loc + 1.
16211663
let journal_size = *self.last_commit_loc + 1;
@@ -1651,6 +1693,17 @@ where
16511693
/// This publishes the batch to the in-memory database state and appends it to the
16521694
/// journal, but does not durably persist it. Call [`Db::commit`] or [`Db::sync`] to
16531695
/// guarantee durability.
1696+
#[tracing::instrument(
1697+
name = "qmdb::any::Db::apply_batch",
1698+
level = "info",
1699+
skip_all,
1700+
fields(
1701+
batch_total_size = batch.bounds.total_size,
1702+
batch_base_size = batch.bounds.base_size,
1703+
db_size = *self.last_commit_loc + 1,
1704+
ancestor_batches = batch.ancestor_diffs.len() as u64,
1705+
),
1706+
)]
16541707
pub async fn apply_batch(
16551708
&mut self,
16561709
batch: Arc<MerkleizedBatch<F, H::Digest, U, S>>,
@@ -1742,6 +1795,16 @@ where
17421795
/// Create an initial [`MerkleizedBatch`] from the committed DB state.
17431796
///
17441797
/// This is the starting point for building owned batch chains.
1798+
#[tracing::instrument(
1799+
name = "qmdb::any::Db::to_batch",
1800+
level = "info",
1801+
skip_all,
1802+
fields(
1803+
db_size = *self.last_commit_loc + 1,
1804+
inactivity_floor = *self.inactivity_floor_loc,
1805+
active_keys = self.active_keys as u64,
1806+
),
1807+
)]
17451808
pub fn to_batch(&self) -> Arc<MerkleizedBatch<F, H::Digest, U, S>> {
17461809
// The DB is always committed, so journal size = last_commit_loc + 1.
17471810
let journal_size = *self.last_commit_loc + 1;

storage/src/qmdb/any/db.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ where
356356

357357
/// Prune historical operations prior to `prune_loc`. This does not affect the db's root or
358358
/// snapshot.
359+
#[tracing::instrument(
360+
name = "qmdb::any::Db::prune",
361+
level = "info",
362+
skip_all,
363+
fields(
364+
requested_loc = *prune_loc,
365+
inactivity_floor = *self.inactivity_floor_loc,
366+
),
367+
)]
359368
pub async fn prune(&mut self, prune_loc: Location<F>) -> Result<(), crate::qmdb::Error<F>> {
360369
let _timer = self.metrics.operations.prune_timer();
361370
self.metrics.operations.prune_calls.inc();
@@ -378,6 +387,17 @@ where
378387
/// Returns [`crate::qmdb::Error::HistoricalFloorPruned`] if `historical_size - 1` is retained
379388
/// but is not a commit op, either because the caller passed a non-commit-boundary size or
380389
/// because pruning removed the commit that would have governed it.
390+
#[allow(clippy::type_complexity)]
391+
#[tracing::instrument(
392+
name = "qmdb::any::Db::historical_proof",
393+
level = "info",
394+
skip_all,
395+
fields(
396+
historical_size = *historical_size,
397+
start_loc = *start_loc,
398+
max_ops = max_ops.get(),
399+
),
400+
)]
381401
pub async fn historical_proof(
382402
&self,
383403
historical_size: Location<F>,
@@ -432,6 +452,15 @@ where
432452
///
433453
/// A successful rewind is not restart-stable until a subsequent [`Db::commit`] or
434454
/// [`Db::sync`].
455+
#[tracing::instrument(
456+
name = "qmdb::any::Db::rewind",
457+
level = "info",
458+
skip_all,
459+
fields(
460+
target_size = *size,
461+
prev_size = *self.last_commit_loc + 1,
462+
),
463+
)]
435464
pub async fn rewind(&mut self, size: Location<F>) -> Result<(), Error<F>> {
436465
let rewind_size = *size;
437466
let current_size = *self.last_commit_loc + 1;
@@ -707,6 +736,16 @@ where
707736
}
708737

709738
/// Sync all database state to disk.
739+
#[tracing::instrument(
740+
name = "qmdb::any::Db::sync",
741+
level = "info",
742+
skip_all,
743+
fields(
744+
db_size = *self.last_commit_loc + 1,
745+
inactivity_floor = *self.inactivity_floor_loc,
746+
active_keys = self.active_keys as u64,
747+
),
748+
)]
710749
pub async fn sync(&self) -> Result<(), crate::qmdb::Error<F>> {
711750
let _timer = self.metrics.operations.sync_timer();
712751
self.metrics.operations.sync_calls.inc();
@@ -716,6 +755,16 @@ where
716755

717756
/// Durably commit the journal state published by prior [`Db::apply_batch`]
718757
/// calls.
758+
#[tracing::instrument(
759+
name = "qmdb::any::Db::commit",
760+
level = "info",
761+
skip_all,
762+
fields(
763+
db_size = *self.last_commit_loc + 1,
764+
inactivity_floor = *self.inactivity_floor_loc,
765+
active_keys = self.active_keys as u64,
766+
),
767+
)]
719768
pub async fn commit(&self) -> Result<(), crate::qmdb::Error<F>> {
720769
let _timer = self.metrics.operations.commit_timer();
721770
self.metrics.operations.commit_calls.inc();

0 commit comments

Comments
 (0)