From 7bdbb18741c2ef12c556dc1813489a46e51700fe Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Tue, 6 Sep 2022 07:39:31 -0700 Subject: [PATCH] acctidx: factor out update_slot_list_entry (#27546) --- runtime/src/in_mem_accounts_index.rs | 30 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 8bf5e2570..bc309c2bf 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -443,6 +443,21 @@ impl InMemAccountsIndex { }) } + /// update 'entry' with 'new_value' + fn update_slot_list_entry( + &self, + entry: &AccountMapEntry, + new_value: PreAllocatedAccountMapEntry, + other_slot: Option, + reclaims: &mut SlotList, + reclaim: UpsertReclaim, + ) { + let new_value: (Slot, T) = new_value.into(); + let upsert_cached = new_value.1.is_cached(); + Self::lock_and_update_slot_list(entry, new_value, other_slot, reclaims, reclaim); + self.set_age_to_future(entry, upsert_cached); + } + pub fn upsert( &self, pubkey: &Pubkey, @@ -455,10 +470,7 @@ impl InMemAccountsIndex { // try to get it just from memory first using only a read lock self.get_only_in_mem(pubkey, false, |entry| { if let Some(entry) = entry { - let new_value: (Slot, T) = new_value.into(); - let upsert_cached = new_value.1.is_cached(); - Self::lock_and_update_slot_list(entry, new_value, other_slot, reclaims, reclaim); - self.set_age_to_future(entry, upsert_cached); + self.update_slot_list_entry(entry, new_value, other_slot, reclaims, reclaim); } else { let mut m = Measure::start("entry"); let mut map = self.map_internal.write().unwrap(); @@ -467,13 +479,10 @@ impl InMemAccountsIndex { let found = matches!(entry, Entry::Occupied(_)); match entry { Entry::Occupied(mut occupied) => { - let new_value: (Slot, T) = new_value.into(); - let upsert_cached = new_value.1.is_cached(); let current = occupied.get_mut(); - Self::lock_and_update_slot_list( + self.update_slot_list_entry( current, new_value, other_slot, reclaims, reclaim, ); - self.set_age_to_future(current, upsert_cached); } Entry::Vacant(vacant) => { // not in cache, look on disk @@ -482,17 +491,14 @@ impl InMemAccountsIndex { // go to in-mem cache first let disk_entry = self.load_account_entry_from_disk(vacant.key()); let new_value = if let Some(disk_entry) = disk_entry { - let new_value: (Slot, T) = new_value.into(); - let upsert_cached = new_value.1.is_cached(); // on disk, so merge new_value with what was on disk - Self::lock_and_update_slot_list( + self.update_slot_list_entry( &disk_entry, new_value, other_slot, reclaims, reclaim, ); - self.set_age_to_future(&disk_entry, upsert_cached); disk_entry } else { // not on disk, so insert new thing