diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 8602dd4141..61dd8ce7c1 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -7175,6 +7175,8 @@ impl AccountsDb { timings.report(); } + self.accounts_index.log_secondary_indexes(); + IndexGenerationInfo { accounts_data_len: accounts_data_len.load(Ordering::Relaxed), } diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 5ee58cf49f..c557c70782 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -1408,6 +1408,22 @@ impl AccountsIndex { } } + /// 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, diff --git a/runtime/src/secondary_index.rs b/runtime/src/secondary_index.rs index 825b384847..c1b5d43368 100644 --- a/runtime/src/secondary_index.rs +++ b/runtime/src/secondary_index.rs @@ -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 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::>(); + entries.sort_unstable(); + entries + .iter() + .rev() + .take(20) + .for_each(|(v, k)| info!("owner: {}, accounts: {}", k, v)); + } }