Skip to content

Commit

Permalink
feat(resharding): log time spent in resharder operations (near#12238)
Browse files Browse the repository at this point in the history
Adding log entries telling the time spent on the longer operations
happening during flat storage resharding.

Part of flat storage resharding issue (near#12174).
  • Loading branch information
Trisfald authored Oct 17, 2024
1 parent 3bc05cd commit b399ae3
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions chain/chain/src/flat_storage_resharder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex};
use near_chain_configs::ReshardingHandle;
use near_chain_primitives::Error;

use tracing::{debug, error, info};
use tracing::{error, info};

use crate::resharding::event_type::{ReshardingEventType, ReshardingSplitShardParams};
use crate::resharding::types::FlatStorageSplitShardRequest;
Expand Down Expand Up @@ -204,9 +204,15 @@ impl FlatStorageResharder {
}

/// Cleans up children shards flat storage's content (status is excluded).
#[tracing::instrument(
level = "info",
target = "resharding",
"FlatStorageResharder::clean_children_shards",
skip_all
)]
fn clean_children_shards(&self, status: &SplittingParentStatus) -> Result<(), Error> {
let SplittingParentStatus { left_child_shard, right_child_shard, .. } = status;
debug!(target: "resharding", ?left_child_shard, ?right_child_shard, "cleaning up children shards flat storage's content");
info!(target: "resharding", ?left_child_shard, ?right_child_shard, "cleaning up children shards flat storage's content");
let mut store_update = self.runtime.store().flat_store().store_update();
for child in [left_child_shard, right_child_shard] {
store_update.remove_all_deltas(*child);
Expand Down Expand Up @@ -263,8 +269,14 @@ impl FlatStorageResharder {
// Prepare the store object for commits and the iterator over parent's flat storage.
let flat_store = self.runtime.store().flat_store();
let mut iter = flat_store.iter(parent_shard);
let mut batches_done = 0;

loop {
let _span = tracing::debug_span!(
target: "resharding",
"split_shard_task_impl/batch",
batch_id = ?batches_done)
.entered();
let mut store_update = flat_store.store_update();

// Process a `BATCH_SIZE` worth of key value pairs.
Expand Down Expand Up @@ -295,7 +307,7 @@ impl FlatStorageResharder {
return FlatStorageReshardingTaskStatus::Failed;
}

// TODO(Trisfald): metrics and logs
batches_done += 1;

// If `iter`` is exhausted we can exit after the store commit.
if iter_exhausted {
Expand All @@ -310,6 +322,12 @@ impl FlatStorageResharder {

/// Performs post-processing of shard splitting after all key-values have been moved from parent to
/// children. `success` indicates whether or not the previous phase was successful.
#[tracing::instrument(
level = "info",
target = "resharding",
"FlatStorageResharder::split_shard_task_postprocessing",
skip_all
)]
fn split_shard_task_postprocessing(&self, task_status: FlatStorageReshardingTaskStatus) {
let (parent_shard, split_status) = self
.get_parent_shard_and_status()
Expand Down

0 comments on commit b399ae3

Please sign in to comment.