From 6624a09d381dde44bc6abf06e2145fc25586631e Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang <93241502+yhchiang-sol@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:32:19 -0800 Subject: [PATCH] [TieredStorage] Rename account-index to index-block (#33928) #### 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. --- accounts-db/src/tiered_storage.rs | 8 ++++---- accounts-db/src/tiered_storage/footer.rs | 18 +++++++++--------- accounts-db/src/tiered_storage/hot.rs | 10 +++++----- accounts-db/src/tiered_storage/index.rs | 12 ++++++------ accounts-db/src/tiered_storage/writer.rs | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/accounts-db/src/tiered_storage.rs b/accounts-db/src/tiered_storage.rs index 6a9f0193f..829b0cb03 100644 --- a/accounts-db/src/tiered_storage.rs +++ b/accounts-db/src/tiered_storage.rs @@ -19,7 +19,7 @@ use { }, error::TieredStorageError, footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat}, - index::AccountIndexFormat, + index::IndexBlockFormat, readable::TieredStorageReader, solana_sdk::account::ReadableAccount, std::{ @@ -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, } @@ -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, @@ -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 diff --git a/accounts-db/src/tiered_storage/footer.rs b/accounts-db/src/tiered_storage/footer.rs index c88d665c4..7763d8d56 100644 --- a/accounts-db/src/tiered_storage/footer.rs +++ b/accounts-db/src/tiered_storage/footer.rs @@ -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, @@ -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, @@ -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, @@ -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(), @@ -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(), @@ -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!( @@ -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); diff --git a/accounts-db/src/tiered_storage/hot.rs b/accounts-db/src/tiered_storage/hot.rs index 782717006..9e987f886 100644 --- a/accounts-db/src/tiered_storage/hot.rs +++ b/accounts-db/src/tiered_storage/hot.rs @@ -9,7 +9,7 @@ use { footer::{ AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat, TieredStorageFooter, }, - index::AccountIndexFormat, + index::IndexBlockFormat, meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta}, mmap_utils::get_type, TieredStorageFormat, TieredStorageResult, @@ -25,7 +25,7 @@ pub const HOT_FORMAT: TieredStorageFormat = TieredStorageFormat { meta_entry_size: std::mem::size_of::(), 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, }; @@ -241,7 +241,7 @@ pub mod tests { FOOTER_SIZE, }, hot::{HotAccountMeta, HotStorageReader}, - index::AccountIndexFormat, + index::IndexBlockFormat, meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta}, }, memoffset::offset_of, @@ -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(), diff --git a/accounts-db/src/tiered_storage/index.rs b/accounts-db/src/tiered_storage/index.rs index 656343fb7..ad66f3c74 100644 --- a/accounts-db/src/tiered_storage/index.rs +++ b/accounts-db/src/tiered_storage/index.rs @@ -30,7 +30,7 @@ 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. @@ -38,7 +38,7 @@ pub enum AccountIndexFormat { 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( @@ -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::() * index + footer.index_block_offset as usize + std::mem::size_of::() * index } }; let (address, _) = get_type::(map, offset)?; @@ -86,7 +86,7 @@ impl AccountIndexFormat { ) -> TieredStorageResult { match self { Self::AddressAndOffset => { - let offset = footer.account_index_offset as usize + let offset = footer.index_block_offset as usize + std::mem::size_of::() * footer.account_entry_count as usize + index * std::mem::size_of::(); let (account_block_offset, _) = get_type(map, offset)?; @@ -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) diff --git a/accounts-db/src/tiered_storage/writer.rs b/accounts-db/src/tiered_storage/writer.rs index dece0e427..113d331e4 100644 --- a/accounts-db/src/tiered_storage/writer.rs +++ b/accounts-db/src/tiered_storage/writer.rs @@ -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()