test_shrink_collect_simple uses write cache (#29115)

This commit is contained in:
Jeff Washington (jwash) 2022-12-07 11:18:45 -06:00 committed by GitHub
parent 8f24ceffbd
commit 59359c3ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 12 deletions

View File

@ -11533,7 +11533,7 @@ pub mod tests {
account2
);
// lots of stores, but 7 storages should be enough for everything
// lots of writes, but they are all duplicates
for i in 0..25 {
accounts.store_for_tests(0, &[(&pubkey1, &account1)]);
let flush = pass == i + 2;
@ -17639,16 +17639,15 @@ 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 size = 100000;
let db = AccountsDb::new_single_for_tests();
let mut db = AccountsDb::new_single_for_tests();
db.caching_enabled = true;
let slot5 = 5;
let inserted_store =
db.create_and_insert_store(slot5, size, "test");
let mut account = AccountSharedData::new(
lamports,
space,
AccountSharedData::default().owner(),
);
let mut to_purge = Vec::default();
for pubkey in pubkeys.iter().take(account_count) {
// store in append vec and index
let old_lamports = account.lamports();
@ -17667,14 +17666,19 @@ pub mod tests {
}
if !alive {
// remove from index so pubkey is 'dead'
db.accounts_index.purge_exact(
pubkey,
&([slot5].into_iter().collect::<HashSet<_>>()),
&mut Vec::default(),
);
to_purge.push(*pubkey);
}
}
let storages = vec![inserted_store];
db.add_root_and_flush_write_cache(slot5);
to_purge.iter().for_each(|pubkey| {
db.accounts_index.purge_exact(
pubkey,
&([slot5].into_iter().collect::<HashSet<_>>()),
&mut Vec::default(),
);
});
let storages = db.get_storages_for_slot(slot5).unwrap().to_vec();
let mut stored_accounts = Vec::default();
assert_eq!(storages.len(), 1);
let shrink_collect = db.shrink_collect(
@ -17763,7 +17767,18 @@ pub mod tests {
assert_eq!(shrink_collect.aligned_total_bytes, 0);
assert_eq!(shrink_collect.alive_total_bytes, 0);
}
assert_eq!(shrink_collect.original_bytes, 102400);
// these constants are multiples of page size (4096).
// They are determined by what size append vec gets created when the write cache is flushed to an append vec.
// Thus, they are dependent on the # of accounts that are written. They were identified by hitting the asserts and noting the value
// for shrink_collect.original_bytes at each account_count and then encoding it here.
let expected_original_bytes = if account_count >= 100 {
28672
} else if account_count >= 50 {
16384
} else {
4096
};
assert_eq!(shrink_collect.original_bytes, expected_original_bytes);
assert_eq!(
shrink_collect.store_ids,
vec![storages[0].append_vec_id()]