Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AccountStorage.get_slot_storage_entry #29480

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions runtime/src/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ impl AccountStorage {
self.map.get(&slot).map(|result| result.value().clone())
}

/// return the append vec for 'slot' if it exists
/// This is only ever called when shrink is not possibly running and there is a max of 1 append vec per slot.
pub(crate) fn get_slot_storage_entry(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
self.get_slot_stores(slot).and_then(|res| {
let read = res.read().unwrap();
assert!(read.len() <= 1);
read.values().next().cloned()
})
}

/// return all append vecs for 'slot' if any exist
pub(crate) fn get_slot_storage_entries(&self, slot: Slot) -> Option<SnapshotStorage> {
self.get_slot_stores(slot)
.map(|res| res.read().unwrap().values().cloned().collect())
Expand Down
34 changes: 14 additions & 20 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2960,11 +2960,7 @@ impl AccountsDb {
if slot > max_slot_inclusive {
return;
}
for storage in self
.storage
.get_slot_storage_entries(slot)
.unwrap_or_default()
{
if let Some(storage) = self.storage.get_slot_storage_entry(slot) {
storage.all_accounts().iter().for_each(|account| {
let pk = account.pubkey();
match pubkey_refcount.entry(*pk) {
Expand Down Expand Up @@ -4841,7 +4837,7 @@ impl AccountsDb {
Ok(used_index)
}

/// Scan a specific slot through all the account storage in parallel
/// Scan a specific slot through all the account storage
pub fn scan_account_storage<R, B>(
&self,
slot: Slot,
Expand Down Expand Up @@ -4883,17 +4879,12 @@ impl AccountsDb {
// If the slot is not in the cache, then all the account information must have
// been flushed. This is guaranteed because we only remove the rooted slot from
// the cache *after* we've finished flushing in `flush_slot_cache`.
let storage_maps = self
.storage
.get_slot_storage_entries(slot)
.unwrap_or_default();
self.thread_pool.install(|| {
storage_maps.par_iter().for_each(|storage| {
storage.accounts.account_iter().for_each(|account| {
storage_scan_func(&retval, LoadedAccount::Stored(account))
})
});
});
if let Some(storage) = self.storage.get_slot_storage_entry(slot) {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: Function's doc-comment seems out of date as we're no longer scanning through storage in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll fix that at some point soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. failed coverage again due to intermittency...

storage
.accounts
.account_iter()
.for_each(|account| storage_scan_func(&retval, LoadedAccount::Stored(account)));
}

ScanStorageResult::Stored(retval)
}
Expand Down Expand Up @@ -8971,10 +8962,13 @@ impl AccountsDb {
for (index, slot) in slots.iter().enumerate() {
let mut scan_time = Measure::start("scan");
log_status.report(index as u64);
let storage_maps = self.storage.get_slot_storage_entries(*slot);
let accounts_map = storage_maps
let storage = self
.storage
.get_slot_storage_entry(*slot)
.map(|storage| vec![storage]);
let accounts_map = storage
.as_ref()
.map(|storage_maps| self.process_storage_slot(storage_maps))
.map(|storage| self.process_storage_slot(storage))
apfitzge marked this conversation as resolved.
Show resolved Hide resolved
.unwrap_or_default();

scan_time.stop();
Expand Down