Skip to content

Commit

Permalink
[TieredStorage] Footer test for HotStorageReader (solana-labs#33718)
Browse files Browse the repository at this point in the history
#### Problem
HotStorageReader currently doesn't have a test that covers its footer.

#### Summary of Changes
This PR includes a test for HotStorageReader that verifies the footer.
  • Loading branch information
yhchiang-sol authored Oct 17, 2023
1 parent c09cbbb commit 0b05e8d
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,18 @@ pub mod tests {
super::*,
crate::tiered_storage::{
byte_block::ByteBlockWriter,
footer::AccountBlockFormat,
file::TieredStorageFile,
footer::{
AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat, TieredStorageFooter,
FOOTER_SIZE,
},
hot::{HotAccountMeta, HotStorageReader},
index::AccountIndexFormat,
meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta},
},
::solana_sdk::{hash::Hash, stake_history::Epoch},
::solana_sdk::{hash::Hash, pubkey::Pubkey, stake_history::Epoch},
memoffset::offset_of,
tempfile::TempDir,
};

#[test]
Expand Down Expand Up @@ -354,4 +361,41 @@ pub mod tests {
optional_fields.account_hash.unwrap()
);
}

#[test]
fn test_hot_storage_footer() {
// Generate a new temp path that is guaranteed to NOT already have a file.
let temp_dir = TempDir::new().unwrap();
let path = temp_dir.path().join("test_hot_storage_footer");
let expected_footer = TieredStorageFooter {
account_meta_format: AccountMetaFormat::Hot,
owners_block_format: OwnersBlockFormat::LocalIndex,
account_index_format: AccountIndexFormat::AddressAndOffset,
account_block_format: AccountBlockFormat::AlignedRaw,
account_entry_count: 300,
account_meta_entry_size: 16,
account_block_size: 4096,
owner_count: 250,
owner_entry_size: 32,
account_index_offset: 1069600,
owners_offset: 1081200,
hash: Hash::new_unique(),
min_account_address: Pubkey::default(),
max_account_address: Pubkey::new_unique(),
footer_size: FOOTER_SIZE as u64,
format_version: 1,
};

{
let file = TieredStorageFile::new_writable(&path).unwrap();
expected_footer.write_footer_block(&file).unwrap();
}

// Reopen the same storage, and expect the persisted footer is
// the same as what we have written.
{
let hot_storage = HotStorageReader::new_from_path(&path).unwrap();
assert_eq!(expected_footer, *hot_storage.footer());
}
}
}

0 comments on commit 0b05e8d

Please sign in to comment.