From 90009f330b51afb1f8e3009d6851ccbac0090b65 Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Thu, 24 Mar 2022 08:20:56 -0500 Subject: [PATCH] small refactor to shorten the lock on slot_under_contention hashset (#23891) * small refactor to shorten the lock on slot_under_contention hashset * adding comments * comments --- runtime/src/accounts_db.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 6862cf1177..ef5490c4c7 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -4853,22 +4853,14 @@ impl AccountsDb { slot: Slot, should_flush_f: Option<&mut impl FnMut(&Pubkey, &AccountSharedData) -> bool>, ) -> Option { - let is_being_purged = { - let mut slots_under_contention = self - .remove_unrooted_slots_synchronization - .slots_under_contention - .lock() - .unwrap(); - // If we're purging this slot, don't flush it here - if slots_under_contention.contains(&slot) { - true - } else { - slots_under_contention.insert(slot); - false - } - }; - - if !is_being_purged { + if self + .remove_unrooted_slots_synchronization + .slots_under_contention + .lock() + .unwrap() + .insert(slot) + { + // We have not see this slot, flush it. let flush_stats = self.accounts_cache.slot_cache(slot).map(|slot_cache| { #[cfg(test)] { @@ -4898,6 +4890,7 @@ impl AccountsDb { .notify_all(); flush_stats } else { + // We have already seen this slot. It is already under flushing. Skip. None } }