Skip to content

Commit 44bd7c7

Browse files
authored
Adds scan_accounts_without_data() to avoid loading account data (#5849)
1 parent 7bb8e2d commit 44bd7c7

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
lines changed

accounts-db/src/accounts_db.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4941,8 +4941,7 @@ impl AccountsDb {
49414941
self.scan_cache_storage_fallback(slot, cache_map_func, |retval, storage| {
49424942
match scan_account_storage_data {
49434943
ScanAccountStorageData::NoData => {
4944-
storage.scan_accounts(|account| {
4945-
let account_without_data = StoredAccountInfoWithoutData::new_from(&account);
4944+
storage.scan_accounts_without_data(|account_without_data| {
49464945
storage_scan_func(retval, &account_without_data, None);
49474946
});
49484947
}

accounts-db/src/accounts_file.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::account_storage::meta::StoredAccountMeta;
33
use {
44
crate::{
55
account_info::AccountInfo,
6-
account_storage::stored_account_info::StoredAccountInfo,
6+
account_storage::stored_account_info::{StoredAccountInfo, StoredAccountInfoWithoutData},
77
accounts_db::AccountsFileId,
88
accounts_update_notifier_interface::AccountForGeyser,
99
append_vec::{AppendVec, AppendVecError, IndexInfo},
@@ -265,6 +265,26 @@ impl AccountsFile {
265265
}
266266

267267
/// Iterate over all accounts and call `callback` with each account.
268+
///
269+
/// Note that account data is not read/passed to the callback.
270+
pub fn scan_accounts_without_data(
271+
&self,
272+
callback: impl for<'local> FnMut(StoredAccountInfoWithoutData<'local>),
273+
) {
274+
match self {
275+
Self::AppendVec(av) => av.scan_accounts_without_data(callback),
276+
Self::TieredStorage(ts) => {
277+
if let Some(reader) = ts.reader() {
278+
_ = reader.scan_accounts_without_data(callback);
279+
}
280+
}
281+
}
282+
}
283+
284+
/// Iterate over all accounts and call `callback` with each account.
285+
///
286+
/// Prefer scan_accounts_without_data() when account data is not needed,
287+
/// as it can potentially read less and be faster.
268288
pub fn scan_accounts(&self, callback: impl for<'local> FnMut(StoredAccountInfo<'local>)) {
269289
match self {
270290
Self::AppendVec(av) => av.scan_accounts(callback),

accounts-db/src/append_vec.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
crate::{
99
account_storage::{
1010
meta::{AccountMeta, StoredAccountMeta, StoredMeta},
11-
stored_account_info::StoredAccountInfo,
11+
stored_account_info::{StoredAccountInfo, StoredAccountInfoWithoutData},
1212
},
1313
accounts_file::{
1414
AccountsFileError, InternalsForArchive, MatchAccountOwnerError, Result, StorageAccess,
@@ -1100,6 +1100,29 @@ impl AppendVec {
11001100
}
11011101

11021102
/// Iterate over all accounts and call `callback` with each account.
1103+
///
1104+
/// Note that account data is not read/passed to the callback.
1105+
pub fn scan_accounts_without_data(
1106+
&self,
1107+
mut callback: impl for<'local> FnMut(StoredAccountInfoWithoutData<'local>),
1108+
) {
1109+
self.scan_stored_accounts_no_data(|stored_account| {
1110+
let account = StoredAccountInfoWithoutData {
1111+
pubkey: stored_account.pubkey(),
1112+
lamports: stored_account.lamports(),
1113+
owner: stored_account.owner(),
1114+
data_len: stored_account.data_len() as usize,
1115+
executable: stored_account.executable(),
1116+
rent_epoch: stored_account.rent_epoch(),
1117+
};
1118+
callback(account);
1119+
})
1120+
}
1121+
1122+
/// Iterate over all accounts and call `callback` with each account.
1123+
///
1124+
/// Prefer scan_accounts_without_data() when account data is not needed,
1125+
/// as it can potentially read less and be faster.
11031126
pub fn scan_accounts(&self, mut callback: impl for<'local> FnMut(StoredAccountInfo<'local>)) {
11041127
self.scan_accounts_stored_meta(|stored_account_meta| {
11051128
let account = StoredAccountInfo {

accounts-db/src/tiered_storage/readable.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use {
22
crate::{
3-
account_storage::{meta::StoredAccountMeta, stored_account_info::StoredAccountInfo},
3+
account_storage::{
4+
meta::StoredAccountMeta,
5+
stored_account_info::{StoredAccountInfo, StoredAccountInfoWithoutData},
6+
},
47
accounts_file::MatchAccountOwnerError,
58
append_vec::{IndexInfo, IndexInfoInner},
69
tiered_storage::{
@@ -168,6 +171,30 @@ impl TieredStorageReader {
168171
}
169172

170173
/// Iterate over all accounts and call `callback` with each account.
174+
///
175+
/// Note that account data is not read/passed to the callback.
176+
pub fn scan_accounts_without_data(
177+
&self,
178+
mut callback: impl for<'local> FnMut(StoredAccountInfoWithoutData<'local>),
179+
) -> TieredStorageResult<()> {
180+
// Note, this should be reimplemented to not read account data
181+
self.scan_accounts(|stored_account| {
182+
let account = StoredAccountInfoWithoutData {
183+
pubkey: stored_account.pubkey(),
184+
lamports: stored_account.lamports(),
185+
owner: stored_account.owner(),
186+
data_len: stored_account.data().len(),
187+
executable: stored_account.executable(),
188+
rent_epoch: stored_account.rent_epoch(),
189+
};
190+
callback(account);
191+
})
192+
}
193+
194+
/// Iterate over all accounts and call `callback` with each account.
195+
///
196+
/// Prefer scan_accounts_without_data() when account data is not needed,
197+
/// as it can potentially read less and be faster.
171198
pub fn scan_accounts(
172199
&self,
173200
mut callback: impl for<'local> FnMut(StoredAccountInfo<'local>),

0 commit comments

Comments
 (0)