Derives Pod for tiered storage types (#34414)

This commit is contained in:
Brooks 2023-12-12 14:59:51 -05:00 committed by GitHub
parent 636992b51e
commit a2d7be0d07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 7 deletions

View File

@ -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)

View File

@ -15,6 +15,7 @@ use {
TieredStorageError, TieredStorageFormat, TieredStorageResult,
},
},
bytemuck::{Pod, Zeroable},
memmap2::{Mmap, MmapOptions},
modular_bitfield::prelude::*,
solana_sdk::{pubkey::Pubkey, stake_history::Epoch},
@ -47,7 +48,7 @@ const MAX_HOT_ACCOUNT_OFFSET: usize = u32::MAX as usize * HOT_ACCOUNT_ALIGNMENT;
#[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:
///
@ -63,11 +64,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 {
@ -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::<HotAccountMeta>() == 8 + 4 + 4);
impl TieredAccountMeta for HotAccountMeta {
/// Construct a HotAccountMeta instance.
fn new() -> Self {

View File

@ -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::<IndexOffset>() == 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::<IndexBlockFormat>() == 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<Offset: AccountOffset + Copy>(
pub fn get_account_offset<Offset: AccountOffset>(
&self,
mmap: &Mmap,
footer: &TieredStorageFooter,

View File

@ -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::<AccountMetaFlags>() == 4);
/// A trait that allows different implementations of the account meta that
/// support different tiers of the accounts storage.
pub trait TieredAccountMeta: Sized {