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

[TieredStorage] Use IndexOffset in TieredStorageMeta and get_account() #35046

Merged
merged 1 commit into from
Feb 2, 2024
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
2 changes: 1 addition & 1 deletion accounts-db/src/account_storage/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<'storage> StoredAccountMeta<'storage> {
pub fn offset(&self) -> usize {
match self {
Self::AppendVec(av) => av.offset(),
Self::Hot(hot) => hot.index(),
Self::Hot(hot) => hot.index().0 as usize,
}
}

Expand Down
10 changes: 5 additions & 5 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl HotStorageReader {
pub fn get_account(
&self,
index_offset: IndexOffset,
) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, usize)>> {
) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, IndexOffset)>> {
if index_offset.0 >= self.footer.account_entry_count {
return Ok(None);
}
Expand All @@ -452,10 +452,10 @@ impl HotStorageReader {
meta,
address,
owner,
index: index_offset.0 as usize,
index: index_offset,
account_block,
}),
index_offset.0.saturating_add(1) as usize,
IndexOffset(index_offset.0.saturating_add(1)),
)))
}
}
Expand Down Expand Up @@ -1244,7 +1244,7 @@ pub mod tests {
);
assert_eq!(*stored_meta.pubkey(), addresses[i]);

assert_eq!(i + 1, next);
assert_eq!(i + 1, next.0 as usize);
}
// Make sure it returns None on NUM_ACCOUNTS to allow termination on
// while loop in actual accounts-db read case.
Expand Down Expand Up @@ -1383,7 +1383,7 @@ pub mod tests {
let (account, address, account_hash, _write_version) = storable_accounts.get(i);
verify_account(&stored_meta, account, address, account_hash);

assert_eq!(i + 1, next);
assert_eq!(i + 1, next.0 as usize);
}
// Make sure it returns None on NUM_ACCOUNTS to allow termination on
// while loop in actual accounts-db read case.
Expand Down
14 changes: 7 additions & 7 deletions accounts-db/src/tiered_storage/readable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct TieredReadableAccount<'accounts_file, M: TieredAccountMeta> {
/// The address of the account owner
pub owner: &'accounts_file Pubkey,
/// The index for accessing the account inside its belonging AccountsFile
pub index: usize,
pub index: IndexOffset,
/// The account block that contains this account. Note that this account
/// block may be shared with other accounts.
pub account_block: &'accounts_file [u8],
Expand All @@ -43,7 +43,7 @@ impl<'accounts_file, M: TieredAccountMeta> TieredReadableAccount<'accounts_file,
}

/// Returns the index to this account in its AccountsFile.
pub fn index(&self) -> usize {
pub fn index(&self) -> IndexOffset {
self.index
}

Expand Down Expand Up @@ -118,10 +118,10 @@ impl TieredStorageReader {
/// Returns the account located at the specified index offset.
pub fn get_account(
&self,
index_offset: u32,
) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, usize)>> {
index_offset: IndexOffset,
) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, IndexOffset)>> {
match self {
Self::Hot(hot) => hot.get_account(IndexOffset(index_offset)),
Self::Hot(hot) => hot.get_account(index_offset),
}
}

Expand All @@ -136,13 +136,13 @@ impl TieredStorageReader {
/// causes a data overrun.
pub fn account_matches_owners(
&self,
index_offset: u32,
index_offset: IndexOffset,
owners: &[Pubkey],
) -> Result<usize, MatchAccountOwnerError> {
match self {
Self::Hot(hot) => {
let account_offset = hot
.get_account_offset(IndexOffset(index_offset))
.get_account_offset(index_offset)
.map_err(|_| MatchAccountOwnerError::UnableToLoad)?;
hot.account_matches_owners(account_offset, owners)
}
Expand Down
Loading