AcctIdx: items() uses held ranges (#21954)

This commit is contained in:
Jeff Washington (jwash)
2021-12-17 09:59:29 -06:00
committed by GitHub
parent af53d2f692
commit 729698e815
4 changed files with 13 additions and 10 deletions

View File

@ -7164,10 +7164,10 @@ impl AccountsDb {
#[allow(clippy::stable_sort_primitive)] #[allow(clippy::stable_sort_primitive)]
roots.sort(); roots.sort();
info!("{}: accounts_index roots: {:?}", label, roots,); 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| { self.accounts_index.account_maps.iter().for_each(|map| {
for (pubkey, account_entry) in for (pubkey, account_entry) in map.read().unwrap().items(&full_pubkey_range) {
map.read().unwrap().items(&None::<&std::ops::Range<Pubkey>>)
{
info!(" key: {} ref_count: {}", pubkey, account_entry.ref_count(),); info!(" key: {} ref_count: {}", pubkey, account_entry.ref_count(),);
info!( info!(
" slots: {:?}", " slots: {:?}",

View File

@ -668,7 +668,7 @@ impl<'a, T: IndexValue> AccountsIndexIterator<'a, T> {
where where
R: RangeBounds<Pubkey> + std::fmt::Debug, R: RangeBounds<Pubkey> + std::fmt::Debug,
{ {
let mut result = map.items(&Some(&range)); let mut result = map.items(&range);
if !collect_all_unsorted { if !collect_all_unsorted {
result.sort_unstable_by(|a, b| a.0.cmp(&b.0)); result.sort_unstable_by(|a, b| a.0.cmp(&b.0));
} }

View File

@ -28,6 +28,7 @@ pub struct BucketMapHolderStats {
pub load_disk_missing_us: AtomicU64, pub load_disk_missing_us: AtomicU64,
pub updates_in_mem: AtomicU64, pub updates_in_mem: AtomicU64,
pub items: AtomicU64, pub items: AtomicU64,
pub items_us: AtomicU64,
pub keys: AtomicU64, pub keys: AtomicU64,
pub deletes: AtomicU64, pub deletes: AtomicU64,
pub inserts: AtomicU64, pub inserts: AtomicU64,
@ -517,6 +518,7 @@ impl BucketMapHolderStats {
i64 i64
), ),
("items", self.items.swap(0, Ordering::Relaxed), 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), ("keys", self.keys.swap(0, Ordering::Relaxed), i64),
); );
} }

View File

@ -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 where
R: RangeBounds<Pubkey> + std::fmt::Debug, R: RangeBounds<Pubkey> + std::fmt::Debug,
{ {
self.start_stop_flush(true); let m = Measure::start("items");
self.put_range_in_cache(range); // check range here to see if our items are already held in the cache self.hold_range_in_memory(range, true);
Self::update_stat(&self.stats().items, 1);
let map = self.map().read().unwrap(); let map = self.map().read().unwrap();
let mut result = Vec::with_capacity(map.len()); let mut result = Vec::with_capacity(map.len());
map.iter().for_each(|(k, v)| { 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))); 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 result
} }