zcash_client_sqlite: Instrument `put_shard_roots`

This commit is contained in:
Jack Grigg 2024-01-22 21:49:05 +00:00
parent ae2a18db93
commit 0ccc126315
1 changed files with 8 additions and 0 deletions

View File

@ -391,6 +391,7 @@ pub(crate) fn last_shard<H: HashSer>(
/// Returns an error iff the proposed insertion range /// Returns an error iff the proposed insertion range
/// for the tree shards would create a discontinuity /// for the tree shards would create a discontinuity
/// in the database. /// in the database.
#[tracing::instrument(skip(conn))]
fn check_shard_discontinuity( fn check_shard_discontinuity(
conn: &rusqlite::Connection, conn: &rusqlite::Connection,
table_prefix: &'static str, table_prefix: &'static str,
@ -517,6 +518,7 @@ pub(crate) fn truncate(
.map(|_| ()) .map(|_| ())
} }
#[tracing::instrument(skip(conn))]
pub(crate) fn get_cap<H: HashSer>( pub(crate) fn get_cap<H: HashSer>(
conn: &rusqlite::Connection, conn: &rusqlite::Connection,
table_prefix: &'static str, table_prefix: &'static str,
@ -534,6 +536,7 @@ pub(crate) fn get_cap<H: HashSer>(
) )
} }
#[tracing::instrument(skip(conn, cap))]
pub(crate) fn put_cap<H: HashSer>( pub(crate) fn put_cap<H: HashSer>(
conn: &rusqlite::Connection, conn: &rusqlite::Connection,
table_prefix: &'static str, table_prefix: &'static str,
@ -949,6 +952,7 @@ pub(crate) fn truncate_checkpoints(
Ok(()) Ok(())
} }
#[tracing::instrument(skip(conn, roots))]
pub(crate) fn put_shard_roots< pub(crate) fn put_shard_roots<
H: Hashable + HashSer + Clone + Eq, H: Hashable + HashSer + Clone + Eq,
const DEPTH: u8, const DEPTH: u8,
@ -1004,6 +1008,7 @@ pub(crate) fn put_shard_roots<
.map_err(ShardTreeError::Storage)?, .map_err(ShardTreeError::Storage)?,
); );
let insert_into_cap = tracing::info_span!("insert_into_cap").entered();
let cap_result = cap let cap_result = cap
.batch_insert( .batch_insert(
Position::from(start_index), Position::from(start_index),
@ -1019,6 +1024,7 @@ pub(crate) fn put_shard_roots<
) )
.map_err(ShardTreeError::Insert)? .map_err(ShardTreeError::Insert)?
.expect("slice of inserted roots was verified to be nonempty"); .expect("slice of inserted roots was verified to be nonempty");
drop(insert_into_cap);
put_cap(conn, table_prefix, cap_result.subtree.take_root()).map_err(ShardTreeError::Storage)?; put_cap(conn, table_prefix, cap_result.subtree.take_root()).map_err(ShardTreeError::Storage)?;
@ -1029,6 +1035,7 @@ pub(crate) fn put_shard_roots<
) )
.map_err(ShardTreeError::Storage)?; .map_err(ShardTreeError::Storage)?;
let put_roots = tracing::info_span!("write_shards").entered();
for (root, i) in roots.iter().zip(0u64..) { for (root, i) in roots.iter().zip(0u64..) {
// We want to avoid deserializing the subtree just to annotate its root node, so we simply // We want to avoid deserializing the subtree just to annotate its root node, so we simply
// cache the downloaded root alongside of any already-persisted subtree. We will update the // cache the downloaded root alongside of any already-persisted subtree. We will update the
@ -1063,6 +1070,7 @@ pub(crate) fn put_shard_roots<
]) ])
.map_err(|e| ShardTreeError::Storage(Error::Query(e)))?; .map_err(|e| ShardTreeError::Storage(Error::Query(e)))?;
} }
drop(put_roots);
Ok(()) Ok(())
} }