From 0f87e598f66e65e57b62f128534b1fe2e1ea17ec Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 21 Jun 2021 18:25:56 -0500 Subject: [PATCH] refactor generate_index_for_slot (#17984) (#18116) (cherry picked from commit 2087f5da942bcf16800042f56d59acc1c2357611) Co-authored-by: Jeff Washington (jwash) <75863576+jeffwashington@users.noreply.github.com> --- runtime/src/accounts_db.rs | 102 +++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 5a7a02e08a..5a574b394e 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5794,6 +5794,58 @@ impl AccountsDb { accounts_map } + fn generate_index_for_slot<'a>(&self, accounts_map: GenerateIndexAccountsMap<'a>, slot: &Slot) { + if !accounts_map.is_empty() { + let len = accounts_map.len(); + + let mut items = Vec::with_capacity(len); + let mut dirty_pubkeys = accounts_map + .iter() + .map(|(pubkey, (_, store_id, stored_account))| { + items.push(( + pubkey, + AccountInfo { + store_id: *store_id, + offset: stored_account.offset, + stored_size: stored_account.stored_size, + lamports: stored_account.account_meta.lamports, + }, + )); + *pubkey + }) + .collect::>(); + + let items_len = items.len(); + let dirty_pubkey_mask = self + .accounts_index + .insert_new_if_missing_into_primary_index(*slot, items); + + assert_eq!(dirty_pubkey_mask.len(), items_len); + + let mut dirty_pubkey_mask_iter = dirty_pubkey_mask.iter(); + + // dirty_pubkey_mask will return true if an item has multiple rooted entries for + // a given pubkey. If there is just a single item, there is no cleaning to + // be done on that pubkey. Prune the touched pubkey set here for only those + // pubkeys with multiple updates. + dirty_pubkeys.retain(|_k| *dirty_pubkey_mask_iter.next().unwrap()); + if !dirty_pubkeys.is_empty() { + self.uncleaned_pubkeys.insert(*slot, dirty_pubkeys); + } + + if !self.account_indexes.is_empty() { + for (pubkey, (_, _store_id, stored_account)) in accounts_map.iter() { + self.accounts_index.update_secondary_indexes( + pubkey, + &stored_account.account_meta.owner, + stored_account.data, + &self.account_indexes, + ); + } + } + } + } + #[allow(clippy::needless_collect)] pub fn generate_index(&self, limit_load_slot_count_from_snapshot: Option) { let mut slots = self.storage.all_slots(); @@ -5826,55 +5878,7 @@ impl AccountsDb { scan_time.stop(); scan_time_sum += scan_time.as_us(); - if !accounts_map.is_empty() { - let len = accounts_map.len(); - - let mut items = Vec::with_capacity(len); - let mut dirty_pubkeys = accounts_map - .iter() - .map(|(pubkey, (_, store_id, stored_account))| { - items.push(( - pubkey, - AccountInfo { - store_id: *store_id, - offset: stored_account.offset, - stored_size: stored_account.stored_size, - lamports: stored_account.account_meta.lamports, - }, - )); - *pubkey - }) - .collect::>(); - - let items_len = items.len(); - let dirty_pubkey_mask = self - .accounts_index - .insert_new_if_missing_into_primary_index(*slot, items); - - assert_eq!(dirty_pubkey_mask.len(), items_len); - - let mut dirty_pubkey_mask_iter = dirty_pubkey_mask.iter(); - - // dirty_pubkey_mask will return true if an item has multiple rooted entries for - // a given pubkey. If there is just a single item, there is no cleaning to - // be done on that pubkey. Prune the touched pubkey set here for only those - // pubkeys with multiple updates. - dirty_pubkeys.retain(|_k| *dirty_pubkey_mask_iter.next().unwrap()); - if !dirty_pubkeys.is_empty() { - self.uncleaned_pubkeys.insert(*slot, dirty_pubkeys); - } - - if !self.account_indexes.is_empty() { - for (pubkey, (_, _store_id, stored_account)) in accounts_map.iter() { - self.accounts_index.update_secondary_indexes( - pubkey, - &stored_account.account_meta.owner, - stored_account.data, - &self.account_indexes, - ); - } - } - } + self.generate_index_for_slot(accounts_map, slot); } scan_time_sum })