Move alignment related consts from append_vec.rs to accounts_file.rs (#30782)

#### Problem
As we start supporting new storage formats, alignment-related constants and macros
defined in append_vec.rs aren't only specific to AppendVec.

#### Summary of Changes
Move alignment-related constants/macros from append_vec.rs to accounts_file.rs
This commit is contained in:
Yueh-Hsuan Chiang 2023-03-20 11:34:18 -07:00 committed by GitHub
parent 9ad77485ce
commit 72c6099ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View File

@ -5,8 +5,8 @@
use {
crate::{
accounts_db::AppendVecId,
accounts_file::ALIGN_BOUNDARY_OFFSET,
accounts_index::{IsCached, ZeroLamport},
append_vec::ALIGN_BOUNDARY_OFFSET,
},
modular_bitfield::prelude::*,
};

View File

@ -9,11 +9,21 @@ use {
solana_sdk::{account::ReadableAccount, clock::Slot, hash::Hash, pubkey::Pubkey},
std::{
borrow::Borrow,
io,
io, mem,
path::{Path, PathBuf},
},
};
// Data placement should be aligned at the next boundary. Without alignment accessing the memory may
// crash on some architectures.
pub const ALIGN_BOUNDARY_OFFSET: usize = mem::size_of::<u64>();
#[macro_export]
macro_rules! u64_align {
($addr: expr) => {
($addr + (ALIGN_BOUNDARY_OFFSET - 1)) & !(ALIGN_BOUNDARY_OFFSET - 1)
};
}
#[derive(Debug)]
/// An enum for accessing an accounts file which can be implemented
/// under different formats.

View File

@ -10,7 +10,9 @@ use {
AccountMeta, StorableAccountsWithHashesAndWriteVersions, StoredAccountInfo,
StoredAccountMeta, StoredMeta, StoredMetaWriteVersion,
},
accounts_file::ALIGN_BOUNDARY_OFFSET,
storable_accounts::StorableAccounts,
u64_align,
},
log::*,
memmap2::MmapMut,
@ -38,15 +40,6 @@ use {
pub mod test_utils;
// Data placement should be aligned at the next boundary. Without alignment accessing the memory may
// crash on some architectures.
pub const ALIGN_BOUNDARY_OFFSET: usize = mem::size_of::<u64>();
macro_rules! u64_align {
($addr: expr) => {
($addr + (ALIGN_BOUNDARY_OFFSET - 1)) & !(ALIGN_BOUNDARY_OFFSET - 1)
};
}
/// size of the fixed sized fields in an append vec
/// we need to add data len and align it to get the actual stored size
pub const STORE_META_OVERHEAD: usize = 136;