Skip to content

Commit

Permalink
[TieredStorage] Implement HotStorageReader::accounts()
Browse files Browse the repository at this point in the history
  • Loading branch information
yhchiang-sol committed Feb 1, 2024
1 parent b4e3acf commit 7b7b59f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,20 @@ impl HotStorageReader {
index_offset.0.saturating_add(1) as usize,
)))
}

/// Return a vector of account metadata for each account, starting from
/// `index_offset`
pub fn accounts(
&self,
mut index_offset: IndexOffset,
) -> TieredStorageResult<Vec<StoredAccountMeta>> {
let mut accounts = vec![];
while let Some((account, next)) = self.get_account(index_offset)? {
accounts.push(account);
index_offset = IndexOffset(next as u32);
}
Ok(accounts)
}
}

fn write_optional_fields(
Expand Down Expand Up @@ -1403,5 +1417,21 @@ pub mod tests {
storable_accounts.get(stored_info.offset);
verify_account(&stored_meta, account, address, account_hash);
}

// verify get_accounts
let accounts = hot_storage.accounts(IndexOffset(0)).unwrap();

// first, we verify everything
for (i, stored_meta) in accounts.iter().enumerate() {
let (account, address, account_hash, _write_version) = storable_accounts.get(i);
verify_account(&stored_meta, account, address, account_hash);
}

// second, we verify various initial position
let total_stored_accounts = accounts.len();
for i in 0..total_stored_accounts {
let partial_accounts = hot_storage.accounts(IndexOffset(i as u32)).unwrap();
assert_eq!(&partial_accounts, &accounts[i..]);
}
}
}
13 changes: 13 additions & 0 deletions accounts-db/src/tiered_storage/readable.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use {
crate::{
account_storage::meta::StoredAccountMeta,
accounts_hash::AccountHash,
tiered_storage::{
footer::{AccountMetaFormat, TieredStorageFooter},
hot::HotStorageReader,
index::IndexOffset,
meta::TieredAccountMeta,
TieredStorageResult,
},
Expand Down Expand Up @@ -111,4 +113,15 @@ impl TieredStorageReader {
Self::Hot(hot) => hot.num_accounts(),
}
}

/// Return a vector of account metadata for each account, starting from
/// `index_offset`
pub fn accounts(
&self,
index_offset: IndexOffset,
) -> TieredStorageResult<Vec<StoredAccountMeta>> {
match self {
Self::Hot(hot) => hot.accounts(index_offset),
}
}
}

0 comments on commit 7b7b59f

Please sign in to comment.