AcctIdx: only remove a fixed number of items per write lock (#23795)
This commit is contained in:
committed by
GitHub
parent
10eeafd3d6
commit
24f6855f86
@ -1123,10 +1123,11 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut evicted = 0;
|
let mut evicted = 0;
|
||||||
// consider chunking these so we don't hold the write lock too long
|
// chunk these so we don't hold the write lock too long
|
||||||
|
for evictions in evictions.chunks(50) {
|
||||||
let mut map = self.map().write().unwrap();
|
let mut map = self.map().write().unwrap();
|
||||||
for k in evictions {
|
for k in evictions {
|
||||||
if let Entry::Occupied(occupied) = map.entry(k) {
|
if let Entry::Occupied(occupied) = map.entry(*k) {
|
||||||
let v = occupied.get();
|
let v = occupied.get();
|
||||||
if Arc::strong_count(v) > 1 {
|
if Arc::strong_count(v) > 1 {
|
||||||
// someone is holding the value arc's ref count and could modify it, so do not evict
|
// someone is holding the value arc's ref count and could modify it, so do not evict
|
||||||
@ -1158,7 +1159,7 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
|
|||||||
if map.is_empty() {
|
if map.is_empty() {
|
||||||
map.shrink_to_fit();
|
map.shrink_to_fit();
|
||||||
}
|
}
|
||||||
drop(map);
|
}
|
||||||
self.stats()
|
self.stats()
|
||||||
.insert_or_delete_mem_count(false, self.bin, evicted);
|
.insert_or_delete_mem_count(false, self.bin, evicted);
|
||||||
Self::update_stat(&self.stats().flush_entries_evicted_from_mem, evicted as u64);
|
Self::update_stat(&self.stats().flush_entries_evicted_from_mem, evicted as u64);
|
||||||
|
Reference in New Issue
Block a user