Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

[TieredStorage] Make IndexBlock persist u32 offsets #34133

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ pub mod tests {
.iter()
.map(|address| AccountIndexWriterEntry {
address,
block_offset: rng.gen_range(0..u64::MAX),
block_offset: rng.gen_range(0..u32::MAX),
intra_block_offset: rng.gen_range(0..4096),
})
.collect();
Expand Down Expand Up @@ -532,7 +532,7 @@ 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();
assert_eq!(account_offset.block as u64, index_writer_entry.block_offset);
assert_eq!(account_offset.block as u32, index_writer_entry.block_offset);

let account_address = hot_storage.get_account_address(IndexOffset(i)).unwrap();
assert_eq!(account_address, index_writer_entry.address);
Expand Down
29 changes: 22 additions & 7 deletions accounts-db/src/tiered_storage/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
TieredStorageResult,
},
memmap2::Mmap,
modular_bitfield::prelude::*,
solana_sdk::pubkey::Pubkey,
};

Expand All @@ -13,8 +14,17 @@ use {
#[derive(Debug)]
pub struct AccountIndexWriterEntry<'a> {
pub address: &'a Pubkey,
pub block_offset: u64,
pub intra_block_offset: u64,
pub block_offset: u32,
pub intra_block_offset: u32,
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
}

/// A struct that stores two u32 offset pair.
#[bitfield(bits = 64)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
struct PackedOffsetPair {
first_offset: u32,
second_offset: u32,
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
}

/// The offset to an account stored inside its accounts block.
Expand Down Expand Up @@ -102,10 +112,15 @@ impl IndexBlockFormat {
Self::AddressAndOffset => {
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::<u64>();
let (account_block_offset, _) = get_type(mmap, account_offset)?;
+ (index_offset.0 >> 1) * std::mem::size_of::<PackedOffsetPair>();
let (packed_offset, _) = get_type::<PackedOffsetPair>(mmap, account_offset)?;

Ok(AccountOffset {
block: *account_block_offset,
block: if index_offset.0 & 1 == 0 {
packed_offset.first_offset()
} else {
packed_offset.second_offset()
} as usize,
})
}
}
Expand All @@ -114,7 +129,7 @@ impl IndexBlockFormat {
/// Returns the size of one index entry.
pub fn entry_size(&self) -> usize {
match self {
Self::AddressAndOffset => std::mem::size_of::<Pubkey>() + std::mem::size_of::<u64>(),
Self::AddressAndOffset => std::mem::size_of::<Pubkey>() + std::mem::size_of::<u32>(),
}
}
}
Expand Down Expand Up @@ -165,7 +180,7 @@ mod tests {
let account_offset = indexer
.get_account_offset(&mmap, &footer, IndexOffset(i))
.unwrap();
assert_eq!(index_entry.block_offset, account_offset.block as u64);
assert_eq!(index_entry.block_offset, account_offset.block as u32);
let address = indexer
.get_account_address(&mmap, &footer, IndexOffset(i))
.unwrap();
Expand Down