simplify clean_dead_slot, factor out root stats (#32035)
This commit is contained in:
parent
afbb0fa92f
commit
31f2f569a6
|
@ -4621,8 +4621,7 @@ impl AccountsDb {
|
|||
let mut bank_hash_stats = self.bank_hash_stats.lock().unwrap();
|
||||
|
||||
dropped_roots.for_each(|slot| {
|
||||
self.accounts_index
|
||||
.clean_dead_slot(slot, &mut AccountsIndexRootsStats::default());
|
||||
self.accounts_index.clean_dead_slot(slot);
|
||||
accounts_delta_hashes.remove(&slot);
|
||||
bank_hash_stats.remove(&slot);
|
||||
// the storage has been removed from this slot and recycled or dropped
|
||||
|
@ -8210,10 +8209,7 @@ impl AccountsDb {
|
|||
let mut unrooted_cleaned_count = 0;
|
||||
let dead_slots: Vec<_> = dead_slots_iter
|
||||
.map(|slot| {
|
||||
if self
|
||||
.accounts_index
|
||||
.clean_dead_slot(*slot, &mut accounts_index_root_stats)
|
||||
{
|
||||
if self.accounts_index.clean_dead_slot(*slot) {
|
||||
rooted_cleaned_count += 1;
|
||||
} else {
|
||||
unrooted_cleaned_count += 1;
|
||||
|
@ -8230,7 +8226,8 @@ impl AccountsDb {
|
|||
);
|
||||
trace!("remove_dead_slots_metadata: dead_slots: {:?}", dead_slots);
|
||||
}
|
||||
|
||||
self.accounts_index
|
||||
.update_roots_stats(&mut accounts_index_root_stats);
|
||||
accounts_index_root_stats.rooted_cleaned_count += rooted_cleaned_count;
|
||||
accounts_index_root_stats.unrooted_cleaned_count += unrooted_cleaned_count;
|
||||
|
||||
|
|
|
@ -1889,7 +1889,7 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
|
|||
/// Remove the slot when the storage for the slot is freed
|
||||
/// Accounts no longer reference this slot.
|
||||
/// return true if slot was a root
|
||||
pub fn clean_dead_slot(&self, slot: Slot, stats: &mut AccountsIndexRootsStats) -> bool {
|
||||
pub fn clean_dead_slot(&self, slot: Slot) -> 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 =
|
||||
|
@ -1912,17 +1912,20 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
|
|||
}
|
||||
false
|
||||
} else {
|
||||
stats.roots_len = Some(w_roots_tracker.alive_roots.len());
|
||||
stats.uncleaned_roots_len = Some(w_roots_tracker.uncleaned_roots.len());
|
||||
stats.previous_uncleaned_roots_len =
|
||||
Some(w_roots_tracker.previous_uncleaned_roots.len());
|
||||
stats.roots_range = Some(w_roots_tracker.alive_roots.range_width());
|
||||
drop(w_roots_tracker);
|
||||
self.roots_removed.fetch_add(1, Ordering::Relaxed);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn update_roots_stats(&self, stats: &mut AccountsIndexRootsStats) {
|
||||
let roots_tracker = self.roots_tracker.read().unwrap();
|
||||
stats.roots_len = Some(roots_tracker.alive_roots.len());
|
||||
stats.uncleaned_roots_len = Some(roots_tracker.uncleaned_roots.len());
|
||||
stats.previous_uncleaned_roots_len = Some(roots_tracker.previous_uncleaned_roots.len());
|
||||
stats.roots_range = Some(roots_tracker.alive_roots.range_width());
|
||||
}
|
||||
|
||||
pub fn min_alive_root(&self) -> Option<Slot> {
|
||||
self.roots_tracker.read().unwrap().min_alive_root()
|
||||
}
|
||||
|
@ -2957,7 +2960,7 @@ pub mod tests {
|
|||
let index = AccountsIndex::<bool, bool>::default_for_tests();
|
||||
index.add_root(0);
|
||||
index.add_root(1);
|
||||
index.clean_dead_slot(0, &mut AccountsIndexRootsStats::default());
|
||||
index.clean_dead_slot(0);
|
||||
assert!(index.is_alive_root(1));
|
||||
assert!(!index.is_alive_root(0));
|
||||
}
|
||||
|
@ -2968,7 +2971,7 @@ pub mod tests {
|
|||
let index = AccountsIndex::<bool, bool>::default_for_tests();
|
||||
index.add_root(0);
|
||||
index.add_root(1);
|
||||
index.clean_dead_slot(1, &mut AccountsIndexRootsStats::default());
|
||||
index.clean_dead_slot(1);
|
||||
assert!(!index.is_alive_root(1));
|
||||
assert!(index.is_alive_root(0));
|
||||
}
|
||||
|
@ -3019,7 +3022,7 @@ pub mod tests {
|
|||
.len()
|
||||
);
|
||||
|
||||
index.clean_dead_slot(1, &mut AccountsIndexRootsStats::default());
|
||||
index.clean_dead_slot(1);
|
||||
assert_eq!(3, index.roots_tracker.read().unwrap().alive_roots.len());
|
||||
assert_eq!(2, index.roots_tracker.read().unwrap().uncleaned_roots.len());
|
||||
assert_eq!(
|
||||
|
@ -3032,7 +3035,7 @@ pub mod tests {
|
|||
.len()
|
||||
);
|
||||
|
||||
index.clean_dead_slot(2, &mut AccountsIndexRootsStats::default());
|
||||
index.clean_dead_slot(2);
|
||||
assert_eq!(2, index.roots_tracker.read().unwrap().alive_roots.len());
|
||||
assert_eq!(1, index.roots_tracker.read().unwrap().uncleaned_roots.len());
|
||||
assert_eq!(
|
||||
|
@ -4023,7 +4026,7 @@ pub mod tests {
|
|||
assert!(!index.clean_rooted_entries(&key, &mut gc, Some(slot2)));
|
||||
assert_eq!(gc, vec![(slot1, value)]);
|
||||
gc.clear();
|
||||
index.clean_dead_slot(slot2, &mut AccountsIndexRootsStats::default());
|
||||
index.clean_dead_slot(slot2);
|
||||
let slot3 = 3;
|
||||
assert!(index.clean_rooted_entries(&key, &mut gc, Some(slot3)));
|
||||
assert_eq!(gc, vec![(slot2, value)]);
|
||||
|
|
Loading…
Reference in New Issue