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] Make IndexOffset use u32 #34152

Merged
merged 1 commit into from
Nov 20, 2023
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
8 changes: 6 additions & 2 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,14 @@ pub mod tests {

let hot_storage = HotStorageReader::new_from_path(&path).unwrap();
for (i, index_writer_entry) in index_writer_entries.iter().enumerate() {
let account_offset = hot_storage.get_account_offset(IndexOffset(i)).unwrap();
let account_offset = hot_storage
.get_account_offset(IndexOffset(i as u32))
.unwrap();
assert_eq!(account_offset.block as u32, index_writer_entry.block_offset);

let account_address = hot_storage.get_account_address(IndexOffset(i)).unwrap();
let account_address = hot_storage
.get_account_address(IndexOffset(i as u32))
.unwrap();
assert_eq!(account_address, index_writer_entry.address);
}
}
Expand Down
11 changes: 6 additions & 5 deletions accounts-db/src/tiered_storage/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct AccountOffset {
/// This can be used to obtain the AccountOffset and address by looking through
/// the accounts index block.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct IndexOffset(pub usize);
pub struct IndexOffset(pub u32);

/// The index format of a tiered accounts file.
#[repr(u16)]
Expand Down Expand Up @@ -84,7 +84,8 @@ impl IndexBlockFormat {
) -> TieredStorageResult<&'a Pubkey> {
let account_offset = match self {
Self::AddressAndBlockOffsetOnly => {
footer.index_block_offset as usize + std::mem::size_of::<Pubkey>() * index_offset.0
footer.index_block_offset as usize
+ std::mem::size_of::<Pubkey>() * (index_offset.0 as usize)
}
};
let (address, _) = get_type::<Pubkey>(mmap, account_offset)?;
Expand All @@ -102,7 +103,7 @@ impl IndexBlockFormat {
Self::AddressAndBlockOffsetOnly => {
let account_offset = footer.index_block_offset as usize
+ std::mem::size_of::<Pubkey>() * footer.account_entry_count as usize
+ index_offset.0 * std::mem::size_of::<u32>();
+ std::mem::size_of::<u32>() * index_offset.0 as usize;
let (block_offset, _) = get_type::<u32>(mmap, account_offset)?;

Ok(AccountOffset {
Expand Down Expand Up @@ -166,11 +167,11 @@ mod tests {
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
for (i, index_entry) in index_entries.iter().enumerate() {
let account_offset = indexer
.get_account_offset(&mmap, &footer, IndexOffset(i))
.get_account_offset(&mmap, &footer, IndexOffset(i as u32))
.unwrap();
assert_eq!(index_entry.block_offset, account_offset.block as u32);
let address = indexer
.get_account_address(&mmap, &footer, IndexOffset(i))
.get_account_address(&mmap, &footer, IndexOffset(i as u32))
.unwrap();
assert_eq!(index_entry.address, address);
}
Expand Down