in_mem_accounts_index filters by range (#19779)

This commit is contained in:
Jeff Washington (jwash) 2021-09-12 21:57:15 -05:00 committed by GitHub
parent 0263ffb2ed
commit b992c02708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 11 deletions

View File

@ -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<Pubkey>>)
{
info!(" key: {} ref_count: {}", pubkey, account_entry.ref_count(),);
info!(
" slots: {:?}",

View File

@ -559,14 +559,9 @@ impl<'a, T: IsCached> AccountsIndexIterator<'a, T> {
collect_all_unsorted: bool,
) -> Vec<(Pubkey, AccountMapEntry<T>)>
where
R: RangeBounds<Pubkey>,
R: RangeBounds<Pubkey> + 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));
}

View File

@ -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<T: IsCached> InMemAccountsIndex<T> {
result
}
pub fn items(&self) -> Vec<(K, AccountMapEntry<T>)> {
pub fn items<R>(&self, range: &Option<&R>) -> Vec<(K, AccountMapEntry<T>)>
where
R: RangeBounds<Pubkey> + 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<K, AccountMapEntry<T>> {