Move clean accounts to background service (#10898)

This commit is contained in:
sakridge
2020-07-02 22:25:17 -07:00
committed by GitHub
parent f1699721ef
commit 832d47317e
4 changed files with 74 additions and 39 deletions

View File

@@ -62,9 +62,14 @@ impl<'a, T: 'a + Clone> AccountsIndex<T> {
.collect()
}
pub fn would_purge(&self, pubkey: &Pubkey) -> SlotList<T> {
let list = &self.account_maps.get(&pubkey).unwrap().1.read().unwrap();
self.get_rooted_entries(&list)
// returns the rooted entries and the storage ref count
pub fn would_purge(&self, pubkey: &Pubkey) -> (SlotList<T>, RefCount) {
let (ref_count, slots_list) = self.account_maps.get(&pubkey).unwrap();
let slots_list_r = &slots_list.read().unwrap();
(
self.get_rooted_entries(&slots_list_r),
ref_count.load(Ordering::Relaxed),
)
}
// filter any rooted entries and return them along with a bool that indicates
@@ -76,6 +81,17 @@ impl<'a, T: 'a + Clone> AccountsIndex<T> {
(reclaims, list.is_empty())
}
pub fn purge_exact(&self, pubkey: &Pubkey, slots: HashSet<Slot>) -> (SlotList<T>, bool) {
let list = &mut self.account_maps.get(&pubkey).unwrap().1.write().unwrap();
let reclaims = list
.iter()
.filter(|(slot, _)| slots.contains(&slot))
.cloned()
.collect();
list.retain(|(slot, _)| !slots.contains(slot));
(reclaims, list.is_empty())
}
// find the latest slot and T in a slice for a given ancestor
// returns index into 'slice' if found, None if not.
fn latest_slot(&self, ancestors: Option<&Ancestors>, slice: SlotSlice<T>) -> Option<usize> {