get root lock once (#16829)

This commit is contained in:
Jeff Washington (jwash) 2021-05-05 15:17:45 -05:00 committed by GitHub
parent e6f49a3e79
commit ffbe8906ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 24 deletions

View File

@ -1313,30 +1313,28 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
/// Remove the slot when the storage for the slot is freed /// Remove the slot when the storage for the slot is freed
/// Accounts no longer reference this slot. /// Accounts no longer reference this slot.
pub fn clean_dead_slot(&self, slot: Slot) -> Option<AccountsIndexRootsStats> { pub fn clean_dead_slot(&self, slot: Slot) -> Option<AccountsIndexRootsStats> {
if self.is_root(slot) { let (roots_len, uncleaned_roots_len, previous_uncleaned_roots_len, roots_range) = {
let (roots_len, uncleaned_roots_len, previous_uncleaned_roots_len, roots_range) = { let mut w_roots_tracker = self.roots_tracker.write().unwrap();
let mut w_roots_tracker = self.roots_tracker.write().unwrap(); if !w_roots_tracker.roots.remove(&slot) {
w_roots_tracker.roots.remove(&slot); return None;
w_roots_tracker.uncleaned_roots.remove(&slot); }
w_roots_tracker.previous_uncleaned_roots.remove(&slot); w_roots_tracker.uncleaned_roots.remove(&slot);
( w_roots_tracker.previous_uncleaned_roots.remove(&slot);
w_roots_tracker.roots.len(), (
w_roots_tracker.uncleaned_roots.len(), w_roots_tracker.roots.len(),
w_roots_tracker.previous_uncleaned_roots.len(), w_roots_tracker.uncleaned_roots.len(),
w_roots_tracker.roots.range_width(), w_roots_tracker.previous_uncleaned_roots.len(),
) w_roots_tracker.roots.range_width(),
}; )
Some(AccountsIndexRootsStats { };
roots_len, Some(AccountsIndexRootsStats {
uncleaned_roots_len, roots_len,
previous_uncleaned_roots_len, uncleaned_roots_len,
roots_range, previous_uncleaned_roots_len,
rooted_cleaned_count: 0, roots_range,
unrooted_cleaned_count: 0, rooted_cleaned_count: 0,
}) unrooted_cleaned_count: 0,
} else { })
None
}
} }
pub fn reset_uncleaned_roots(&self, max_clean_root: Option<Slot>) -> HashSet<Slot> { pub fn reset_uncleaned_roots(&self, max_clean_root: Option<Slot>) -> HashSet<Slot> {