rework slot list update (#17232)
This commit is contained in:
committed by
GitHub
parent
7fe24c455c
commit
4788976517
@ -183,28 +183,31 @@ impl<T: 'static + Clone + IsCached> WriteAccountMapEntry<T> {
|
|||||||
// already exists in the list, remove the older item, add it to `reclaims`, and insert
|
// already exists in the list, remove the older item, add it to `reclaims`, and insert
|
||||||
// the new item.
|
// the new item.
|
||||||
pub fn update(&mut self, slot: Slot, account_info: T, reclaims: &mut SlotList<T>) {
|
pub fn update(&mut self, slot: Slot, account_info: T, reclaims: &mut SlotList<T>) {
|
||||||
// filter out other dirty entries from the same slot
|
let mut addref = !account_info.is_cached();
|
||||||
let mut same_slot_previous_updates: Vec<(usize, &(Slot, T))> = self
|
self.slot_list_mut(|list| {
|
||||||
.slot_list()
|
// find other dirty entries from the same slot
|
||||||
.iter()
|
for list_index in 0..list.len() {
|
||||||
.enumerate()
|
let (s, previous_update_value) = &list[list_index];
|
||||||
.filter(|(_, (s, _))| *s == slot)
|
if *s == slot {
|
||||||
.collect();
|
addref = addref && previous_update_value.is_cached();
|
||||||
assert!(same_slot_previous_updates.len() <= 1);
|
|
||||||
if let Some((list_index, (s, previous_update_value))) = same_slot_previous_updates.pop() {
|
let mut new_item = (slot, account_info);
|
||||||
let is_flush_from_cache =
|
std::mem::swap(&mut new_item, &mut list[list_index]);
|
||||||
previous_update_value.is_cached() && !account_info.is_cached();
|
reclaims.push(new_item);
|
||||||
reclaims.push((*s, previous_update_value.clone()));
|
list[(list_index + 1)..]
|
||||||
self.slot_list_mut(|list| list.remove(list_index));
|
.iter()
|
||||||
if is_flush_from_cache {
|
.for_each(|item| assert!(item.0 != slot));
|
||||||
self.ref_count().fetch_add(1, Ordering::Relaxed);
|
return; // this returns from self.slot_list_mut above
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if !account_info.is_cached() {
|
|
||||||
|
// if we make it here, we did not find the slot in the list
|
||||||
|
list.push((slot, account_info));
|
||||||
|
});
|
||||||
|
if addref {
|
||||||
// If it's the first non-cache insert, also bump the stored ref count
|
// If it's the first non-cache insert, also bump the stored ref count
|
||||||
self.ref_count().fetch_add(1, Ordering::Relaxed);
|
self.ref_count().fetch_add(1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.slot_list_mut(|list| list.push((slot, account_info)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user