AcctIdx: check for range holds outside lock (#23706)

This commit is contained in:
Jeff Washington (jwash) 2022-03-16 17:44:59 -05:00 committed by GitHub
parent caddb851be
commit be0aeea01a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 7 deletions

View File

@ -1045,7 +1045,7 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
// return true if the removal was completed
fn evict_from_cache(
&self,
evictions: Vec<Pubkey>,
mut evictions: Vec<Pubkey>,
current_age: Age,
startup: bool,
randomly_evicted: bool,
@ -1060,7 +1060,20 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
if self.get_stop_evictions() {
return false; // did NOT complete, ranges were changed, so have to restart
}
// skip any keys that are held in memory because of ranges being held
let ranges = self.cache_ranges_held.read().unwrap().clone();
if !ranges.is_empty() {
evictions.retain(|k| {
if ranges.iter().any(|range| range.contains(k)) {
// this item is held in mem by range, so don't remove
completed_scan = false;
false
} else {
true
}
});
}
let mut removed = 0;
// consider chunking these so we don't hold the write lock too long
@ -1086,12 +1099,6 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
continue;
}
if ranges.iter().any(|range| range.contains(&k)) {
// this item is held in mem by range, so don't remove
completed_scan = false;
continue;
}
if stop_evictions_changes_at_start != self.get_stop_evictions_changes() {
return false; // did NOT complete, ranges were changed, so have to restart
}