From ec97e3978acf2020bccafb07a824531796333ed3 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Wed, 20 Mar 2024 11:53:24 -0700 Subject: [PATCH] Enable accountsdb_scan_account_storage_no_bank tests for hot storage. --- accounts-db/src/accounts_db.rs | 35 ++++++++++++++++++------------- accounts-db/src/accounts_file.rs | 4 ++-- accounts-db/src/tiered_storage.rs | 4 ++++ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 1a4bcd078ca9b3..fe9cca049f0dce 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -1030,7 +1030,7 @@ pub struct AccountStorageEntry { } impl AccountStorageEntry { - pub fn new( + pub fn new( path: &Path, slot: Slot, id: AccountsFileId, @@ -1038,7 +1038,7 @@ impl AccountStorageEntry { ) -> 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, @@ -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, @@ -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( + _accounts_file_provider: AP, + ) { solana_logger::setup(); let expected = 1; @@ -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::(&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::(&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(); @@ -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( + _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::(&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::(&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(); diff --git a/accounts-db/src/accounts_file.rs b/accounts-db/src/accounts_file.rs index 4fa78705ab1171..0f56e02edad405 100644 --- a/accounts-db/src/accounts_file.rs +++ b/accounts-db/src/accounts_file.rs @@ -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, file_size: u64) -> AccountsFile { @@ -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, _file_size: u64) -> AccountsFile { diff --git a/accounts-db/src/tiered_storage.rs b/accounts-db/src/tiered_storage.rs index cbca5c93d0041e..8437e103739474 100644 --- a/accounts-db/src/tiered_storage.rs +++ b/accounts-db/src/tiered_storage.rs @@ -28,6 +28,7 @@ use { std::{ borrow::Borrow, fs, + io::ErrorKind, path::{Path, PathBuf}, sync::{ atomic::{AtomicBool, Ordering}, @@ -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(),