[TieredStorage] Define OwnerOffset as u32 (#34105)
#### Problem The current OwnerOffset is defined as usize, which actual size could be u32 or u64. On the other hand, the OwnerOffset is used to access the ith owner in one TieredStorageFile. As a result, u32 is more than enough to represent the number of owners inside one TieredStorageFile while u16 might not be always enough. #### Summary of Changes This PR defines OwnerOffset as u32. #### Test Plan Existing test cases.
This commit is contained in:
parent
3081b4378d
commit
f59887077a
|
@ -571,7 +571,9 @@ pub mod tests {
|
|||
let hot_storage = HotStorageReader::new_from_path(&path).unwrap();
|
||||
for (i, address) in addresses.iter().enumerate() {
|
||||
assert_eq!(
|
||||
hot_storage.get_owner_address(OwnerOffset(i)).unwrap(),
|
||||
hot_storage
|
||||
.get_owner_address(OwnerOffset(i as u32))
|
||||
.unwrap(),
|
||||
address,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,11 @@ pub struct OwnersBlock;
|
|||
|
||||
/// The offset to an owner entry in the owners block.
|
||||
/// This is used to obtain the address of the account owner.
|
||||
///
|
||||
/// Note that as its internal type is u32, it means the maximum number of
|
||||
/// unique owners in one TieredStorageFile is 2^32.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct OwnerOffset(pub usize);
|
||||
pub struct OwnerOffset(pub u32);
|
||||
|
||||
/// OwnersBlock is persisted as a consecutive bytes of pubkeys without any
|
||||
/// meta-data. For each account meta, it has a owner_offset field to
|
||||
|
@ -42,8 +45,8 @@ impl OwnersBlock {
|
|||
footer: &TieredStorageFooter,
|
||||
owner_offset: OwnerOffset,
|
||||
) -> TieredStorageResult<&'a Pubkey> {
|
||||
let offset =
|
||||
footer.owners_block_offset as usize + (std::mem::size_of::<Pubkey>() * owner_offset.0);
|
||||
let offset = footer.owners_block_offset as usize
|
||||
+ (std::mem::size_of::<Pubkey>() * owner_offset.0 as usize);
|
||||
let (pubkey, _) = get_type::<Pubkey>(mmap, offset)?;
|
||||
|
||||
Ok(pubkey)
|
||||
|
@ -90,7 +93,7 @@ mod tests {
|
|||
|
||||
for (i, address) in addresses.iter().enumerate() {
|
||||
assert_eq!(
|
||||
OwnersBlock::get_owner_address(&mmap, &footer, OwnerOffset(i)).unwrap(),
|
||||
OwnersBlock::get_owner_address(&mmap, &footer, OwnerOffset(i as u32)).unwrap(),
|
||||
address
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue