Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switches order of tiered storage footer size and version #34310

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions accounts-db/src/tiered_storage/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ pub struct TieredStorageFooter {
/// A hash that represents a tiered accounts file for consistency check.
pub hash: Hash,

/// The format version of the tiered accounts file.
pub format_version: u64,
// The below fields belong to footer tail.
// The sum of their sizes should match FOOTER_TAIL_SIZE.
/// The size of the footer including the magic number.
pub footer_size: u64,
/// The format version of the tiered accounts file.
pub format_version: u64,
// This field is persisted in the storage but not in this struct.
// The number should match FOOTER_MAGIC_NUMBER.
// pub magic_number: u64,
Expand All @@ -166,8 +166,8 @@ const _: () = assert!(
+ std::mem::size_of::<Pubkey>() // min_account_address
+ std::mem::size_of::<Pubkey>() // max_account_address
+ std::mem::size_of::<Hash>() // hash
+ std::mem::size_of::<u64>() // footer_size
+ std::mem::size_of::<u64>(), // format_version
+ std::mem::size_of::<u64>() // format_version
+ std::mem::size_of::<u64>(), // footer_size
"TieredStorageFooter cannot have any padding"
);

Expand All @@ -188,8 +188,8 @@ impl Default for TieredStorageFooter {
hash: Hash::new_unique(),
min_account_address: Pubkey::default(),
max_account_address: Pubkey::default(),
footer_size: FOOTER_SIZE as u64,
format_version: FOOTER_FORMAT_VERSION,
footer_size: FOOTER_SIZE as u64,
}
}
}
Expand All @@ -208,8 +208,15 @@ impl TieredStorageFooter {
}

pub fn new_from_footer_block(file: &TieredStorageFile) -> TieredStorageResult<Self> {
let mut footer_size: u64 = 0;
file.seek_from_end(-(FOOTER_TAIL_SIZE as i64))?;

let mut footer_version: u64 = 0;
file.read_type(&mut footer_version)?;
if footer_version != FOOTER_FORMAT_VERSION {
return Err(TieredStorageError::InvalidFooterVersion(footer_version));
}

let mut footer_size: u64 = 0;
file.read_type(&mut footer_size)?;
if footer_size != FOOTER_SIZE as u64 {
return Err(TieredStorageError::InvalidFooterSize(
Expand All @@ -218,12 +225,6 @@ impl TieredStorageFooter {
));
}

let mut footer_version: u64 = 0;
file.read_type(&mut footer_version)?;
if footer_version != FOOTER_FORMAT_VERSION {
return Err(TieredStorageError::InvalidFooterVersion(footer_version));
}

let mut magic_number = TieredStorageMagicNumber::zeroed();
file.read_type(&mut magic_number)?;
if magic_number != TieredStorageMagicNumber::default() {
Expand All @@ -243,6 +244,12 @@ impl TieredStorageFooter {

pub fn new_from_mmap(mmap: &Mmap) -> TieredStorageResult<&TieredStorageFooter> {
let offset = mmap.len().saturating_sub(FOOTER_TAIL_SIZE);

let (footer_version, offset) = get_type::<u64>(mmap, offset)?;
if *footer_version != FOOTER_FORMAT_VERSION {
return Err(TieredStorageError::InvalidFooterVersion(*footer_version));
}

let (&footer_size, offset) = get_type::<u64>(mmap, offset)?;
if footer_size != FOOTER_SIZE as u64 {
return Err(TieredStorageError::InvalidFooterSize(
Expand All @@ -251,11 +258,6 @@ impl TieredStorageFooter {
));
}

let (footer_version, offset) = get_type::<u64>(mmap, offset)?;
if *footer_version != FOOTER_FORMAT_VERSION {
return Err(TieredStorageError::InvalidFooterVersion(*footer_version));
}

let (magic_number, _offset) = get_type::<TieredStorageMagicNumber>(mmap, offset)?;
if *magic_number != TieredStorageMagicNumber::default() {
return Err(TieredStorageError::MagicNumberMismatch(
Expand Down Expand Up @@ -353,8 +355,8 @@ mod tests {
hash: Hash::new_unique(),
min_account_address: Pubkey::default(),
max_account_address: Pubkey::new_unique(),
footer_size: FOOTER_SIZE as u64,
format_version: FOOTER_FORMAT_VERSION,
footer_size: FOOTER_SIZE as u64,
};

// Persist the expected footer.
Expand Down Expand Up @@ -390,8 +392,8 @@ mod tests {
assert_eq!(offset_of!(TieredStorageFooter, min_account_address), 0x30);
assert_eq!(offset_of!(TieredStorageFooter, max_account_address), 0x50);
assert_eq!(offset_of!(TieredStorageFooter, hash), 0x70);
assert_eq!(offset_of!(TieredStorageFooter, footer_size), 0x90);
assert_eq!(offset_of!(TieredStorageFooter, format_version), 0x98);
assert_eq!(offset_of!(TieredStorageFooter, format_version), 0x90);
assert_eq!(offset_of!(TieredStorageFooter, footer_size), 0x98);
}

#[test]
Expand Down