Skip to content
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
3 changes: 1 addition & 2 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4941,8 +4941,7 @@ impl AccountsDb {
self.scan_cache_storage_fallback(slot, cache_map_func, |retval, storage| {
match scan_account_storage_data {
ScanAccountStorageData::NoData => {
storage.scan_accounts(|account| {
let account_without_data = StoredAccountInfoWithoutData::new_from(&account);
storage.scan_accounts_without_data(|account_without_data| {
Copy link
Author

Choose a reason for hiding this comment

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

Here's the main change. We now do not load account data if scan_account_storage_data is NoData 🎉

storage_scan_func(retval, &account_without_data, None);
});
}
Expand Down
22 changes: 21 additions & 1 deletion accounts-db/src/accounts_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::account_storage::meta::StoredAccountMeta;
use {
crate::{
account_info::AccountInfo,
account_storage::stored_account_info::StoredAccountInfo,
account_storage::stored_account_info::{StoredAccountInfo, StoredAccountInfoWithoutData},
accounts_db::AccountsFileId,
accounts_update_notifier_interface::AccountForGeyser,
append_vec::{AppendVec, AppendVecError, IndexInfo},
Expand Down Expand Up @@ -265,6 +265,26 @@ impl AccountsFile {
}

/// Iterate over all accounts and call `callback` with each account.
///
/// Note that account data is not read/passed to the callback.
pub fn scan_accounts_without_data(
&self,
callback: impl for<'local> FnMut(StoredAccountInfoWithoutData<'local>),
) {
match self {
Self::AppendVec(av) => av.scan_accounts_without_data(callback),
Self::TieredStorage(ts) => {
if let Some(reader) = ts.reader() {
_ = reader.scan_accounts_without_data(callback);
}
}
}
}

/// Iterate over all accounts and call `callback` with each account.
///
/// Prefer scan_accounts_without_data() when account data is not needed,
/// as it can potentially read less and be faster.
pub fn scan_accounts(&self, callback: impl for<'local> FnMut(StoredAccountInfo<'local>)) {
match self {
Self::AppendVec(av) => av.scan_accounts(callback),
Expand Down
25 changes: 24 additions & 1 deletion accounts-db/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
crate::{
account_storage::{
meta::{AccountMeta, StoredAccountMeta, StoredMeta},
stored_account_info::StoredAccountInfo,
stored_account_info::{StoredAccountInfo, StoredAccountInfoWithoutData},
},
accounts_file::{
AccountsFileError, InternalsForArchive, MatchAccountOwnerError, Result, StorageAccess,
Expand Down Expand Up @@ -1100,6 +1100,29 @@ impl AppendVec {
}

/// Iterate over all accounts and call `callback` with each account.
///
/// Note that account data is not read/passed to the callback.
pub fn scan_accounts_without_data(
&self,
mut callback: impl for<'local> FnMut(StoredAccountInfoWithoutData<'local>),
) {
self.scan_stored_accounts_no_data(|stored_account| {
let account = StoredAccountInfoWithoutData {
pubkey: stored_account.pubkey(),
lamports: stored_account.lamports(),
owner: stored_account.owner(),
data_len: stored_account.data_len() as usize,
executable: stored_account.executable(),
rent_epoch: stored_account.rent_epoch(),
};
callback(account);
})
}

/// Iterate over all accounts and call `callback` with each account.
///
/// Prefer scan_accounts_without_data() when account data is not needed,
/// as it can potentially read less and be faster.
pub fn scan_accounts(&self, mut callback: impl for<'local> FnMut(StoredAccountInfo<'local>)) {
self.scan_accounts_stored_meta(|stored_account_meta| {
let account = StoredAccountInfo {
Expand Down
29 changes: 28 additions & 1 deletion accounts-db/src/tiered_storage/readable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use {
crate::{
account_storage::{meta::StoredAccountMeta, stored_account_info::StoredAccountInfo},
account_storage::{
meta::StoredAccountMeta,
stored_account_info::{StoredAccountInfo, StoredAccountInfoWithoutData},
},
accounts_file::MatchAccountOwnerError,
append_vec::{IndexInfo, IndexInfoInner},
tiered_storage::{
Expand Down Expand Up @@ -168,6 +171,30 @@ impl TieredStorageReader {
}

/// Iterate over all accounts and call `callback` with each account.
///
/// Note that account data is not read/passed to the callback.
pub fn scan_accounts_without_data(
&self,
mut callback: impl for<'local> FnMut(StoredAccountInfoWithoutData<'local>),
) -> TieredStorageResult<()> {
// Note, this should be reimplemented to not read account data
self.scan_accounts(|stored_account| {
Copy link
Author

Choose a reason for hiding this comment

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

We can fix this Tiered Storage implementation later when we need to. I didn't think it was necessary for this PR though.

let account = StoredAccountInfoWithoutData {
pubkey: stored_account.pubkey(),
lamports: stored_account.lamports(),
owner: stored_account.owner(),
data_len: stored_account.data().len(),
executable: stored_account.executable(),
rent_epoch: stored_account.rent_epoch(),
};
callback(account);
})
}

/// Iterate over all accounts and call `callback` with each account.
///
/// Prefer scan_accounts_without_data() when account data is not needed,
/// as it can potentially read less and be faster.
pub fn scan_accounts(
&self,
mut callback: impl for<'local> FnMut(StoredAccountInfo<'local>),
Expand Down
Loading