From b992c027081f86ff9e642b44e77d213030a3bd28 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Sun, 12 Sep 2021 21:57:15 -0500 Subject: [PATCH] in_mem_accounts_index filters by range (#19779) --- runtime/src/accounts_db.rs | 4 +++- runtime/src/accounts_index.rs | 9 ++------- runtime/src/in_mem_accounts_index.rs | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 341288eb84..c311d49098 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -6461,7 +6461,9 @@ impl AccountsDb { roots.sort(); info!("{}: accounts_index roots: {:?}", label, roots,); self.accounts_index.account_maps.iter().for_each(|map| { - for (pubkey, account_entry) in map.read().unwrap().items() { + for (pubkey, account_entry) in + map.read().unwrap().items(&None::<&std::ops::Range>) + { info!(" key: {} ref_count: {}", pubkey, account_entry.ref_count(),); info!( " slots: {:?}", diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index e13e99c32e..0e1d66aae1 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -559,14 +559,9 @@ impl<'a, T: IsCached> AccountsIndexIterator<'a, T> { collect_all_unsorted: bool, ) -> Vec<(Pubkey, AccountMapEntry)> where - R: RangeBounds, + R: RangeBounds + std::fmt::Debug, { - let mut result = Vec::with_capacity(map.len()); - for (k, v) in map.items() { - if range.contains(&k) { - result.push((k, v)); - } - } + let mut result = map.items(&Some(&range)); if !collect_all_unsorted { result.sort_unstable_by(|a, b| a.0.cmp(&b.0)); } diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index dede0741c5..b6c60f9531 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -14,7 +14,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; use std::fmt::Debug; - +use std::ops::RangeBounds; type K = Pubkey; // one instance of this represents one bin of the accounts index. @@ -51,9 +51,18 @@ impl InMemAccountsIndex { result } - pub fn items(&self) -> Vec<(K, AccountMapEntry)> { + pub fn items(&self, range: &Option<&R>) -> Vec<(K, AccountMapEntry)> + where + R: RangeBounds + std::fmt::Debug, + { Self::update_stat(&self.stats().items, 1); - self.map.iter().map(|(k, v)| (*k, v.clone())).collect() + let mut result = Vec::with_capacity(self.map.len()); + self.map.iter().for_each(|(k, v)| { + if range.map(|range| range.contains(k)).unwrap_or(true) { + result.push((*k, v.clone())); + } + }); + result } pub fn keys(&self) -> Keys> {