Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

test_shrink_candidate_slots uses write cache #29145

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13752,7 +13752,8 @@ pub mod tests {
fn test_shrink_candidate_slots() {
solana_logger::setup();

let accounts = AccountsDb::new_single_for_tests();
let mut accounts = AccountsDb::new_single_for_tests();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intent to also enable the write cache here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The write cache will be enabled globally shortly. The shrink ratio parameter doesn't affect the v1 shrink code path anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha.

Does

accounts.shrink_candidate_slots();

end up calling the v1 shrink code path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't look like it. But how we create append vecs is different. Whatever the case, I updated the test to use the write cache completely. I just have to back this out once everyone can only use the write cache.

accounts.caching_enabled = true;

let pubkey_count = 30000;
let pubkeys: Vec<_> = (0..pubkey_count)
Expand All @@ -13772,7 +13773,8 @@ pub mod tests {
accounts.store_for_tests(current_slot, &[(pubkey, &account)]);
}
let shrink_slot = current_slot;
accounts.add_root(current_slot);
accounts.get_accounts_delta_hash(current_slot);
accounts.add_root_and_flush_write_cache(current_slot);

current_slot += 1;
let pubkey_count_after_shrink = 25000;
Expand All @@ -13781,16 +13783,19 @@ pub mod tests {
for pubkey in updated_pubkeys {
accounts.store_for_tests(current_slot, &[(pubkey, &account)]);
}
accounts.add_root(current_slot);
accounts.get_accounts_delta_hash(current_slot);
accounts.add_root_and_flush_write_cache(current_slot);
accounts.clean_accounts_for_tests();

assert_eq!(
pubkey_count,
accounts.all_account_count_in_append_vec(shrink_slot)
);

// Only, try to shrink stale slots, nothing happens because 90/100
// Only, try to shrink stale slots, nothing happens because shrink ratio
// is not small enough to do a shrink
// Note this shrink ratio had to change because we are WAY over-allocating append vecs when we flush the write cache at the moment.
accounts.shrink_ratio = AccountShrinkThreshold::TotalSpace { shrink_ratio: 0.4 };
accounts.shrink_candidate_slots();
assert_eq!(
pubkey_count,
Expand Down