From e37b602bda0dbe739922860e2a3d6e9654113c5e Mon Sep 17 00:00:00 2001 From: brooks Date: Tue, 12 Dec 2023 10:52:21 -0500 Subject: [PATCH] Derives Pod for tiered storage types --- accounts-db/src/tiered_storage/footer.rs | 3 +++ accounts-db/src/tiered_storage/hot.rs | 16 +++++++++++++--- accounts-db/src/tiered_storage/index.rs | 14 +++++++++++--- accounts-db/src/tiered_storage/meta.rs | 6 +++++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/accounts-db/src/tiered_storage/footer.rs b/accounts-db/src/tiered_storage/footer.rs index 8bf9b5f228c3e3..f7b885e1af5801 100644 --- a/accounts-db/src/tiered_storage/footer.rs +++ b/accounts-db/src/tiered_storage/footer.rs @@ -29,6 +29,9 @@ pub const FOOTER_MAGIC_NUMBER: u64 = 0x502A2AB5; // SOLALABS -> SOLANA LABS #[repr(C)] pub struct TieredStorageMagicNumber(pub u64); +// Ensure there are no implicit padding bytes +const _: () = assert!(std::mem::size_of::() == 8); + impl Default for TieredStorageMagicNumber { fn default() -> Self { Self(FOOTER_MAGIC_NUMBER) diff --git a/accounts-db/src/tiered_storage/hot.rs b/accounts-db/src/tiered_storage/hot.rs index e365b638dff3f3..2b273c19a19f42 100644 --- a/accounts-db/src/tiered_storage/hot.rs +++ b/accounts-db/src/tiered_storage/hot.rs @@ -15,6 +15,7 @@ use { TieredStorageError, TieredStorageFormat, TieredStorageResult, }, }, + bytemuck::{Pod, Zeroable}, memmap2::{Mmap, MmapOptions}, modular_bitfield::prelude::*, solana_sdk::{pubkey::Pubkey, stake_history::Epoch}, @@ -45,7 +46,7 @@ const MAX_HOT_ACCOUNT_OFFSET: usize = u32::MAX as usize * HOT_ACCOUNT_OFFSET_ALI #[bitfield(bits = 32)] #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Pod, Zeroable)] struct HotMetaPackedFields { /// A hot account entry consists of the following elements: /// @@ -61,11 +62,17 @@ struct HotMetaPackedFields { owner_offset: B29, } +// Ensure there are no implicit padding bytes +const _: () = assert!(std::mem::size_of::() == 4); + /// The offset to access a hot account. #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Pod, Zeroable)] pub struct HotAccountOffset(u32); +// Ensure there are no implicit padding bytes +const _: () = assert!(std::mem::size_of::() == 4); + impl AccountOffset for HotAccountOffset {} impl HotAccountOffset { @@ -99,7 +106,7 @@ impl HotAccountOffset { /// The storage and in-memory representation of the metadata entry for a /// hot account. -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Pod, Zeroable)] #[repr(C)] pub struct HotAccountMeta { /// The balance of this account. @@ -110,6 +117,9 @@ pub struct HotAccountMeta { flags: AccountMetaFlags, } +// Ensure there are no implicit padding bytes +const _: () = assert!(std::mem::size_of::() == 8 + 4 + 4); + impl TieredAccountMeta for HotAccountMeta { /// Construct a HotAccountMeta instance. fn new() -> Self { diff --git a/accounts-db/src/tiered_storage/index.rs b/accounts-db/src/tiered_storage/index.rs index 0921bf6259cead..e9003fd19ff348 100644 --- a/accounts-db/src/tiered_storage/index.rs +++ b/accounts-db/src/tiered_storage/index.rs @@ -3,6 +3,7 @@ use { file::TieredStorageFile, footer::TieredStorageFooter, mmap_utils::get_type, TieredStorageResult, }, + bytemuck::{Pod, Zeroable}, memmap2::Mmap, solana_sdk::pubkey::Pubkey, }; @@ -17,14 +18,18 @@ pub struct AccountIndexWriterEntry<'a, Offset: AccountOffset> { } /// The offset to an account. -pub trait AccountOffset {} +pub trait AccountOffset: Clone + Copy + Pod + Zeroable {} /// The offset to an account/address entry in the accounts index block. /// This can be used to obtain the AccountOffset and address by looking through /// the accounts index block. -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[repr(C)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Pod, Zeroable)] pub struct IndexOffset(pub u32); +// Ensure there are no implicit padding bytes +const _: () = assert!(std::mem::size_of::() == 4); + /// The index format of a tiered accounts file. #[repr(u16)] #[derive( @@ -46,6 +51,9 @@ pub enum IndexBlockFormat { AddressAndBlockOffsetOnly = 0, } +// Ensure there are no implicit padding bytes +const _: () = assert!(std::mem::size_of::() == 2); + impl IndexBlockFormat { /// Persists the specified index_entries to the specified file and returns /// the total number of bytes written. @@ -86,7 +94,7 @@ impl IndexBlockFormat { } /// Returns the offset to the account given the specified index. - pub fn get_account_offset( + pub fn get_account_offset( &self, mmap: &Mmap, footer: &TieredStorageFooter, diff --git a/accounts-db/src/tiered_storage/meta.rs b/accounts-db/src/tiered_storage/meta.rs index 0111902fb8369d..134b094bf66f1f 100644 --- a/accounts-db/src/tiered_storage/meta.rs +++ b/accounts-db/src/tiered_storage/meta.rs @@ -2,6 +2,7 @@ use { crate::{accounts_hash::AccountHash, tiered_storage::owners::OwnerOffset}, + bytemuck::{Pod, Zeroable}, modular_bitfield::prelude::*, solana_sdk::stake_history::Epoch, }; @@ -9,7 +10,7 @@ use { /// The struct that handles the account meta flags. #[bitfield(bits = 32)] #[repr(C)] -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Pod, Zeroable)] pub struct AccountMetaFlags { /// whether the account meta has rent epoch pub has_rent_epoch: bool, @@ -19,6 +20,9 @@ pub struct AccountMetaFlags { reserved: B30, } +// Ensure there are no implicit padding bytes +const _: () = assert!(std::mem::size_of::() == 4); + /// A trait that allows different implementations of the account meta that /// support different tiers of the accounts storage. pub trait TieredAccountMeta: Sized {