From be0aeea01ac5ec74bc2935f04322c182cbb02400 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Wed, 16 Mar 2022 17:44:59 -0500 Subject: [PATCH] AcctIdx: check for range holds outside lock (#23706) --- runtime/src/in_mem_accounts_index.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index da1c1e19c7..29c91e971e 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -1045,7 +1045,7 @@ impl InMemAccountsIndex { // return true if the removal was completed fn evict_from_cache( &self, - evictions: Vec, + mut evictions: Vec, current_age: Age, startup: bool, randomly_evicted: bool, @@ -1060,7 +1060,20 @@ impl InMemAccountsIndex { 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 InMemAccountsIndex { 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 }