move max_clean_root deeper in flush cache (#23869)
This commit is contained in:
parent
c31db81ac4
commit
82328fd9d8
|
@ -4721,21 +4721,8 @@ impl AccountsDb {
|
||||||
// outdated updates in earlier roots
|
// outdated updates in earlier roots
|
||||||
let mut num_roots_flushed = 0;
|
let mut num_roots_flushed = 0;
|
||||||
for &root in cached_roots.iter().rev() {
|
for &root in cached_roots.iter().rev() {
|
||||||
let should_flush_f = if let Some(max_clean_root) = max_clean_root {
|
|
||||||
if root > max_clean_root {
|
|
||||||
// Only if the root is greater than the `max_clean_root` do we
|
|
||||||
// have to prevent cleaning, otherwise, just default to `should_flush_f`
|
|
||||||
// for any slots <= `max_clean_root`
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
should_flush_f.as_mut()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
should_flush_f.as_mut()
|
|
||||||
};
|
|
||||||
|
|
||||||
if self
|
if self
|
||||||
.flush_slot_cache_with_clean(&[root], should_flush_f)
|
.flush_slot_cache_with_clean(&[root], should_flush_f.as_mut(), max_clean_root)
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
num_roots_flushed += 1;
|
num_roots_flushed += 1;
|
||||||
|
@ -4764,6 +4751,7 @@ impl AccountsDb {
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
slot_cache: &SlotCache,
|
slot_cache: &SlotCache,
|
||||||
mut should_flush_f: Option<&mut impl FnMut(&Pubkey, &AccountSharedData) -> bool>,
|
mut should_flush_f: Option<&mut impl FnMut(&Pubkey, &AccountSharedData) -> bool>,
|
||||||
|
max_clean_root: Option<Slot>,
|
||||||
) -> FlushStats {
|
) -> FlushStats {
|
||||||
let mut num_purged = 0;
|
let mut num_purged = 0;
|
||||||
let mut total_size = 0;
|
let mut total_size = 0;
|
||||||
|
@ -4771,6 +4759,16 @@ impl AccountsDb {
|
||||||
let iter_items: Vec<_> = slot_cache.iter().collect();
|
let iter_items: Vec<_> = slot_cache.iter().collect();
|
||||||
let mut purged_slot_pubkeys: HashSet<(Slot, Pubkey)> = HashSet::new();
|
let mut purged_slot_pubkeys: HashSet<(Slot, Pubkey)> = HashSet::new();
|
||||||
let mut pubkey_to_slot_set: Vec<(Pubkey, Slot)> = vec![];
|
let mut pubkey_to_slot_set: Vec<(Pubkey, Slot)> = vec![];
|
||||||
|
if should_flush_f.is_some() {
|
||||||
|
if let Some(max_clean_root) = max_clean_root {
|
||||||
|
if slot > max_clean_root {
|
||||||
|
// Only if the root is greater than the `max_clean_root` do we
|
||||||
|
// have to prevent cleaning, otherwise, just default to `should_flush_f`
|
||||||
|
// for any slots <= `max_clean_root`
|
||||||
|
should_flush_f = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
let (accounts, hashes): (Vec<(&Pubkey, &AccountSharedData)>, Vec<Hash>) = iter_items
|
let (accounts, hashes): (Vec<(&Pubkey, &AccountSharedData)>, Vec<Hash>) = iter_items
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|iter_item| {
|
.filter_map(|iter_item| {
|
||||||
|
@ -4842,7 +4840,7 @@ impl AccountsDb {
|
||||||
|
|
||||||
/// flush all accounts in this slot
|
/// flush all accounts in this slot
|
||||||
fn flush_slot_cache(&self, slot: Slot) -> Option<FlushStats> {
|
fn flush_slot_cache(&self, slot: Slot) -> Option<FlushStats> {
|
||||||
self.flush_slot_cache_with_clean(&[slot], None::<&mut fn(&_, &_) -> bool>)
|
self.flush_slot_cache_with_clean(&[slot], None::<&mut fn(&_, &_) -> bool>, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `should_flush_f` is an optional closure that determines whether a given
|
/// `should_flush_f` is an optional closure that determines whether a given
|
||||||
|
@ -4852,6 +4850,7 @@ impl AccountsDb {
|
||||||
&self,
|
&self,
|
||||||
slots: &[Slot],
|
slots: &[Slot],
|
||||||
should_flush_f: Option<&mut impl FnMut(&Pubkey, &AccountSharedData) -> bool>,
|
should_flush_f: Option<&mut impl FnMut(&Pubkey, &AccountSharedData) -> bool>,
|
||||||
|
max_clean_root: Option<Slot>,
|
||||||
) -> Option<FlushStats> {
|
) -> Option<FlushStats> {
|
||||||
assert_eq!(1, slots.len());
|
assert_eq!(1, slots.len());
|
||||||
let slot = slots[0];
|
let slot = slots[0];
|
||||||
|
@ -4873,7 +4872,7 @@ impl AccountsDb {
|
||||||
// still exists in the cache, we know the slot cannot be removed
|
// still exists in the cache, we know the slot cannot be removed
|
||||||
// by any other threads past this point. We are now responsible for
|
// by any other threads past this point. We are now responsible for
|
||||||
// flushing this slot.
|
// flushing this slot.
|
||||||
self.do_flush_slot_cache(slot, &slot_cache, should_flush_f)
|
self.do_flush_slot_cache(slot, &slot_cache, should_flush_f, max_clean_root)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Nobody else should have been purging this slot, so should not have been removed
|
// Nobody else should have been purging this slot, so should not have been removed
|
||||||
|
|
Loading…
Reference in New Issue