Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tracing] Add tracing for Garbage Collection #10177

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ impl Chain {
tries: ShardTries,
gc_config: &near_chain_configs::GCConfig,
) -> Result<(), Error> {
let _span = tracing::debug_span!(target: "chain", "clear_data").entered();
let _span = tracing::debug_span!(target: "garbage_collection", "clear_data").entered();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the target here seems a bit controversial, what is your goal here?
Personally I would rather keep it as chain but add the GC prefix as you've done elsewhere. Not a blocker, more of a preference and I don't think we have any guidelines on this so feel free to keep as is.


let head = self.store.head()?;
let tail = self.store.tail()?;
Expand Down
15 changes: 14 additions & 1 deletion chain/chain/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use std::io;
use std::{fmt, io};

use borsh::{BorshDeserialize, BorshSerialize};
use chrono::Utc;
Expand Down Expand Up @@ -74,6 +74,16 @@ pub enum GCMode {
StateSync { clear_block_info: bool },
}

impl fmt::Debug for GCMode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
GCMode::Fork(_) => write!(f, "GCMode::Fork"),
GCMode::Canonical(_) => write!(f, "GCMode::Canonical"),
GCMode::StateSync { .. } => write!(f, "GCMode::StateSync"),
Comment on lines +80 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can use the f.debug_struct method. Under the hood it'll also use write but you're guaranteed that its style will be consistent with the rest of the codebase and the defaults. You can find plenty of examples in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked, I think write! is fine here as we don't have any other fields we would like to print out here.

}
}
}

/// Accesses the chain store. Used to create atomic editable views that can be reverted.
pub trait ChainStoreAccess {
/// Returns underlaying store.
Expand Down Expand Up @@ -2344,6 +2354,7 @@ impl<'a> ChainStoreUpdate<'a> {
// Now we can proceed to removing the trie state and flat state
let mut store_update = self.store().store_update();
for shard_uid in prev_shard_layout.get_shard_uids() {
tracing::info!(target: "garbage_collection", ?block_hash, ?shard_uid, "GC resharding");
runtime.get_tries().delete_trie_for_shard(shard_uid, &mut store_update);
runtime
.get_flat_storage_manager()
Expand All @@ -2364,6 +2375,8 @@ impl<'a> ChainStoreUpdate<'a> {
) -> Result<(), Error> {
let mut store_update = self.store().store_update();

tracing::info!(target: "garbage_collection", ?gc_mode, ?block_hash, "GC block_hash");

// 1. Apply revert insertions or deletions from DBCol::TrieChanges for Trie
{
let shard_uids_to_gc: Vec<_> = self.get_shard_uids_to_gc(epoch_manager, &block_hash);
Expand Down
1 change: 1 addition & 0 deletions core/store/src/flat/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ impl FlatStorageManager {
let mut flat_storages = self.0.flat_storages.lock().expect(POISONED_LOCK_ERR);
if let Some(flat_store) = flat_storages.remove(&shard_uid) {
flat_store.clear_state(store_update)?;
tracing::info!(target: "store", ?shard_uid, "remove_flat_storage_for_shard successful");
Ok(true)
} else {
Ok(false)
Expand Down
Loading