Skip to content

Commit

Permalink
Derives Pod for tiered storage types
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Dec 12, 2023
1 parent 39a3566 commit e37b602
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions accounts-db/src/tiered_storage/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TieredStorageMagicNumber>() == 8);

impl Default for TieredStorageMagicNumber {
fn default() -> Self {
Self(FOOTER_MAGIC_NUMBER)
Expand Down
16 changes: 13 additions & 3 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use {
TieredStorageError, TieredStorageFormat, TieredStorageResult,
},
},
bytemuck::{Pod, Zeroable},
memmap2::{Mmap, MmapOptions},
modular_bitfield::prelude::*,
solana_sdk::{pubkey::Pubkey, stake_history::Epoch},
Expand Down Expand Up @@ -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:
///
Expand All @@ -61,11 +62,17 @@ struct HotMetaPackedFields {
owner_offset: B29,
}

// Ensure there are no implicit padding bytes
const _: () = assert!(std::mem::size_of::<HotMetaPackedFields>() == 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::<HotAccountOffset>() == 4);

impl AccountOffset for HotAccountOffset {}

impl HotAccountOffset {
Expand Down Expand Up @@ -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.
Expand All @@ -110,6 +117,9 @@ pub struct HotAccountMeta {
flags: AccountMetaFlags,
}

// Ensure there are no implicit padding bytes
const _: () = assert!(std::mem::size_of::<HotAccountMeta>() == 8 + 4 + 4);

impl TieredAccountMeta for HotAccountMeta {
/// Construct a HotAccountMeta instance.
fn new() -> Self {
Expand Down
14 changes: 11 additions & 3 deletions accounts-db/src/tiered_storage/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
file::TieredStorageFile, footer::TieredStorageFooter, mmap_utils::get_type,
TieredStorageResult,
},
bytemuck::{Pod, Zeroable},
memmap2::Mmap,
solana_sdk::pubkey::Pubkey,
};
Expand All @@ -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::<IndexOffset>() == 4);

/// The index format of a tiered accounts file.
#[repr(u16)]
#[derive(
Expand All @@ -46,6 +51,9 @@ pub enum IndexBlockFormat {
AddressAndBlockOffsetOnly = 0,
}

// Ensure there are no implicit padding bytes
const _: () = assert!(std::mem::size_of::<IndexBlockFormat>() == 2);

impl IndexBlockFormat {
/// Persists the specified index_entries to the specified file and returns
/// the total number of bytes written.
Expand Down Expand Up @@ -86,7 +94,7 @@ impl IndexBlockFormat {
}

/// Returns the offset to the account given the specified index.
pub fn get_account_offset<Offset: AccountOffset + Copy>(
pub fn get_account_offset<Offset: AccountOffset>(
&self,
mmap: &Mmap,
footer: &TieredStorageFooter,
Expand Down
6 changes: 5 additions & 1 deletion accounts-db/src/tiered_storage/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
use {
crate::{accounts_hash::AccountHash, tiered_storage::owners::OwnerOffset},
bytemuck::{Pod, Zeroable},
modular_bitfield::prelude::*,
solana_sdk::stake_history::Epoch,
};

/// 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,
Expand All @@ -19,6 +20,9 @@ pub struct AccountMetaFlags {
reserved: B30,
}

// Ensure there are no implicit padding bytes
const _: () = assert!(std::mem::size_of::<AccountMetaFlags>() == 4);

/// A trait that allows different implementations of the account meta that
/// support different tiers of the accounts storage.
pub trait TieredAccountMeta: Sized {
Expand Down

0 comments on commit e37b602

Please sign in to comment.