get_slot_stores -> get_slot_storage_entry (#29665)

This commit is contained in:
Jeff Washington (jwash) 2023-01-12 09:09:56 -06:00 committed by GitHub
parent 9d1c0c5a3c
commit b64f58614d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 53 additions and 107 deletions

View File

@ -6338,15 +6338,7 @@ impl AccountsDb {
// If the above sizing function is correct, just one AppendVec is enough to hold // If the above sizing function is correct, just one AppendVec is enough to hold
// all the data for the slot // all the data for the slot
assert_eq!( assert!(self.storage.get_slot_storage_entry(slot).is_some());
self.storage
.get_slot_stores(slot)
.unwrap()
.read()
.unwrap()
.len(),
1
);
} }
// Remove this slot from the cache, which will to AccountsDb's new readers should look like an // Remove this slot from the cache, which will to AccountsDb's new readers should look like an
@ -7738,11 +7730,9 @@ impl AccountsDb {
} }
dead_slots.retain(|slot| { dead_slots.retain(|slot| {
if let Some(slot_stores) = self.storage.get_slot_stores(*slot) { if let Some(slot_store) = self.storage.get_slot_storage_entry(*slot) {
for x in slot_stores.read().unwrap().values() { if slot_store.count() != 0 {
if x.count() != 0 { return false;
return false;
}
} }
} }
true true
@ -7902,10 +7892,8 @@ impl AccountsDb {
let mut stores = vec![]; let mut stores = vec![];
// get all stores in a vec so we can iterate in parallel // get all stores in a vec so we can iterate in parallel
for slot in dead_slots.iter() { for slot in dead_slots.iter() {
if let Some(slot_storage) = self.storage.get_slot_stores(*slot) { if let Some(slot_storage) = self.storage.get_slot_storage_entry(*slot) {
for store in slot_storage.read().unwrap().values() { stores.push(slot_storage);
stores.push(store.clone());
}
} }
} }
// get all pubkeys in all dead slots // get all pubkeys in all dead slots
@ -9043,23 +9031,16 @@ impl AccountsDb {
slots.sort(); slots.sort();
info!("{}: count_and status for {} slots:", label, slots.len()); info!("{}: count_and status for {} slots:", label, slots.len());
for slot in &slots { for slot in &slots {
let slot_stores = self.storage.get_slot_stores(*slot).unwrap(); let entry = self.storage.get_slot_storage_entry(*slot).unwrap();
let r_slot_stores = slot_stores.read().unwrap(); info!(
let mut ids: Vec<_> = r_slot_stores.keys().cloned().collect(); " slot: {} id: {} count_and_status: {:?} approx_store_count: {} len: {} capacity: {}",
#[allow(clippy::stable_sort_primitive)] slot,
ids.sort(); entry.append_vec_id(),
for id in &ids { *entry.count_and_status.read().unwrap(),
let entry = r_slot_stores.get(id).unwrap(); entry.approx_store_count.load(Ordering::Relaxed),
info!( entry.accounts.len(),
" slot: {} id: {} count_and_status: {:?} approx_store_count: {} len: {} capacity: {}", entry.accounts.capacity(),
slot, );
id,
*entry.count_and_status.read().unwrap(),
entry.approx_store_count.load(Ordering::Relaxed),
entry.accounts.len(),
entry.accounts.capacity(),
);
}
} }
} }
} }
@ -9126,8 +9107,8 @@ impl AccountsDb {
pub fn alive_account_count_in_slot(&self, slot: Slot) -> usize { pub fn alive_account_count_in_slot(&self, slot: Slot) -> usize {
self.storage self.storage
.get_slot_stores(slot) .get_slot_storage_entry(slot)
.map(|storages| storages.read().unwrap().values().map(|s| s.count()).sum()) .map(|storage| storage.count())
.unwrap_or(0) .unwrap_or(0)
.saturating_add( .saturating_add(
self.accounts_cache self.accounts_cache
@ -10528,16 +10509,12 @@ pub mod tests {
db.get_accounts_delta_hash(1); db.get_accounts_delta_hash(1);
db.add_root_and_flush_write_cache(1); db.add_root_and_flush_write_cache(1);
{ {
let slot_0_stores = &db.storage.get_slot_stores(0).unwrap(); let slot_0_store = &db.storage.get_slot_storage_entry(0).unwrap();
let slot_1_stores = &db.storage.get_slot_stores(1).unwrap(); let slot_1_store = &db.storage.get_slot_storage_entry(1).unwrap();
let r_slot_0_stores = slot_0_stores.read().unwrap(); assert_eq!(slot_0_store.count(), 2);
let r_slot_1_stores = slot_1_stores.read().unwrap(); assert_eq!(slot_1_store.count(), 2);
assert_eq!(r_slot_0_stores.len(), 1); assert_eq!(slot_0_store.approx_stored_count(), 2);
assert_eq!(r_slot_1_stores.len(), 1); assert_eq!(slot_1_store.approx_stored_count(), 2);
assert_eq!(r_slot_0_stores.get(&0).unwrap().count(), 2);
assert_eq!(r_slot_1_stores[&1].count(), 2);
assert_eq!(r_slot_0_stores.get(&0).unwrap().approx_stored_count(), 2);
assert_eq!(r_slot_1_stores[&1].approx_stored_count(), 2);
} }
// overwrite old rooted account version; only the r_slot_0_stores.count() should be // overwrite old rooted account version; only the r_slot_0_stores.count() should be
@ -10546,16 +10523,12 @@ pub mod tests {
db.store_for_tests(2, &[(&pubkeys[0], &account)]); db.store_for_tests(2, &[(&pubkeys[0], &account)]);
db.clean_accounts_for_tests(); db.clean_accounts_for_tests();
{ {
let slot_0_stores = &db.storage.get_slot_stores(0).unwrap(); let slot_0_store = &db.storage.get_slot_storage_entry(0).unwrap();
let slot_1_stores = &db.storage.get_slot_stores(1).unwrap(); let slot_1_store = &db.storage.get_slot_storage_entry(1).unwrap();
let r_slot_0_stores = slot_0_stores.read().unwrap(); assert_eq!(slot_0_store.count(), 1);
let r_slot_1_stores = slot_1_stores.read().unwrap(); assert_eq!(slot_1_store.count(), 2);
assert_eq!(r_slot_0_stores.len(), 1); assert_eq!(slot_0_store.approx_stored_count(), 2);
assert_eq!(r_slot_1_stores.len(), 1); assert_eq!(slot_1_store.approx_stored_count(), 2);
assert_eq!(r_slot_0_stores.get(&0).unwrap().count(), 1);
assert_eq!(r_slot_1_stores[&1].count(), 2);
assert_eq!(r_slot_0_stores.get(&0).unwrap().approx_stored_count(), 2);
assert_eq!(r_slot_1_stores[&1].approx_stored_count(), 2);
} }
} }
@ -10613,7 +10586,7 @@ pub mod tests {
assert!(db.load_without_fixed_root(&ancestors, &key).is_none()); assert!(db.load_without_fixed_root(&ancestors, &key).is_none());
assert!(db.bank_hashes.read().unwrap().get(&unrooted_slot).is_none()); assert!(db.bank_hashes.read().unwrap().get(&unrooted_slot).is_none());
assert!(db.accounts_cache.slot_cache(unrooted_slot).is_none()); assert!(db.accounts_cache.slot_cache(unrooted_slot).is_none());
assert!(db.storage.get_slot_stores(unrooted_slot).is_none()); assert!(db.storage.get_slot_storage_entry(unrooted_slot).is_none());
assert!(db.accounts_index.get_account_read_entry(&key).is_none()); assert!(db.accounts_index.get_account_read_entry(&key).is_none());
assert!(db assert!(db
.accounts_index .accounts_index
@ -10726,16 +10699,7 @@ pub mod tests {
} }
fn check_storage(accounts: &AccountsDb, slot: Slot, count: usize) -> bool { fn check_storage(accounts: &AccountsDb, slot: Slot, count: usize) -> bool {
assert_eq!( assert!(accounts.storage.get_slot_storage_entry(slot).is_some());
accounts
.storage
.get_slot_stores(slot)
.unwrap()
.read()
.unwrap()
.len(),
1
);
let slot_storages = accounts.storage.get_slot_stores(slot).unwrap(); let slot_storages = accounts.storage.get_slot_stores(slot).unwrap();
let mut total_count: usize = 0; let mut total_count: usize = 0;
let r_slot_storages = slot_storages.read().unwrap(); let r_slot_storages = slot_storages.read().unwrap();
@ -10881,11 +10845,9 @@ pub mod tests {
accounts.store_for_tests(0, &[(&pubkey1, &account1)]); accounts.store_for_tests(0, &[(&pubkey1, &account1)]);
if pass == 0 { if pass == 0 {
accounts.add_root_and_flush_write_cache(0); accounts.add_root_and_flush_write_cache(0);
let stores = &accounts.storage.get_slot_stores(0).unwrap(); let store = &accounts.storage.get_slot_storage_entry(0).unwrap();
let r_stores = stores.read().unwrap(); assert_eq!(store.count(), 1);
assert_eq!(r_stores.len(), 1); assert_eq!(store.status(), AccountStorageStatus::Available);
assert_eq!(r_stores[&0].count(), 1);
assert_eq!(r_stores[&0].status(), AccountStorageStatus::Available);
continue; continue;
} }
@ -10896,11 +10858,9 @@ pub mod tests {
if pass == 1 { if pass == 1 {
accounts.add_root_and_flush_write_cache(0); accounts.add_root_and_flush_write_cache(0);
assert_eq!(accounts.storage.len(), 1); assert_eq!(accounts.storage.len(), 1);
let stores = &accounts.storage.get_slot_stores(0).unwrap(); let store = &accounts.storage.get_slot_storage_entry(0).unwrap();
let r_stores = stores.read().unwrap(); assert_eq!(store.count(), 2);
assert_eq!(r_stores.len(), 1); assert_eq!(store.status(), AccountStorageStatus::Available);
assert_eq!(r_stores[&0].count(), 2);
assert_eq!(r_stores[&0].status(), AccountStorageStatus::Available);
continue; continue;
} }
let ancestors = vec![(0, 0)].into_iter().collect(); let ancestors = vec![(0, 0)].into_iter().collect();
@ -10926,10 +10886,8 @@ pub mod tests {
if flush { if flush {
accounts.add_root_and_flush_write_cache(0); accounts.add_root_and_flush_write_cache(0);
assert_eq!(accounts.storage.len(), 1); assert_eq!(accounts.storage.len(), 1);
let stores = &accounts.storage.get_slot_stores(0).unwrap(); let store = &accounts.storage.get_slot_storage_entry(0).unwrap();
let r_stores = stores.read().unwrap(); assert_eq!(store.status(), status[0]);
assert_eq!(r_stores.len(), 1);
assert_eq!(r_stores[&0].status(), status[0]);
} }
let ancestors = vec![(0, 0)].into_iter().collect(); let ancestors = vec![(0, 0)].into_iter().collect();
assert_eq!( assert_eq!(
@ -10977,14 +10935,14 @@ pub mod tests {
accounts.get_accounts_delta_hash(0); accounts.get_accounts_delta_hash(0);
//slot is still there, since gc is lazy //slot is still there, since gc is lazy
assert!(accounts assert_eq!(
.storage accounts
.get_slot_stores(0) .storage
.unwrap() .get_slot_storage_entry(0)
.read() .unwrap()
.unwrap() .append_vec_id(),
.get(&id) id
.is_some()); );
//store causes clean //store causes clean
accounts.store_for_tests(1, &[(&pubkey, &account)]); accounts.store_for_tests(1, &[(&pubkey, &account)]);
@ -11009,17 +10967,10 @@ pub mod tests {
impl AccountsDb { impl AccountsDb {
fn all_account_count_in_append_vec(&self, slot: Slot) -> usize { fn all_account_count_in_append_vec(&self, slot: Slot) -> usize {
let slot_storage = self.storage.get_slot_stores(slot); let store = self.storage.get_slot_storage_entry(slot);
if let Some(slot_storage) = slot_storage { if let Some(store) = store {
let r_slot_storage = slot_storage.read().unwrap(); let count = store.all_accounts().len();
let count = r_slot_storage let stored_count = store.approx_stored_count();
.values()
.map(|store| store.all_accounts().len())
.sum();
let stored_count: usize = r_slot_storage
.values()
.map(|store| store.approx_stored_count())
.sum();
assert_eq!(stored_count, count); assert_eq!(stored_count, count);
count count
} else { } else {
@ -12521,12 +12472,7 @@ pub mod tests {
db.store_for_tests(base_slot, &[(&key, &account)]); db.store_for_tests(base_slot, &[(&key, &account)]);
if pass == 0 { if pass == 0 {
db.add_root_and_flush_write_cache(base_slot); db.add_root_and_flush_write_cache(base_slot);
db.storage db.storage.remove(&base_slot);
.get_slot_stores(base_slot)
.unwrap()
.write()
.unwrap()
.clear();
assert!(db.get_snapshot_storages(..=after_slot, None).0.is_empty()); assert!(db.get_snapshot_storages(..=after_slot, None).0.is_empty());
continue; continue;
} }