Skip to content

Commit

Permalink
Enable accountsdb_scan_account_storage_no_bank tests for hot storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhchiang-sol committed Mar 26, 2024
1 parent be0be12 commit ec97e39
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
35 changes: 20 additions & 15 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,15 +1030,15 @@ pub struct AccountStorageEntry {
}

impl AccountStorageEntry {
pub fn new<AFP: AccountsFileProvider>(
pub fn new<AP: AccountsFileProvider>(
path: &Path,
slot: Slot,
id: AccountsFileId,
file_size: u64,
) -> Self {
let tail = AccountsFile::file_name(slot, id);
let path = Path::new(path).join(tail);
let accounts = AFP::new_writable(path, file_size);
let accounts = AP::new_writable(path, file_size);

Self {
id,
Expand Down Expand Up @@ -9509,6 +9509,7 @@ pub mod tests {
crate::{
account_info::StoredSize,
account_storage::meta::{AccountMeta, StoredMeta},
accounts_file::{AppendVecProvider, HotStorageProvider},
accounts_hash::MERKLE_FANOUT,
accounts_index::{tests::*, AccountSecondaryIndexesIncludeExclude},
ancient_append_vecs,
Expand Down Expand Up @@ -10592,8 +10593,11 @@ pub mod tests {
}
}

#[test]
fn test_accountsdb_scan_account_storage_no_bank() {
#[test_case(AppendVecProvider::default(); "append_vec")]
#[test_case(HotStorageProvider::default(); "hot_storage")]
fn test_accountsdb_scan_account_storage_no_bank<AP: AccountsFileProvider>(
_accounts_file_provider: AP,
) {
solana_logger::setup();

let expected = 1;
Expand All @@ -10603,10 +10607,9 @@ pub mod tests {
let (_temp_dirs, paths) = get_temp_accounts_paths(1).unwrap();
let slot_expected: Slot = 0;
let size: usize = 123;
let mut data =
AccountStorageEntry::new::<AppendVecProvider>(&paths[0], slot_expected, 0, size as u64);
let av = AccountsFile::AppendVec(AppendVec::new(&tf.path, true, 1024 * 1024));
data.accounts = av;
let mut data = AccountStorageEntry::new::<AP>(&paths[0], slot_expected, 0, size as u64);
let accounts_file = AP::new_writable(&tf.path, 1024 * 1024);
data.accounts = accounts_file;

let storage = Arc::new(data);
let pubkey = solana_sdk::pubkey::new_rand();
Expand Down Expand Up @@ -10709,21 +10712,23 @@ pub mod tests {
}
}

#[test]
fn test_accountsdb_scan_account_storage_no_bank_one_slot() {
#[test_case(AppendVecProvider::default(); "append_vec")]
#[test_case(HotStorageProvider::default(); "hot_storage")]
fn test_accountsdb_scan_account_storage_no_bank_one_slot<AP: AccountsFileProvider>(
_accounts_file_provider: AP,
) {
solana_logger::setup();

let expected = 1;
let tf = crate::append_vec::test_utils::get_append_vec_path(
"test_accountsdb_scan_account_storage_no_bank",
"test_accountsdb_scan_account_storage_no_bank_one_slot",
);
let (_temp_dirs, paths) = get_temp_accounts_paths(1).unwrap();
let slot_expected: Slot = 0;
let size: usize = 123;
let mut data =
AccountStorageEntry::new::<AppendVecProvider>(&paths[0], slot_expected, 0, size as u64);
let av = AccountsFile::AppendVec(AppendVec::new(&tf.path, true, 1024 * 1024));
data.accounts = av;
let mut data = AccountStorageEntry::new::<AP>(&paths[0], slot_expected, 0, size as u64);
let accounts_file = AP::new_writable(&tf.path, 1024 * 1024);
data.accounts = accounts_file;

let storage = Arc::new(data);
let pubkey = solana_sdk::pubkey::new_rand();
Expand Down
4 changes: 2 additions & 2 deletions accounts-db/src/accounts_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub trait AccountsFileProvider {
}

/// A struct that creates AccountsFile instance under AppendVec format.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct AppendVecProvider;
impl AccountsFileProvider for AppendVecProvider {
fn new_writable(path: impl Into<PathBuf>, file_size: u64) -> AccountsFile {
Expand All @@ -242,7 +242,7 @@ impl AccountsFileProvider for AppendVecProvider {
}

/// A struct that creates AccountsFile instance under HotStorage format.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct HotStorageProvider;
impl AccountsFileProvider for HotStorageProvider {
fn new_writable(path: impl Into<PathBuf>, _file_size: u64) -> AccountsFile {
Expand Down
4 changes: 4 additions & 0 deletions accounts-db/src/tiered_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use {
std::{
borrow::Borrow,
fs,
io::ErrorKind,
path::{Path, PathBuf},
sync::{
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -65,6 +66,9 @@ pub struct TieredStorage {
impl Drop for TieredStorage {
fn drop(&mut self) {
if let Err(err) = fs::remove_file(&self.path) {
if err.kind() == ErrorKind::NotFound {
return;
}
panic!(
"TieredStorage failed to remove backing storage file '{}': {err}",
self.path.display(),
Expand Down

0 comments on commit ec97e39

Please sign in to comment.