Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
AcctIdx: items() uses held ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Dec 17, 2021
1 parent 4d71bb5 commit edf7a4f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7163,10 +7163,10 @@ impl AccountsDb {
#[allow(clippy::stable_sort_primitive)]
roots.sort();
info!("{}: accounts_index roots: {:?}", label, roots,);
let full_pubkey_range = Pubkey::new(&[0; 32])..=Pubkey::new(&[0xff; 32]);

self.accounts_index.account_maps.iter().for_each(|map| {
for (pubkey, account_entry) in
map.read().unwrap().items(&None::<&std::ops::Range<Pubkey>>)
{
for (pubkey, account_entry) in map.read().unwrap().items(&full_pubkey_range) {
info!(" key: {} ref_count: {}", pubkey, account_entry.ref_count(),);
info!(
" slots: {:?}",
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ impl<'a, T: IndexValue> AccountsIndexIterator<'a, T> {
where
R: RangeBounds<Pubkey> + std::fmt::Debug,
{
let mut result = map.items(&Some(&range));
let mut result = map.items(&range);
if !collect_all_unsorted {
result.sort_unstable_by(|a, b| a.0.cmp(&b.0));
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/bucket_map_holder_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct BucketMapHolderStats {
pub load_disk_missing_us: AtomicU64,
pub updates_in_mem: AtomicU64,
pub items: AtomicU64,
pub items_us: AtomicU64,
pub keys: AtomicU64,
pub deletes: AtomicU64,
pub inserts: AtomicU64,
Expand Down Expand Up @@ -518,6 +519,7 @@ impl BucketMapHolderStats {
i64
),
("items", self.items.swap(0, Ordering::Relaxed), i64),
("items_us", self.items_us.swap(0, Ordering::Relaxed), i64),
("keys", self.keys.swap(0, Ordering::Relaxed), i64),
);
}
Expand Down
13 changes: 7 additions & 6 deletions runtime/src/in_mem_accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,22 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
}
}

pub fn items<R>(&self, range: &Option<&R>) -> Vec<(K, AccountMapEntry<T>)>
pub fn items<R>(&self, range: &R) -> Vec<(K, AccountMapEntry<T>)>
where
R: RangeBounds<Pubkey> + std::fmt::Debug,
{
self.start_stop_flush(true);
self.put_range_in_cache(range); // check range here to see if our items are already held in the cache
Self::update_stat(&self.stats().items, 1);
let m = Measure::start("items");
self.hold_range_in_memory(range, true);
let map = self.map().read().unwrap();
let mut result = Vec::with_capacity(map.len());
map.iter().for_each(|(k, v)| {
if range.map(|range| range.contains(k)).unwrap_or(true) {
if range.contains(k) {
result.push((*k, Arc::clone(v)));
}
});
self.start_stop_flush(false);
self.hold_range_in_memory(range, false);
Self::update_stat(&self.stats().items, 1);
Self::update_time_stat(&self.stats().items_us, m);
result
}

Expand Down

0 comments on commit edf7a4f

Please sign in to comment.