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

#### Problem
TieredStorageMeta and TieredStorageReader::get_account API uses
u32 to represent IndexOffset.  However, within the TieredStorage scope,
IndexOffset should be used, it is not until working with AccountsFile API
when u32 representation of offset is needed.

#### Summary of Changes
Have TieredStorageMeta and TieredStorageReader to use IndexOffset.

#### Test Plan
Existing unit-tests.
This commit is contained in:
Yueh-Hsuan Chiang 2024-02-02 09:53:13 -08:00 committed by GitHub
parent 9c595bca54
commit 97d994ee6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 13 deletions

View File

@ -142,7 +142,7 @@ impl<'storage> StoredAccountMeta<'storage> {
pub fn offset(&self) -> usize { pub fn offset(&self) -> usize {
match self { match self {
Self::AppendVec(av) => av.offset(), Self::AppendVec(av) => av.offset(),
Self::Hot(hot) => hot.index(), Self::Hot(hot) => hot.index().0 as usize,
} }
} }

View File

@ -435,7 +435,7 @@ impl HotStorageReader {
pub fn get_account( pub fn get_account(
&self, &self,
index_offset: IndexOffset, index_offset: IndexOffset,
) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, usize)>> { ) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, IndexOffset)>> {
if index_offset.0 >= self.footer.account_entry_count { if index_offset.0 >= self.footer.account_entry_count {
return Ok(None); return Ok(None);
} }
@ -452,10 +452,10 @@ impl HotStorageReader {
meta, meta,
address, address,
owner, owner,
index: index_offset.0 as usize, index: index_offset,
account_block, account_block,
}), }),
index_offset.0.saturating_add(1) as usize, IndexOffset(index_offset.0.saturating_add(1)),
))) )))
} }
} }
@ -1244,7 +1244,7 @@ pub mod tests {
); );
assert_eq!(*stored_meta.pubkey(), addresses[i]); 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 // Make sure it returns None on NUM_ACCOUNTS to allow termination on
// while loop in actual accounts-db read case. // while loop in actual accounts-db read case.
@ -1383,7 +1383,7 @@ pub mod tests {
let (account, address, account_hash, _write_version) = storable_accounts.get(i); let (account, address, account_hash, _write_version) = storable_accounts.get(i);
verify_account(&stored_meta, account, address, account_hash); 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 // Make sure it returns None on NUM_ACCOUNTS to allow termination on
// while loop in actual accounts-db read case. // while loop in actual accounts-db read case.

View File

@ -25,7 +25,7 @@ pub struct TieredReadableAccount<'accounts_file, M: TieredAccountMeta> {
/// The address of the account owner /// The address of the account owner
pub owner: &'accounts_file Pubkey, pub owner: &'accounts_file Pubkey,
/// The index for accessing the account inside its belonging AccountsFile /// 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 /// The account block that contains this account. Note that this account
/// block may be shared with other accounts. /// block may be shared with other accounts.
pub account_block: &'accounts_file [u8], pub account_block: &'accounts_file [u8],
@ -43,7 +43,7 @@ impl<'accounts_file, M: TieredAccountMeta> TieredReadableAccount<'accounts_file,
} }
/// Returns the index to this account in its AccountsFile. /// Returns the index to this account in its AccountsFile.
pub fn index(&self) -> usize { pub fn index(&self) -> IndexOffset {
self.index self.index
} }
@ -118,10 +118,10 @@ impl TieredStorageReader {
/// Returns the account located at the specified index offset. /// Returns the account located at the specified index offset.
pub fn get_account( pub fn get_account(
&self, &self,
index_offset: u32, index_offset: IndexOffset,
) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, usize)>> { ) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, IndexOffset)>> {
match self { match self {
Self::Hot(hot) => hot.get_account(IndexOffset(index_offset)), Self::Hot(hot) => hot.get_account(index_offset),
} }
} }
@ -136,13 +136,13 @@ impl TieredStorageReader {
/// causes a data overrun. /// causes a data overrun.
pub fn account_matches_owners( pub fn account_matches_owners(
&self, &self,
index_offset: u32, index_offset: IndexOffset,
owners: &[Pubkey], owners: &[Pubkey],
) -> Result<usize, MatchAccountOwnerError> { ) -> Result<usize, MatchAccountOwnerError> {
match self { match self {
Self::Hot(hot) => { Self::Hot(hot) => {
let account_offset = hot let account_offset = hot
.get_account_offset(IndexOffset(index_offset)) .get_account_offset(index_offset)
.map_err(|_| MatchAccountOwnerError::UnableToLoad)?; .map_err(|_| MatchAccountOwnerError::UnableToLoad)?;
hot.account_matches_owners(account_offset, owners) hot.account_matches_owners(account_offset, owners)
} }