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

Define bank_snapshots_dir as tmpdir #31216

Merged
merged 4 commits into from
Apr 17, 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
39 changes: 17 additions & 22 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5124,8 +5124,7 @@ mod tests {
let genesis_config = GenesisConfig::default();
let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));

let tmp_dir = tempfile::TempDir::new().unwrap();
let bank_snapshots_dir = tmp_dir.path();
let bank_snapshots_dir = tempfile::TempDir::new().unwrap();
let collecter_id = Pubkey::new_unique();
let snapshot_version = SnapshotVersion::default();

Expand All @@ -5140,7 +5139,7 @@ mod tests {
let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
add_bank_snapshot(
bank_snapshots_dir,
&bank_snapshots_dir,
&bank,
&snapshot_storages,
snapshot_version,
Expand All @@ -5149,27 +5148,27 @@ mod tests {
.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);

let complete_flag_file = snapshot.snapshot_dir.join(SNAPSHOT_STATE_COMPLETE_FILENAME);
fs::remove_file(complete_flag_file).unwrap();
// The incomplete snapshot dir should still exist
let snapshot_dir_4 = snapshot.snapshot_dir;
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);
// The incomplete snapshot dir should have been deleted
assert!(!snapshot_dir_4.exists());

let snapshot_version_file = snapshot.snapshot_dir.join(SNAPSHOT_VERSION_FILENAME);
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);

let status_cache_file = snapshot.snapshot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
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);
}

Expand Down Expand Up @@ -5226,9 +5225,7 @@ mod tests {
solana_logger::setup();
let genesis_config = GenesisConfig::default();
let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));

let tmp_dir = tempfile::TempDir::new().unwrap();
let bank_snapshots_dir = tmp_dir.path();
let bank_snapshots_dir = tempfile::TempDir::new().unwrap();
let collecter_id = Pubkey::new_unique();
let snapshot_version = SnapshotVersion::default();

Expand All @@ -5243,7 +5240,7 @@ mod tests {
let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
add_bank_snapshot(
bank_snapshots_dir,
&bank_snapshots_dir,
&bank,
&snapshot_storages,
snapshot_version,
Expand All @@ -5252,7 +5249,7 @@ mod tests {
.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");

// the symlinks point to the account snapshot hardlink directories <account_path>/snapshot/<slot>/ for slot 2
Expand All @@ -5278,7 +5275,7 @@ mod tests {
.map(|dir| dir.parent().unwrap().parent().unwrap().to_path_buf())
.collect();
// 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
assert!(hardlink_dirs_slot_2
Expand Down Expand Up @@ -5462,8 +5459,7 @@ mod tests {
let genesis_config = GenesisConfig::default();
let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));

let tmp_dir = tempfile::TempDir::new().unwrap();
let bank_snapshots_dir = tmp_dir.path();
let bank_snapshots_dir = tempfile::TempDir::new().unwrap();
let collecter_id = Pubkey::new_unique();
let snapshot_version = SnapshotVersion::default();

Expand All @@ -5478,7 +5474,7 @@ mod tests {
let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
add_bank_snapshot(
bank_snapshots_dir,
&bank_snapshots_dir,
&bank,
&snapshot_storages,
snapshot_version,
Expand All @@ -5487,7 +5483,7 @@ mod tests {
.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 (bank_constructed, ..) = bank_from_snapshot_dir(
Expand Down Expand Up @@ -5530,8 +5526,7 @@ mod tests {
let genesis_config = GenesisConfig::default();
let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));

let tmp_dir = tempfile::TempDir::new().unwrap();
let bank_snapshots_dir = tmp_dir.path();
let bank_snapshots_dir = tempfile::TempDir::new().unwrap();
let collecter_id = Pubkey::new_unique();
let snapshot_version = SnapshotVersion::default();

Expand All @@ -5546,7 +5541,7 @@ mod tests {
let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
add_bank_snapshot(
bank_snapshots_dir,
&bank_snapshots_dir,
&bank,
&snapshot_storages,
snapshot_version,
Expand All @@ -5557,7 +5552,7 @@ mod tests {
// to construct a bank.
assert!(
crate::serde_snapshot::reserialize_bank_with_new_accounts_hash(
bank_snapshots_dir,
&bank_snapshots_dir,
bank.slot(),
&AccountsHash(Hash::new_unique()),
None
Expand All @@ -5568,7 +5563,7 @@ mod tests {
let account_paths = &bank.rc.accounts.accounts_db.paths;

let deserialized_bank = bank_from_latest_snapshot_dir(
bank_snapshots_dir,
&bank_snapshots_dir,
&genesis_config,
&RuntimeConfig::default(),
account_paths,
Expand Down