From df39b37cb8de5cfa764d96844931b5cc9840a0da Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Wed, 6 Oct 2021 20:04:26 -0500 Subject: [PATCH] improve clean stats (#20469) --- runtime/src/accounts_db.rs | 8 +++- runtime/src/accounts_index.rs | 77 +++++++++++++++-------------------- 2 files changed, 38 insertions(+), 47 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 4d0746b2e7..582d7d12ee 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -1962,6 +1962,7 @@ impl AccountsDb { let total_keys_count = pubkeys.len(); let mut accounts_scan = Measure::start("accounts_scan"); + let uncleaned_roots_len = self.accounts_index.uncleaned_roots_len(); // parallel scan the index. let (mut purges_zero_lamports, purges_old_accounts) = { let do_clean_scan = || { @@ -2161,6 +2162,7 @@ impl AccountsDb { ("delta_key_count", key_timings.delta_key_count, i64), ("dirty_pubkeys_count", key_timings.dirty_pubkeys_count, i64), ("total_keys_count", total_keys_count, i64), + ("uncleaned_roots_len", uncleaned_roots_len, i64), ); } @@ -5856,9 +5858,11 @@ impl AccountsDb { let mut unrooted_cleaned_count = 0; let dead_slots: Vec<_> = dead_slots_iter .map(|slot| { - if let Some(latest) = self.accounts_index.clean_dead_slot(*slot) { + if self + .accounts_index + .clean_dead_slot(*slot, &mut accounts_index_root_stats) + { rooted_cleaned_count += 1; - accounts_index_root_stats = latest; } else { unrooted_cleaned_count += 1; } diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index cab880c37e..9dd2cb169f 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -1768,47 +1768,35 @@ impl AccountsIndex { /// Remove the slot when the storage for the slot is freed /// Accounts no longer reference this slot. - pub fn clean_dead_slot(&self, slot: Slot) -> Option { - let (roots_len, uncleaned_roots_len, previous_uncleaned_roots_len, roots_range) = { - let mut w_roots_tracker = self.roots_tracker.write().unwrap(); - let removed_from_unclean_roots = w_roots_tracker.uncleaned_roots.remove(&slot); - let removed_from_previous_uncleaned_roots = - w_roots_tracker.previous_uncleaned_roots.remove(&slot); - if !w_roots_tracker.roots.remove(&slot) { - if removed_from_unclean_roots { - error!("clean_dead_slot-removed_from_unclean_roots: {}", slot); - inc_new_counter_error!("clean_dead_slot-removed_from_unclean_roots", 1, 1); - } - if removed_from_previous_uncleaned_roots { - error!( - "clean_dead_slot-removed_from_previous_uncleaned_roots: {}", - slot - ); - inc_new_counter_error!( - "clean_dead_slot-removed_from_previous_uncleaned_roots", - 1, - 1 - ); - } - return None; + pub fn clean_dead_slot(&self, slot: Slot, stats: &mut AccountsIndexRootsStats) -> bool { + let mut w_roots_tracker = self.roots_tracker.write().unwrap(); + let removed_from_unclean_roots = w_roots_tracker.uncleaned_roots.remove(&slot); + let removed_from_previous_uncleaned_roots = + w_roots_tracker.previous_uncleaned_roots.remove(&slot); + if !w_roots_tracker.roots.remove(&slot) { + if removed_from_unclean_roots { + error!("clean_dead_slot-removed_from_unclean_roots: {}", slot); + inc_new_counter_error!("clean_dead_slot-removed_from_unclean_roots", 1, 1); } - ( - w_roots_tracker.roots.len(), - w_roots_tracker.uncleaned_roots.len(), - w_roots_tracker.previous_uncleaned_roots.len(), - w_roots_tracker.roots.range_width(), - ) - }; - Some(AccountsIndexRootsStats { - roots_len, - uncleaned_roots_len, - previous_uncleaned_roots_len, - roots_range, - rooted_cleaned_count: 0, - unrooted_cleaned_count: 0, - clean_unref_from_storage_us: 0, - clean_dead_slot_us: 0, - }) + if removed_from_previous_uncleaned_roots { + error!( + "clean_dead_slot-removed_from_previous_uncleaned_roots: {}", + slot + ); + inc_new_counter_error!( + "clean_dead_slot-removed_from_previous_uncleaned_roots", + 1, + 1 + ); + } + false + } else { + stats.roots_len = w_roots_tracker.roots.len(); + stats.uncleaned_roots_len = w_roots_tracker.uncleaned_roots.len(); + stats.previous_uncleaned_roots_len = w_roots_tracker.previous_uncleaned_roots.len(); + stats.roots_range = w_roots_tracker.roots.range_width(); + true + } } pub fn min_root(&self) -> Option { @@ -1870,7 +1858,6 @@ impl AccountsIndex { self.roots_tracker.write().unwrap().roots.clear() } - #[cfg(test)] pub fn uncleaned_roots_len(&self) -> usize { self.roots_tracker.read().unwrap().uncleaned_roots.len() } @@ -3274,7 +3261,7 @@ pub mod tests { let index = AccountsIndex::::default_for_tests(); index.add_root(0, false); index.add_root(1, false); - index.clean_dead_slot(0); + index.clean_dead_slot(0, &mut AccountsIndexRootsStats::default()); assert!(index.is_root(1)); assert!(!index.is_root(0)); } @@ -3285,7 +3272,7 @@ pub mod tests { let index = AccountsIndex::::default_for_tests(); index.add_root(0, false); index.add_root(1, false); - index.clean_dead_slot(1); + index.clean_dead_slot(1, &mut AccountsIndexRootsStats::default()); assert!(!index.is_root(1)); assert!(index.is_root(0)); } @@ -3334,7 +3321,7 @@ pub mod tests { .len() ); - index.clean_dead_slot(1); + index.clean_dead_slot(1, &mut AccountsIndexRootsStats::default()); assert_eq!(3, index.roots_tracker.read().unwrap().roots.len()); assert_eq!(2, index.roots_tracker.read().unwrap().uncleaned_roots.len()); assert_eq!( @@ -3347,7 +3334,7 @@ pub mod tests { .len() ); - index.clean_dead_slot(2); + index.clean_dead_slot(2, &mut AccountsIndexRootsStats::default()); assert_eq!(2, index.roots_tracker.read().unwrap().roots.len()); assert_eq!(1, index.roots_tracker.read().unwrap().uncleaned_roots.len()); assert_eq!(