log secondary index contents on startup (#24348)

This commit is contained in:
Jeff Washington (jwash) 2022-04-15 13:30:03 -05:00 committed by GitHub
parent 8c9430359e
commit b4fd9124bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -7175,6 +7175,8 @@ impl AccountsDb {
timings.report();
}
self.accounts_index.log_secondary_indexes();
IndexGenerationInfo {
accounts_data_len: accounts_data_len.load(Ordering::Relaxed),
}

View File

@ -1408,6 +1408,22 @@ impl<T: IndexValue> AccountsIndex<T> {
}
}
/// log any secondary index counts, if non-zero
pub(crate) fn log_secondary_indexes(&self) {
if !self.program_id_index.index.is_empty() {
info!("secondary index: {:?}", AccountIndex::ProgramId);
self.program_id_index.log_contents();
}
if !self.spl_token_mint_index.index.is_empty() {
info!("secondary index: {:?}", AccountIndex::SplTokenMint);
self.spl_token_mint_index.log_contents();
}
if !self.spl_token_owner_index.index.is_empty() {
info!("secondary index: {:?}", AccountIndex::SplTokenOwner);
self.spl_token_owner_index.log_contents();
}
}
pub(crate) fn update_secondary_indexes(
&self,
pubkey: &Pubkey,

View File

@ -1,5 +1,6 @@
use {
dashmap::{mapref::entry::Entry::Occupied, DashMap},
log::*,
solana_sdk::{pubkey::Pubkey, timing::AtomicInterval},
std::{
collections::HashSet,
@ -223,4 +224,19 @@ impl<SecondaryIndexEntryType: SecondaryIndexEntry + Default + Sync + Send>
vec![]
}
}
/// log top 20 (owner, # accounts) in descending order of # accounts
pub fn log_contents(&self) {
let mut entries = self
.index
.iter()
.map(|entry| (entry.value().len(), *entry.key()))
.collect::<Vec<_>>();
entries.sort_unstable();
entries
.iter()
.rev()
.take(20)
.for_each(|(v, k)| info!("owner: {}, accounts: {}", k, v));
}
}