flush_slot_cache_with_clean (#23868)

This commit is contained in:
Jeff Washington (jwash)
2022-03-23 14:09:56 -05:00
committed by GitHub
parent 260f899eda
commit dc3863ef14

View File

@ -4575,7 +4575,7 @@ impl AccountsDb {
} }
pub fn flush_accounts_cache_slot(&self, slot: Slot) { pub fn flush_accounts_cache_slot(&self, slot: Slot) {
self.flush_slot_cache(slot, None::<&mut fn(&_, &_) -> bool>); self.flush_slot_cache(slot);
} }
/// true if write cache is too big /// true if write cache is too big
@ -4642,9 +4642,7 @@ impl AccountsDb {
// Don't flush slots that are known to be unrooted // Don't flush slots that are known to be unrooted
if old_slot > max_flushed_root { if old_slot > max_flushed_root {
if self.should_aggressively_flush_cache() { if self.should_aggressively_flush_cache() {
if let Some(stats) = if let Some(stats) = self.flush_slot_cache(old_slot) {
self.flush_slot_cache(old_slot, None::<&mut fn(&_, &_) -> bool>)
{
flush_stats.num_flushed += stats.num_flushed; flush_stats.num_flushed += stats.num_flushed;
flush_stats.num_purged += stats.num_purged; flush_stats.num_purged += stats.num_purged;
flush_stats.total_size += stats.total_size; flush_stats.total_size += stats.total_size;
@ -4736,7 +4734,10 @@ impl AccountsDb {
should_flush_f.as_mut() should_flush_f.as_mut()
}; };
if self.flush_slot_cache(root, should_flush_f).is_some() { if self
.flush_slot_cache_with_clean(root, should_flush_f)
.is_some()
{
num_roots_flushed += 1; num_roots_flushed += 1;
} }
@ -4839,10 +4840,15 @@ impl AccountsDb {
} }
} }
/// flush all accounts in this slot
fn flush_slot_cache(&self, slot: Slot) -> Option<FlushStats> {
self.flush_slot_cache_with_clean(slot, None::<&mut fn(&_, &_) -> bool>)
}
/// `should_flush_f` is an optional closure that determines whether a given /// `should_flush_f` is an optional closure that determines whether a given
/// account should be flushed. Passing `None` will by default flush all /// account should be flushed. Passing `None` will by default flush all
/// accounts /// accounts
fn flush_slot_cache( fn flush_slot_cache_with_clean(
&self, &self,
slot: Slot, slot: Slot,
should_flush_f: Option<&mut impl FnMut(&Pubkey, &AccountSharedData) -> bool>, should_flush_f: Option<&mut impl FnMut(&Pubkey, &AccountSharedData) -> bool>,
@ -12852,7 +12858,7 @@ pub mod tests {
if flush_trial_start_receiver.recv().is_err() { if flush_trial_start_receiver.recv().is_err() {
return; return;
} }
db.flush_slot_cache(10, None::<&mut fn(&_, &_) -> bool>); db.flush_slot_cache(10);
flush_done_sender.send(()).unwrap(); flush_done_sender.send(()).unwrap();
}) })
.unwrap() .unwrap()
@ -12921,7 +12927,7 @@ pub mod tests {
return; return;
} }
for slot in 0..num_cached_slots { for slot in 0..num_cached_slots {
db.flush_slot_cache(slot, None::<&mut fn(&_, &_) -> bool>); db.flush_slot_cache(slot);
} }
flush_done_sender.send(()).unwrap(); flush_done_sender.send(()).unwrap();
}) })