Skip to content

Commit

Permalink
[TieredStorage] Rename account-index to index-block (solana-labs#33928)
Browse files Browse the repository at this point in the history
#### Problem
The current tiered-storage code uses "account-index" to call index-block.
This could lead to confusion especially as we start giving each offset/position/index a specific type.

#### Summary of Changes
This PR renames all structs/variables that use account-index to refer to index-block.
  • Loading branch information
yhchiang-sol authored Nov 6, 2023
1 parent d6ac9be commit 6624a09
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions accounts-db/src/tiered_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use {
},
error::TieredStorageError,
footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat},
index::AccountIndexFormat,
index::IndexBlockFormat,
readable::TieredStorageReader,
solana_sdk::account::ReadableAccount,
std::{
Expand All @@ -40,7 +40,7 @@ pub struct TieredStorageFormat {
pub meta_entry_size: usize,
pub account_meta_format: AccountMetaFormat,
pub owners_block_format: OwnersBlockFormat,
pub account_index_format: AccountIndexFormat,
pub index_block_format: IndexBlockFormat,
pub account_block_format: AccountBlockFormat,
}

Expand Down Expand Up @@ -236,7 +236,7 @@ mod tests {
assert_eq!(tiered_storage_readonly.reader().unwrap().num_accounts(), 0);
assert_eq!(footer.account_meta_format, HOT_FORMAT.account_meta_format);
assert_eq!(footer.owners_block_format, HOT_FORMAT.owners_block_format);
assert_eq!(footer.account_index_format, HOT_FORMAT.account_index_format);
assert_eq!(footer.index_block_format, HOT_FORMAT.index_block_format);
assert_eq!(footer.account_block_format, HOT_FORMAT.account_block_format);
assert_eq!(
tiered_storage_readonly.file_size().unwrap() as usize,
Expand Down Expand Up @@ -379,7 +379,7 @@ mod tests {
let expected_footer = TieredStorageFooter {
account_meta_format: expected_format.account_meta_format,
owners_block_format: expected_format.owners_block_format,
account_index_format: expected_format.account_index_format,
index_block_format: expected_format.index_block_format,
account_block_format: expected_format.account_block_format,
account_entry_count: expected_accounts.len() as u32,
// Hash is not yet implemented, so we bypass the check
Expand Down
18 changes: 9 additions & 9 deletions accounts-db/src/tiered_storage/footer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::tiered_storage::{
error::TieredStorageError, file::TieredStorageFile, index::AccountIndexFormat,
error::TieredStorageError, file::TieredStorageFile, index::IndexBlockFormat,
mmap_utils::get_type, TieredStorageResult as TsResult,
},
memmap2::Mmap,
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct TieredStorageFooter {
/// The format of the owners block.
pub owners_block_format: OwnersBlockFormat,
/// The format of the account index block.
pub account_index_format: AccountIndexFormat,
pub index_block_format: IndexBlockFormat,
/// The format of the account block.
pub account_block_format: AccountBlockFormat,

Expand All @@ -120,7 +120,7 @@ pub struct TieredStorageFooter {
// Offsets
// Note that offset to the account blocks is omitted as it's always 0.
/// The offset pointing to the first byte of the account index block.
pub account_index_offset: u64,
pub index_block_offset: u64,
/// The offset pointing to the first byte of the owners block.
pub owners_offset: u64,

Expand Down Expand Up @@ -149,14 +149,14 @@ impl Default for TieredStorageFooter {
Self {
account_meta_format: AccountMetaFormat::default(),
owners_block_format: OwnersBlockFormat::default(),
account_index_format: AccountIndexFormat::default(),
index_block_format: IndexBlockFormat::default(),
account_block_format: AccountBlockFormat::default(),
account_entry_count: 0,
account_meta_entry_size: 0,
account_block_size: 0,
owner_count: 0,
owner_entry_size: 0,
account_index_offset: 0,
index_block_offset: 0,
owners_offset: 0,
hash: Hash::new_unique(),
min_account_address: Pubkey::default(),
Expand Down Expand Up @@ -241,14 +241,14 @@ mod tests {
let expected_footer = TieredStorageFooter {
account_meta_format: AccountMetaFormat::Hot,
owners_block_format: OwnersBlockFormat::LocalIndex,
account_index_format: AccountIndexFormat::AddressAndOffset,
index_block_format: IndexBlockFormat::AddressAndOffset,
account_block_format: AccountBlockFormat::AlignedRaw,
account_entry_count: 300,
account_meta_entry_size: 24,
account_block_size: 4096,
owner_count: 250,
owner_entry_size: 32,
account_index_offset: 1069600,
index_block_offset: 1069600,
owners_offset: 1081200,
hash: Hash::new_unique(),
min_account_address: Pubkey::default(),
Expand All @@ -275,7 +275,7 @@ mod tests {
fn test_footer_layout() {
assert_eq!(offset_of!(TieredStorageFooter, account_meta_format), 0x00);
assert_eq!(offset_of!(TieredStorageFooter, owners_block_format), 0x02);
assert_eq!(offset_of!(TieredStorageFooter, account_index_format), 0x04);
assert_eq!(offset_of!(TieredStorageFooter, index_block_format), 0x04);
assert_eq!(offset_of!(TieredStorageFooter, account_block_format), 0x06);
assert_eq!(offset_of!(TieredStorageFooter, account_entry_count), 0x08);
assert_eq!(
Expand All @@ -285,7 +285,7 @@ mod tests {
assert_eq!(offset_of!(TieredStorageFooter, account_block_size), 0x10);
assert_eq!(offset_of!(TieredStorageFooter, owner_count), 0x18);
assert_eq!(offset_of!(TieredStorageFooter, owner_entry_size), 0x1C);
assert_eq!(offset_of!(TieredStorageFooter, account_index_offset), 0x20);
assert_eq!(offset_of!(TieredStorageFooter, index_block_offset), 0x20);
assert_eq!(offset_of!(TieredStorageFooter, owners_offset), 0x28);
assert_eq!(offset_of!(TieredStorageFooter, min_account_address), 0x30);
assert_eq!(offset_of!(TieredStorageFooter, max_account_address), 0x50);
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 @@ -9,7 +9,7 @@ use {
footer::{
AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat, TieredStorageFooter,
},
index::AccountIndexFormat,
index::IndexBlockFormat,
meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta},
mmap_utils::get_type,
TieredStorageFormat, TieredStorageResult,
Expand All @@ -25,7 +25,7 @@ pub const HOT_FORMAT: TieredStorageFormat = TieredStorageFormat {
meta_entry_size: std::mem::size_of::<HotAccountMeta>(),
account_meta_format: AccountMetaFormat::Hot,
owners_block_format: OwnersBlockFormat::LocalIndex,
account_index_format: AccountIndexFormat::AddressAndOffset,
index_block_format: IndexBlockFormat::AddressAndOffset,
account_block_format: AccountBlockFormat::AlignedRaw,
};

Expand Down Expand Up @@ -241,7 +241,7 @@ pub mod tests {
FOOTER_SIZE,
},
hot::{HotAccountMeta, HotStorageReader},
index::AccountIndexFormat,
index::IndexBlockFormat,
meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta},
},
memoffset::offset_of,
Expand Down Expand Up @@ -383,14 +383,14 @@ pub mod tests {
let expected_footer = TieredStorageFooter {
account_meta_format: AccountMetaFormat::Hot,
owners_block_format: OwnersBlockFormat::LocalIndex,
account_index_format: AccountIndexFormat::AddressAndOffset,
index_block_format: IndexBlockFormat::AddressAndOffset,
account_block_format: AccountBlockFormat::AlignedRaw,
account_entry_count: 300,
account_meta_entry_size: 16,
account_block_size: 4096,
owner_count: 250,
owner_entry_size: 32,
account_index_offset: 1069600,
index_block_offset: 1069600,
owners_offset: 1081200,
hash: Hash::new_unique(),
min_account_address: Pubkey::default(),
Expand Down
12 changes: 6 additions & 6 deletions accounts-db/src/tiered_storage/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ pub struct AccountIndexWriterEntry<'a> {
num_enum::IntoPrimitive,
num_enum::TryFromPrimitive,
)]
pub enum AccountIndexFormat {
pub enum IndexBlockFormat {
/// This format optimizes the storage size by storing only account addresses
/// and offsets. It skips storing the size of account data by storing account
/// block entries and index block entries in the same order.
#[default]
AddressAndOffset = 0,
}

impl AccountIndexFormat {
impl IndexBlockFormat {
/// Persists the specified index_entries to the specified file and returns
/// the total number of bytes written.
pub fn write_index_block(
Expand Down Expand Up @@ -69,7 +69,7 @@ impl AccountIndexFormat {
) -> TieredStorageResult<&'a Pubkey> {
let offset = match self {
Self::AddressAndOffset => {
footer.account_index_offset as usize + std::mem::size_of::<Pubkey>() * index
footer.index_block_offset as usize + std::mem::size_of::<Pubkey>() * index
}
};
let (address, _) = get_type::<Pubkey>(map, offset)?;
Expand All @@ -86,7 +86,7 @@ impl AccountIndexFormat {
) -> TieredStorageResult<u64> {
match self {
Self::AddressAndOffset => {
let offset = footer.account_index_offset as usize
let offset = footer.index_block_offset as usize
+ std::mem::size_of::<Pubkey>() * footer.account_entry_count as usize
+ index * std::mem::size_of::<u64>();
let (account_block_offset, _) = get_type(map, offset)?;
Expand Down Expand Up @@ -134,11 +134,11 @@ mod tests {

{
let file = TieredStorageFile::new_writable(&path).unwrap();
let indexer = AccountIndexFormat::AddressAndOffset;
let indexer = IndexBlockFormat::AddressAndOffset;
indexer.write_index_block(&file, &index_entries).unwrap();
}

let indexer = AccountIndexFormat::AddressAndOffset;
let indexer = IndexBlockFormat::AddressAndOffset;
let file = OpenOptions::new()
.read(true)
.create(false)
Expand Down
2 changes: 1 addition & 1 deletion accounts-db/src/tiered_storage/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'format> TieredStorageWriter<'format> {
account_meta_format: self.format.account_meta_format,
owners_block_format: self.format.owners_block_format,
account_block_format: self.format.account_block_format,
account_index_format: self.format.account_index_format,
index_block_format: self.format.index_block_format,
account_entry_count: accounts
.accounts
.len()
Expand Down

0 comments on commit 6624a09

Please sign in to comment.