remove caching_enabled (#29117)

* warp_from_parents works with write_cache enabled

* remove caching_enabled
This commit is contained in:
Jeff Washington (jwash) 2022-12-09 16:31:54 -06:00 committed by GitHub
parent 631a98a3b6
commit f9c4170d34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 131 additions and 233 deletions

View File

@ -1339,8 +1339,6 @@ pub struct AccountsDb {
pub account_indexes: AccountSecondaryIndexes,
pub caching_enabled: bool,
/// Set of unique keys per slot which is used
/// to drive clean_accounts
/// Generated by get_accounts_delta_hash
@ -2343,7 +2341,6 @@ impl AccountsDb {
stats: AccountsStats::default(),
cluster_type: None,
account_indexes: AccountSecondaryIndexes::default(),
caching_enabled: false,
#[cfg(test)]
load_delay: u64::default(),
#[cfg(test)]
@ -2392,7 +2389,7 @@ impl AccountsDb {
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
caching_enabled: bool,
_caching_enabled: bool,
shrink_ratio: AccountShrinkThreshold,
mut accounts_db_config: Option<AccountsDbConfig>,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
@ -2442,7 +2439,6 @@ impl AccountsDb {
ancient_append_vec_offset,
cluster_type: Some(*cluster_type),
account_indexes,
caching_enabled,
shrink_ratio,
accounts_update_notifier,
filler_accounts_config,
@ -3067,10 +3063,6 @@ impl AccountsDb {
let mut measure_all = Measure::start("clean_accounts");
let max_clean_root_inclusive = self.max_clean_root(max_clean_root_inclusive);
// hold a lock to prevent slot shrinking from running because it might modify some rooted
// slot storages which can not happen as long as we're cleaning accounts because we're also
// modifying the rooted slot storages!
let mut candidates_v1 = self.shrink_candidate_slots_v1.lock().unwrap();
self.report_store_stats();
let mut key_timings = CleanKeyTimings::default();
@ -3211,11 +3203,7 @@ impl AccountsDb {
&ancient_account_cleans,
);
if self.caching_enabled {
self.do_reset_uncleaned_roots(max_clean_root_inclusive);
} else {
self.do_reset_uncleaned_roots_v1(&mut candidates_v1, max_clean_root_inclusive);
}
self.do_reset_uncleaned_roots(max_clean_root_inclusive);
clean_old_rooted.stop();
let mut store_counts_time = Measure::start("store_counts");
@ -4727,7 +4715,7 @@ impl AccountsDb {
let _guard = self.active_stats.activate(ActiveStatItem::Shrink);
const DIRTY_STORES_CLEANING_THRESHOLD: usize = 10_000;
const OUTER_CHUNK_SIZE: usize = 2000;
if is_startup && self.caching_enabled {
if is_startup {
let slots = self.all_slots_in_storage();
let threads = num_cpus::get();
let inner_chunk_size = std::cmp::max(OUTER_CHUNK_SIZE / threads, 1);
@ -4743,11 +4731,7 @@ impl AccountsDb {
});
} else {
for slot in self.all_slots_in_storage() {
if self.caching_enabled {
self.shrink_slot_forced(slot);
} else {
self.do_shrink_slot_forced_v1(slot);
}
self.shrink_slot_forced(slot);
if self.dirty_stores.len() > DIRTY_STORES_CLEANING_THRESHOLD {
self.clean_accounts(None, is_startup, last_full_snapshot_slot);
}
@ -5351,30 +5335,28 @@ impl AccountsDb {
self.read_index_for_accessor_or_load_slow(ancestors, pubkey, max_root, false)?;
// Notice the subtle `?` at previous line, we bail out pretty early if missing.
if self.caching_enabled {
let in_write_cache = storage_location.is_cached();
if !load_into_read_cache_only {
if !in_write_cache {
let result = self.read_only_accounts_cache.load(*pubkey, slot);
if let Some(account) = result {
if matches!(load_zero_lamports, LoadZeroLamports::None)
&& account.is_zero_lamport()
{
return None;
}
return Some((account, slot));
let in_write_cache = storage_location.is_cached();
if !load_into_read_cache_only {
if !in_write_cache {
let result = self.read_only_accounts_cache.load(*pubkey, slot);
if let Some(account) = result {
if matches!(load_zero_lamports, LoadZeroLamports::None)
&& account.is_zero_lamport()
{
return None;
}
return Some((account, slot));
}
} else {
// goal is to load into read cache
if in_write_cache {
// no reason to load in read cache. already in write cache
return None;
}
if self.read_only_accounts_cache.in_cache(pubkey, slot) {
// already in read cache
return None;
}
}
} else {
// goal is to load into read cache
if in_write_cache {
// no reason to load in read cache. already in write cache
return None;
}
if self.read_only_accounts_cache.in_cache(pubkey, slot) {
// already in read cache
return None;
}
}
@ -5393,7 +5375,7 @@ impl AccountsDb {
return None;
}
if self.caching_enabled && !is_cached {
if !is_cached {
/*
We show this store into the read-only cache for account 'A' and future loads of 'A' from the read-only cache are
safe/reflect 'A''s latest state on this fork.
@ -6710,7 +6692,7 @@ impl AccountsDb {
.calc_stored_meta
.fetch_add(calc_stored_meta_time.as_us(), Ordering::Relaxed);
if self.caching_enabled && is_cached_store {
if is_cached_store {
let signature_iter: Box<dyn std::iter::Iterator<Item = &Option<&Signature>>> =
match txn_signatures {
Some(txn_signatures) => {
@ -8019,8 +8001,7 @@ impl AccountsDb {
self.dirty_stores
.insert((*slot, store.append_vec_id()), store.clone());
dead_slots.insert(*slot);
} else if self.caching_enabled
&& Self::is_shrinking_productive(*slot, [&store].into_iter())
} else if Self::is_shrinking_productive(*slot, [&store].into_iter())
&& self.is_candidate_for_shrink(&store, false)
{
// Checking that this single storage entry is ready for shrinking,
@ -8041,29 +8022,27 @@ impl AccountsDb {
.remove_dead_accounts_remove_us
.fetch_add(measure.as_us(), Ordering::Relaxed);
if self.caching_enabled {
let mut measure = Measure::start("shrink");
let mut shrink_candidate_slots = self.shrink_candidate_slots.lock().unwrap();
for (slot, slot_shrink_candidates) in new_shrink_candidates {
for (store_id, store) in slot_shrink_candidates {
// count could be == 0 if multiple accounts are removed
// at once
if store.count() != 0 {
debug!(
"adding: {} {} to shrink candidates: count: {}/{} bytes: {}/{}",
store_id,
slot,
store.approx_stored_count(),
store.count(),
store.alive_bytes(),
store.total_bytes()
);
let mut measure = Measure::start("shrink");
let mut shrink_candidate_slots = self.shrink_candidate_slots.lock().unwrap();
for (slot, slot_shrink_candidates) in new_shrink_candidates {
for (store_id, store) in slot_shrink_candidates {
// count could be == 0 if multiple accounts are removed
// at once
if store.count() != 0 {
debug!(
"adding: {} {} to shrink candidates: count: {}/{} bytes: {}/{}",
store_id,
slot,
store.approx_stored_count(),
store.count(),
store.alive_bytes(),
store.total_bytes()
);
shrink_candidate_slots
.entry(slot)
.or_default()
.insert(store_id, store);
}
shrink_candidate_slots
.entry(slot)
.or_default()
.insert(store_id, store);
}
}
measure.stop();
@ -8278,12 +8257,7 @@ impl AccountsDb {
accounts: impl StorableAccounts<'a, T>,
txn_signatures: Option<&'a [Option<&'a Signature>]>,
) {
self.store(
accounts,
self.caching_enabled,
txn_signatures,
StoreReclaims::Default,
);
self.store(accounts, true, txn_signatures, StoreReclaims::Default);
}
/// Store the account update.
@ -8565,7 +8539,7 @@ impl AccountsDb {
let reclaim = if matches!(reclaim, StoreReclaims::Ignore) {
UpsertReclaim::IgnoreReclaims
} else if self.caching_enabled && is_cached_store {
} else if is_cached_store {
UpsertReclaim::PreviousSlotEntryWasCached
} else {
UpsertReclaim::PopulateReclaims
@ -8586,12 +8560,10 @@ impl AccountsDb {
// filter out the cached reclaims as those don't actually map
// to anything that needs to be cleaned in the backing storage
// entries
if self.caching_enabled {
reclaims.retain(|(_, r)| !r.is_cached());
reclaims.retain(|(_, r)| !r.is_cached());
if is_cached_store {
assert!(reclaims.is_empty());
}
if is_cached_store {
assert!(reclaims.is_empty());
}
update_index_time.stop();
@ -8630,12 +8602,10 @@ impl AccountsDb {
pub fn add_root(&self, slot: Slot) -> AccountsAddRootTiming {
let mut index_time = Measure::start("index_add_root");
self.accounts_index.add_root(slot, self.caching_enabled);
self.accounts_index.add_root(slot, true);
index_time.stop();
let mut cache_time = Measure::start("cache_add_root");
if self.caching_enabled {
self.accounts_cache.add_root(slot);
}
self.accounts_cache.add_root(slot);
cache_time.stop();
let mut store_time = Measure::start("store_add_root");
if let Some(slot_stores) = self.storage.get_slot_stores(slot) {
@ -9562,7 +9532,6 @@ impl AccountsDb {
pub fn new_sized_caching(paths: Vec<PathBuf>, file_size: u64) -> Self {
AccountsDb {
file_size,
caching_enabled: true,
..AccountsDb::new(paths, &ClusterType::Development)
}
}
@ -9648,26 +9617,9 @@ impl AccountsDb {
}
}
fn do_reset_uncleaned_roots_v1(
&self,
candidates: &mut MutexGuard<Vec<Slot>>,
max_clean_root: Option<Slot>,
) {
let previous_roots = self.accounts_index.reset_uncleaned_roots(max_clean_root);
candidates.extend(previous_roots);
}
#[cfg(test)]
fn reset_uncleaned_roots_v1(&self) {
self.do_reset_uncleaned_roots_v1(&mut self.shrink_candidate_slots_v1.lock().unwrap(), None);
}
fn do_shrink_stale_slot_v1(&self, slot: Slot) -> usize {
self.do_shrink_slot_v1(slot, false)
}
fn do_shrink_slot_forced_v1(&self, slot: Slot) {
self.do_shrink_slot_v1(slot, true);
}
fn shrink_stale_slot_v1(&self, candidates: &mut MutexGuard<Vec<Slot>>) -> usize {
let mut shrunken_account_total = 0;
@ -10301,8 +10253,7 @@ pub mod tests {
#[test]
fn test_accountsdb_scan_snapshot_stores() {
solana_logger::setup();
let mut accounts_db = AccountsDb::new_single_for_tests();
accounts_db.caching_enabled = true;
let accounts_db = AccountsDb::new_single_for_tests();
let (storages, raw_expected) = sample_storages_and_accounts(&accounts_db);
let bins = 1;
@ -10388,8 +10339,7 @@ pub mod tests {
#[test]
fn test_accountsdb_scan_snapshot_stores_2nd_chunk() {
let mut accounts_db = AccountsDb::new_single_for_tests();
accounts_db.caching_enabled = true;
let accounts_db = AccountsDb::new_single_for_tests();
// enough stores to get to 2nd chunk
let bins = 1;
let slot = MAX_ITEMS_PER_CHUNK as Slot;
@ -10419,8 +10369,7 @@ pub mod tests {
#[test]
fn test_accountsdb_scan_snapshot_stores_binning() {
let mut stats = HashStats::default();
let mut accounts_db = AccountsDb::new_single_for_tests();
accounts_db.caching_enabled = true;
let accounts_db = AccountsDb::new_single_for_tests();
let (storages, raw_expected) = sample_storages_and_accounts(&accounts_db);
// just the first bin of 2
@ -10526,8 +10475,7 @@ pub mod tests {
#[test]
fn test_accountsdb_scan_snapshot_stores_binning_2nd_chunk() {
let mut accounts_db = AccountsDb::new_single_for_tests();
accounts_db.caching_enabled = true;
let accounts_db = AccountsDb::new_single_for_tests();
// enough stores to get to 2nd chunk
// range is for only 1 bin out of 256.
let bins = 256;
@ -10589,8 +10537,7 @@ pub mod tests {
fn test_accountsdb_calculate_accounts_hash_from_storages() {
solana_logger::setup();
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let (storages, raw_expected) = sample_storages_and_accounts(&db);
let expected_hash =
AccountsHasher::compute_merkle_root_loop(raw_expected.clone(), MERKLE_FANOUT, |item| {
@ -11110,8 +11057,7 @@ pub mod tests {
#[test]
fn test_accountsdb_count_stores() {
solana_logger::setup();
let mut db = AccountsDb::new_single_for_tests();
db.caching_enabled = true;
let db = AccountsDb::new_single_for_tests();
let mut pubkeys: Vec<Pubkey> = vec![];
create_account(&db, &mut pubkeys, 0, 2, DEFAULT_FILE_SIZE as usize / 3, 0);
@ -11187,8 +11133,7 @@ pub mod tests {
fn run_test_remove_unrooted_slot(is_cached: bool) {
let unrooted_slot = 9;
let unrooted_bank_id = 9;
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account0 = AccountSharedData::new(1, 0, &key);
let ancestors = vec![(unrooted_slot, 1)].into_iter().collect();
@ -11240,8 +11185,7 @@ pub mod tests {
solana_logger::setup();
let unrooted_slot = 9;
let unrooted_bank_id = 9;
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = solana_sdk::pubkey::new_rand();
let account0 = AccountSharedData::new(1, 0, &key);
db.store_for_tests(unrooted_slot, &[(&key, &account0)]);
@ -11473,8 +11417,7 @@ pub mod tests {
#[test]
fn test_account_grow() {
for pass in 0..27 {
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
let status = [AccountStorageStatus::Available, AccountStorageStatus::Full];
let pubkey1 = solana_sdk::pubkey::new_rand();
@ -11560,8 +11503,7 @@ pub mod tests {
//This test is pedantic
//A slot is purged when a non root bank is cleaned up. If a slot is behind root but it is
//not root, it means we are retaining dead banks.
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
//store an account
@ -11637,8 +11579,7 @@ pub mod tests {
fn test_clean_zero_lamport_and_dead_slot() {
solana_logger::setup();
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey1 = solana_sdk::pubkey::new_rand();
let pubkey2 = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(1, 1, AccountSharedData::default().owner());
@ -11702,8 +11643,7 @@ pub mod tests {
fn test_clean_multiple_zero_lamport_decrements_index_ref_count() {
solana_logger::setup();
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey1 = solana_sdk::pubkey::new_rand();
let pubkey2 = solana_sdk::pubkey::new_rand();
let zero_lamport_account =
@ -11751,8 +11691,7 @@ pub mod tests {
fn test_clean_zero_lamport_and_old_roots() {
solana_logger::setup();
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
let zero_lamport_account =
@ -11797,8 +11736,7 @@ pub mod tests {
fn test_clean_old_with_normal_account() {
solana_logger::setup();
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
//store an account
@ -11826,8 +11764,7 @@ pub mod tests {
fn test_clean_old_with_zero_lamport_account() {
solana_logger::setup();
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey1 = solana_sdk::pubkey::new_rand();
let pubkey2 = solana_sdk::pubkey::new_rand();
let normal_account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
@ -12004,8 +11941,7 @@ pub mod tests {
fn test_clean_max_slot_zero_lamport_account() {
solana_logger::setup();
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
let zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner());
@ -12050,8 +11986,7 @@ pub mod tests {
fn test_uncleaned_roots_with_account() {
solana_logger::setup();
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
//store an account
@ -12071,8 +12006,7 @@ pub mod tests {
fn test_uncleaned_roots_with_no_account() {
solana_logger::setup();
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
assert_eq!(accounts.accounts_index.uncleaned_roots_len(), 0);
@ -12089,8 +12023,7 @@ pub mod tests {
fn test_accounts_db_serialize1() {
for pass in 0..2 {
solana_logger::setup();
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
let mut pubkeys: Vec<Pubkey> = vec![];
// Create 100 accounts in slot 0
@ -12245,8 +12178,7 @@ pub mod tests {
let zero_lamport_account = AccountSharedData::new(zero_lamport, no_data, &owner);
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
accounts.get_accounts_delta_hash(0);
accounts.add_root_and_flush_write_cache(0);
@ -12326,8 +12258,7 @@ pub mod tests {
let zero_lamport_account = AccountSharedData::new(zero_lamport, no_data, &owner);
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
accounts.add_root(0);
let mut current_slot = 1;
@ -12395,8 +12326,7 @@ pub mod tests {
let filler_account = AccountSharedData::new(some_lamport, no_data, &owner);
let filler_account_pubkey = solana_sdk::pubkey::new_rand();
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
let mut current_slot = 1;
accounts.store_for_tests(current_slot, &[(&pubkey, &account)]);
@ -12450,8 +12380,7 @@ pub mod tests {
let dummy_account = AccountSharedData::new(dummy_lamport, no_data, &owner);
let dummy_pubkey = Pubkey::default();
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
let mut current_slot = 1;
accounts.store_for_tests(current_slot, &[(&pubkey, &account)]);
@ -12894,8 +12823,7 @@ pub mod tests {
fn test_verify_bank_hash() {
use BankHashVerificationError::*;
solana_logger::setup();
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = solana_sdk::pubkey::new_rand();
let some_data_len = 0;
@ -13112,8 +13040,7 @@ pub mod tests {
#[test]
fn test_get_snapshot_storages_only_older_than_or_equal_to_snapshot_slot() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account = AccountSharedData::new(1, 0, &key);
@ -13132,8 +13059,7 @@ pub mod tests {
#[test]
fn test_get_snapshot_storages_only_non_empty() {
for pass in 0..2 {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account = AccountSharedData::new(1, 0, &key);
@ -13161,8 +13087,7 @@ pub mod tests {
#[test]
fn test_get_snapshot_storages_only_roots() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account = AccountSharedData::new(1, 0, &key);
@ -13178,8 +13103,7 @@ pub mod tests {
#[test]
fn test_get_snapshot_storages_exclude_empty() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account = AccountSharedData::new(1, 0, &key);
@ -13204,8 +13128,7 @@ pub mod tests {
#[test]
fn test_get_snapshot_storages_with_base_slot() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account = AccountSharedData::new(1, 0, &key);
@ -13223,8 +13146,7 @@ pub mod tests {
#[test]
#[should_panic(expected = "double remove of account in slot: 0/store: 0!!")]
fn test_storage_remove_account_double_remove() {
let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
accounts.caching_enabled = true;
let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development);
let pubkey = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
accounts.store_for_tests(0, &[(&pubkey, &account)]);
@ -13263,8 +13185,7 @@ pub mod tests {
let purged_pubkey2 = solana_sdk::pubkey::new_rand();
let mut current_slot = 0;
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
// create intermediate updates to purged_pubkey1 so that
// generate_index must add slots as root last at once
@ -13326,8 +13247,7 @@ pub mod tests {
let zero_lamport_account = AccountSharedData::new(zero_lamport, data_size, &owner);
let mut current_slot = 0;
let mut accounts = AccountsDb::new_sized_no_extra_stores(Vec::new(), store_size);
accounts.caching_enabled = true;
let accounts = AccountsDb::new_sized_no_extra_stores(Vec::new(), store_size);
// A: Initialize AccountsDb with pubkey1 and pubkey2
current_slot += 1;
@ -13456,8 +13376,7 @@ pub mod tests {
let dummy_pubkey = solana_sdk::pubkey::new_rand();
let mut current_slot = 0;
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
// A: Initialize AccountsDb with pubkey1 and pubkey2
current_slot += 1;
@ -13587,9 +13506,10 @@ pub mod tests {
}
#[test]
#[ignore]
fn test_shrink_next_slots() {
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = false;
let accounts = AccountsDb::new_single_for_tests();
// accounts.caching_enabled = false;
let mut current_slot = 7;
@ -13626,11 +13546,12 @@ pub mod tests {
}
#[test]
#[ignore] // this test only works with write cache off
fn test_shrink_reset_uncleaned_roots() {
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = false;
let accounts = AccountsDb::new_single_for_tests();
// accounts.caching_enabled = false;
accounts.reset_uncleaned_roots_v1();
// accounts.reset_uncleaned_roots_v1();
assert_eq!(
*accounts.shrink_candidate_slots_v1.lock().unwrap(),
vec![] as Vec<Slot>
@ -13643,11 +13564,11 @@ pub mod tests {
accounts.get_accounts_delta_hash(2);
accounts.add_root(2);
accounts.reset_uncleaned_roots_v1();
// accounts.reset_uncleaned_roots_v1();
let actual_slots = accounts.shrink_candidate_slots_v1.lock().unwrap().clone();
assert_eq!(actual_slots, vec![] as Vec<Slot>);
accounts.reset_uncleaned_roots_v1();
// accounts.reset_uncleaned_roots_v1();
let mut actual_slots = accounts.shrink_candidate_slots_v1.lock().unwrap().clone();
actual_slots.sort_unstable();
assert_eq!(actual_slots, vec![0, 1, 2]);
@ -13665,8 +13586,7 @@ pub mod tests {
solana_logger::setup();
for startup in &[false, true] {
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
let pubkey_count = 100;
let pubkeys: Vec<_> = (0..pubkey_count)
@ -13752,7 +13672,6 @@ pub mod tests {
solana_logger::setup();
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let pubkey_count = 30000;
let pubkeys: Vec<_> = (0..pubkey_count)
@ -14034,12 +13953,13 @@ pub mod tests {
}
#[test]
#[ignore]
fn test_shrink_stale_slots_skipped() {
solana_logger::setup();
let mut accounts = AccountsDb::new_single_for_tests();
let accounts = AccountsDb::new_single_for_tests();
// this test tests v1 code, which can not use the write cache.
accounts.caching_enabled = false;
// accounts.caching_enabled = false;
let pubkey_count = 30000;
let pubkeys: Vec<_> = (0..pubkey_count)
@ -14268,8 +14188,7 @@ pub mod tests {
#[test]
fn test_store_overhead() {
solana_logger::setup();
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
let account = AccountSharedData::default();
let pubkey = solana_sdk::pubkey::new_rand();
accounts.store_for_tests(0, &[(&pubkey, &account)]);
@ -14400,8 +14319,7 @@ pub mod tests {
#[test]
#[should_panic(expected = "We've run out of storage ids!")]
fn test_wrapping_append_vec_id() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let zero_lamport_account =
AccountSharedData::new(0, 0, AccountSharedData::default().owner());
@ -14428,8 +14346,7 @@ pub mod tests {
#[should_panic(expected = "We've run out of storage ids!")]
fn test_reuse_append_vec_id() {
solana_logger::setup();
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let zero_lamport_account =
AccountSharedData::new(0, 0, AccountSharedData::default().owner());
@ -14455,8 +14372,7 @@ pub mod tests {
#[test]
fn test_zero_lamport_new_root_not_cleaned() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let account_key = Pubkey::new_unique();
let zero_lamport_account =
AccountSharedData::new(0, 0, AccountSharedData::default().owner());
@ -14481,8 +14397,7 @@ pub mod tests {
#[test]
fn test_store_load_cached() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account0 = AccountSharedData::new(1, 0, &key);
let slot = 0;
@ -14514,8 +14429,7 @@ pub mod tests {
#[test]
fn test_store_flush_load_cached() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account0 = AccountSharedData::new(1, 0, &key);
let slot = 0;
@ -14542,8 +14456,7 @@ pub mod tests {
#[test]
fn test_flush_accounts_cache() {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let account0 = AccountSharedData::new(1, 0, &Pubkey::default());
let unrooted_slot = 4;
@ -14610,7 +14523,6 @@ pub mod tests {
fn run_test_flush_accounts_cache_if_needed(num_roots: usize, num_unrooted: usize) {
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.write_cache_limit_bytes = Some(max_cache_slots() as u64);
db.caching_enabled = true;
let space = 1; // # data bytes per account. write cache counts data len
let account0 = AccountSharedData::new(1, space, &Pubkey::default());
let mut keys = vec![];
@ -15568,8 +15480,7 @@ pub mod tests {
#[test]
fn test_partial_clean() {
solana_logger::setup();
let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development);
db.caching_enabled = true;
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let account_key1 = Pubkey::new_unique();
let account_key2 = Pubkey::new_unique();
let account1 = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
@ -16295,8 +16206,7 @@ pub mod tests {
#[test]
fn test_calculate_storage_count_and_alive_bytes() {
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
let shared_key = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(1, 1, AccountSharedData::default().owner());
let slot0 = 0;
@ -16331,8 +16241,7 @@ pub mod tests {
#[test]
fn test_calculate_storage_count_and_alive_bytes_2_accounts() {
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
let keys = [
solana_sdk::pubkey::Pubkey::new(&[0; 32]),
solana_sdk::pubkey::Pubkey::new(&[255; 32]),
@ -16374,8 +16283,7 @@ pub mod tests {
#[test]
fn test_set_storage_count_and_alive_bytes() {
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
// make sure we have storage 0
let shared_key = solana_sdk::pubkey::new_rand();
@ -16413,8 +16321,7 @@ pub mod tests {
#[test]
fn test_purge_alive_unrooted_slots_after_clean() {
let mut accounts = AccountsDb::new_single_for_tests();
accounts.caching_enabled = true;
let accounts = AccountsDb::new_single_for_tests();
// Key shared between rooted and nonrooted slot
let shared_key = solana_sdk::pubkey::new_rand();
@ -16477,8 +16384,7 @@ pub mod tests {
#[test]
fn test_clean_accounts_with_last_full_snapshot_slot() {
solana_logger::setup();
let mut accounts_db = AccountsDb::new_single_for_tests();
accounts_db.caching_enabled = true;
let accounts_db = AccountsDb::new_single_for_tests();
let pubkey = solana_sdk::pubkey::new_rand();
let owner = solana_sdk::pubkey::new_rand();
let space = 0;
@ -16687,34 +16593,30 @@ pub mod tests {
/// useful to adapt tests written prior to introduction of the write cache
/// to use the write cache
fn add_root_and_flush_write_cache(&self, slot: Slot) {
if self.caching_enabled {
self.add_root(slot);
self.flush_root_write_cache(slot);
}
self.add_root(slot);
self.flush_root_write_cache(slot);
}
/// useful to adapt tests written prior to introduction of the write cache
/// to use the write cache
fn flush_root_write_cache(&self, root: Slot) {
if self.caching_enabled {
assert!(
self.accounts_index
.roots_tracker
.read()
.unwrap()
.alive_roots
.contains(&root),
"slot: {root}"
);
self.flush_accounts_cache(true, Some(root));
}
assert!(
self.accounts_index
.roots_tracker
.read()
.unwrap()
.alive_roots
.contains(&root),
"slot: {root}"
);
self.flush_accounts_cache(true, Some(root));
}
/// callers use to call store_uncached. But, this is not allowed anymore.
fn store_for_tests(&self, slot: Slot, accounts: &[(&Pubkey, &AccountSharedData)]) {
self.store(
(slot, accounts, INCLUDE_SLOT_IN_HASH_TESTS),
self.caching_enabled,
true,
None,
StoreReclaims::Default,
);
@ -17605,8 +17507,7 @@ pub mod tests {
account_count += 1;
}
debug!("space: {space}, lamports: {lamports}, alive: {alive}, account_count: {account_count}, append_opposite_alive_account: {append_opposite_alive_account}, append_opposite_zero_lamport_account: {append_opposite_zero_lamport_account}, normal_account_count: {normal_account_count}");
let mut db = AccountsDb::new_single_for_tests();
db.caching_enabled = true;
let db = AccountsDb::new_single_for_tests();
let slot5 = 5;
let mut account = AccountSharedData::new(
lamports,

View File

@ -8699,9 +8699,7 @@ pub(crate) mod tests {
updater();
let new = bank.capitalization();
if asserter(old, new) {
if bank.rc.accounts.accounts_db.caching_enabled {
add_root_and_flush_write_cache(bank);
}
add_root_and_flush_write_cache(bank);
assert_eq!(bank.capitalization(), bank.calculate_capitalization(true));
}
}
@ -14957,6 +14955,7 @@ pub(crate) mod tests {
// process_stale_slot_with_budget is no longer called. We'll remove this test when we remove the function
#[ignore]
#[test]
#[ignore] // this test only works when not using the write cache
fn test_process_stale_slot_with_budget() {
solana_logger::setup();
let pubkey1 = solana_sdk::pubkey::new_rand();
@ -15173,10 +15172,8 @@ pub(crate) mod tests {
/// useful to adapt tests written prior to introduction of the write cache
/// to use the write cache
fn add_root_and_flush_write_cache(bank: &Bank) {
if bank.rc.accounts.accounts_db.caching_enabled {
bank.rc.accounts.add_root(bank.slot());
bank.flush_accounts_cache_slot_for_tests()
}
bank.rc.accounts.add_root(bank.slot());
bank.flush_accounts_cache_slot_for_tests()
}
#[test]