Define bank_snapshots_dir as tmpdir (#31216)

* Let bank_snapshots_dir be TempDir

* Same change in test_bank_from_latest_snapshot_dir

* Use borrow to avoid releasing the tmp dir

* One more to change to reference
This commit is contained in:
Xiang Zhu 2023-04-17 08:07:24 -07:00 committed by GitHub
parent 8fccbadbc3
commit f066ea9f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 22 deletions

View File

@ -5124,8 +5124,7 @@ mod tests {
let genesis_config = GenesisConfig::default(); let genesis_config = GenesisConfig::default();
let mut bank = Arc::new(Bank::new_for_tests(&genesis_config)); let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));
let tmp_dir = tempfile::TempDir::new().unwrap(); let bank_snapshots_dir = tempfile::TempDir::new().unwrap();
let bank_snapshots_dir = tmp_dir.path();
let collecter_id = Pubkey::new_unique(); let collecter_id = Pubkey::new_unique();
let snapshot_version = SnapshotVersion::default(); let snapshot_version = SnapshotVersion::default();
@ -5140,7 +5139,7 @@ mod tests {
let snapshot_storages = bank.get_snapshot_storages(None); let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas(); let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
add_bank_snapshot( add_bank_snapshot(
bank_snapshots_dir, &bank_snapshots_dir,
&bank, &bank,
&snapshot_storages, &snapshot_storages,
snapshot_version, snapshot_version,
@ -5149,7 +5148,7 @@ mod tests {
.unwrap(); .unwrap();
} }
let snapshot = get_highest_bank_snapshot(bank_snapshots_dir).unwrap(); let snapshot = get_highest_bank_snapshot(&bank_snapshots_dir).unwrap();
assert_eq!(snapshot.slot, 4); assert_eq!(snapshot.slot, 4);
let complete_flag_file = snapshot.snapshot_dir.join(SNAPSHOT_STATE_COMPLETE_FILENAME); let complete_flag_file = snapshot.snapshot_dir.join(SNAPSHOT_STATE_COMPLETE_FILENAME);
@ -5157,19 +5156,19 @@ mod tests {
// The incomplete snapshot dir should still exist // The incomplete snapshot dir should still exist
let snapshot_dir_4 = snapshot.snapshot_dir; let snapshot_dir_4 = snapshot.snapshot_dir;
assert!(snapshot_dir_4.exists()); assert!(snapshot_dir_4.exists());
let snapshot = get_highest_bank_snapshot(bank_snapshots_dir).unwrap(); let snapshot = get_highest_bank_snapshot(&bank_snapshots_dir).unwrap();
assert_eq!(snapshot.slot, 3); assert_eq!(snapshot.slot, 3);
// The incomplete snapshot dir should have been deleted // The incomplete snapshot dir should have been deleted
assert!(!snapshot_dir_4.exists()); assert!(!snapshot_dir_4.exists());
let snapshot_version_file = snapshot.snapshot_dir.join(SNAPSHOT_VERSION_FILENAME); let snapshot_version_file = snapshot.snapshot_dir.join(SNAPSHOT_VERSION_FILENAME);
fs::remove_file(snapshot_version_file).unwrap(); fs::remove_file(snapshot_version_file).unwrap();
let snapshot = get_highest_bank_snapshot(bank_snapshots_dir).unwrap(); let snapshot = get_highest_bank_snapshot(&bank_snapshots_dir).unwrap();
assert_eq!(snapshot.slot, 2); assert_eq!(snapshot.slot, 2);
let status_cache_file = snapshot.snapshot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME); let status_cache_file = snapshot.snapshot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
fs::remove_file(status_cache_file).unwrap(); fs::remove_file(status_cache_file).unwrap();
let snapshot = get_highest_bank_snapshot(bank_snapshots_dir).unwrap(); let snapshot = get_highest_bank_snapshot(&bank_snapshots_dir).unwrap();
assert_eq!(snapshot.slot, 1); assert_eq!(snapshot.slot, 1);
} }
@ -5226,9 +5225,7 @@ mod tests {
solana_logger::setup(); solana_logger::setup();
let genesis_config = GenesisConfig::default(); let genesis_config = GenesisConfig::default();
let mut bank = Arc::new(Bank::new_for_tests(&genesis_config)); let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));
let bank_snapshots_dir = tempfile::TempDir::new().unwrap();
let tmp_dir = tempfile::TempDir::new().unwrap();
let bank_snapshots_dir = tmp_dir.path();
let collecter_id = Pubkey::new_unique(); let collecter_id = Pubkey::new_unique();
let snapshot_version = SnapshotVersion::default(); let snapshot_version = SnapshotVersion::default();
@ -5243,7 +5240,7 @@ mod tests {
let snapshot_storages = bank.get_snapshot_storages(None); let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas(); let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
add_bank_snapshot( add_bank_snapshot(
bank_snapshots_dir, &bank_snapshots_dir,
&bank, &bank,
&snapshot_storages, &snapshot_storages,
snapshot_version, snapshot_version,
@ -5252,7 +5249,7 @@ mod tests {
.unwrap(); .unwrap();
} }
let snapshot_dir_slot_2 = bank_snapshots_dir.join("2"); let snapshot_dir_slot_2 = bank_snapshots_dir.path().join("2");
let accounts_link_dir_slot_2 = snapshot_dir_slot_2.join("accounts_hardlinks"); let accounts_link_dir_slot_2 = snapshot_dir_slot_2.join("accounts_hardlinks");
// the symlinks point to the account snapshot hardlink directories <account_path>/snapshot/<slot>/ for slot 2 // the symlinks point to the account snapshot hardlink directories <account_path>/snapshot/<slot>/ for slot 2
@ -5278,7 +5275,7 @@ mod tests {
.map(|dir| dir.parent().unwrap().parent().unwrap().to_path_buf()) .map(|dir| dir.parent().unwrap().parent().unwrap().to_path_buf())
.collect(); .collect();
// clean the orphaned hardlink directories // clean the orphaned hardlink directories
clean_orphaned_account_snapshot_dirs(bank_snapshots_dir, &account_snapshot_paths).unwrap(); clean_orphaned_account_snapshot_dirs(&bank_snapshots_dir, &account_snapshot_paths).unwrap();
// verify the hardlink directories are gone // verify the hardlink directories are gone
assert!(hardlink_dirs_slot_2 assert!(hardlink_dirs_slot_2
@ -5462,8 +5459,7 @@ mod tests {
let genesis_config = GenesisConfig::default(); let genesis_config = GenesisConfig::default();
let mut bank = Arc::new(Bank::new_for_tests(&genesis_config)); let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));
let tmp_dir = tempfile::TempDir::new().unwrap(); let bank_snapshots_dir = tempfile::TempDir::new().unwrap();
let bank_snapshots_dir = tmp_dir.path();
let collecter_id = Pubkey::new_unique(); let collecter_id = Pubkey::new_unique();
let snapshot_version = SnapshotVersion::default(); let snapshot_version = SnapshotVersion::default();
@ -5478,7 +5474,7 @@ mod tests {
let snapshot_storages = bank.get_snapshot_storages(None); let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas(); let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
add_bank_snapshot( add_bank_snapshot(
bank_snapshots_dir, &bank_snapshots_dir,
&bank, &bank,
&snapshot_storages, &snapshot_storages,
snapshot_version, snapshot_version,
@ -5487,7 +5483,7 @@ mod tests {
.unwrap(); .unwrap();
} }
let bank_snapshot = get_highest_bank_snapshot(bank_snapshots_dir).unwrap(); let bank_snapshot = get_highest_bank_snapshot(&bank_snapshots_dir).unwrap();
let account_paths = &bank.rc.accounts.accounts_db.paths; let account_paths = &bank.rc.accounts.accounts_db.paths;
let (bank_constructed, ..) = bank_from_snapshot_dir( let (bank_constructed, ..) = bank_from_snapshot_dir(
@ -5530,8 +5526,7 @@ mod tests {
let genesis_config = GenesisConfig::default(); let genesis_config = GenesisConfig::default();
let mut bank = Arc::new(Bank::new_for_tests(&genesis_config)); let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));
let tmp_dir = tempfile::TempDir::new().unwrap(); let bank_snapshots_dir = tempfile::TempDir::new().unwrap();
let bank_snapshots_dir = tmp_dir.path();
let collecter_id = Pubkey::new_unique(); let collecter_id = Pubkey::new_unique();
let snapshot_version = SnapshotVersion::default(); let snapshot_version = SnapshotVersion::default();
@ -5546,7 +5541,7 @@ mod tests {
let snapshot_storages = bank.get_snapshot_storages(None); let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas(); let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
add_bank_snapshot( add_bank_snapshot(
bank_snapshots_dir, &bank_snapshots_dir,
&bank, &bank,
&snapshot_storages, &snapshot_storages,
snapshot_version, snapshot_version,
@ -5557,7 +5552,7 @@ mod tests {
// to construct a bank. // to construct a bank.
assert!( assert!(
crate::serde_snapshot::reserialize_bank_with_new_accounts_hash( crate::serde_snapshot::reserialize_bank_with_new_accounts_hash(
bank_snapshots_dir, &bank_snapshots_dir,
bank.slot(), bank.slot(),
&AccountsHash(Hash::new_unique()), &AccountsHash(Hash::new_unique()),
None None
@ -5568,7 +5563,7 @@ mod tests {
let account_paths = &bank.rc.accounts.accounts_db.paths; let account_paths = &bank.rc.accounts.accounts_db.paths;
let deserialized_bank = bank_from_latest_snapshot_dir( let deserialized_bank = bank_from_latest_snapshot_dir(
bank_snapshots_dir, &bank_snapshots_dir,
&genesis_config, &genesis_config,
&RuntimeConfig::default(), &RuntimeConfig::default(),
account_paths, account_paths,