add ability to flush read only accounts cache (#28726)

This commit is contained in:
Jeff Washington (jwash) 2022-11-02 12:03:32 -07:00 committed by GitHub
parent faf32e2a94
commit 88d7f6cc9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -5260,6 +5260,12 @@ impl AccountsDb {
)
}
/// remove all entries from the read only accounts cache
/// useful for benches/tests
pub fn flush_read_only_cache_for_tests(&self) {
self.read_only_accounts_cache.reset_for_tests();
}
/// if 'load_into_read_cache_only', then return value is meaningless.
/// The goal is to get the account into the read-only cache.
fn do_load_with_populate_read_cache(

View File

@ -54,6 +54,17 @@ impl ReadOnlyAccountsCache {
}
}
/// reset the read only accounts cache
/// useful for benches/tests
pub fn reset_for_tests(&self) {
self.cache.clear();
self.queue.lock().unwrap().clear();
self.data_size.store(0, Ordering::Relaxed);
self.hits.store(0, Ordering::Relaxed);
self.misses.store(0, Ordering::Relaxed);
self.evicts.store(0, Ordering::Relaxed);
}
/// true if pubkey is in cache at slot
pub fn in_cache(&self, pubkey: &Pubkey, slot: Slot) -> bool {
self.cache.contains_key(&(*pubkey, slot))