From b89e506cbb0b881569b65af748e646ea67fca4a8 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 1 Jul 2020 11:38:59 +0900 Subject: [PATCH] Consistently create temp dirs under ledger/farf (#10848) --- ledger-tool/src/main.rs | 2 +- ledger/src/blockstore.rs | 2 +- local-cluster/src/local_cluster.rs | 5 ++++- local-cluster/tests/local_cluster.rs | 12 +++++++++--- runtime/src/snapshot_utils.rs | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 5e0b612351..79df8be6f0 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -1341,7 +1341,7 @@ fn main() { bank.clean_accounts(); bank.update_accounts_hash(); - let temp_dir = tempfile::TempDir::new().unwrap_or_else(|err| { + let temp_dir = tempfile::tempdir_in(ledger_path).unwrap_or_else(|err| { eprintln!("Unable to create temporary directory: {}", err); exit(1); }); diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index ec5ddcd4bd..d1a32ab888 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -2700,7 +2700,7 @@ pub fn create_new_ledger( // ensure the genesis archive can be unpacked and it is under // max_genesis_archive_unpacked_size, immediately after creating it above. { - let temp_dir = tempfile::TempDir::new().unwrap(); + let temp_dir = tempfile::tempdir_in(ledger_path).unwrap(); // unpack into a temp dir, while completely discarding the unpacked files let unpack_check = unpack_genesis_archive( &archive_path, diff --git a/local-cluster/src/local_cluster.rs b/local-cluster/src/local_cluster.rs index 90ca9d892d..d56debf635 100644 --- a/local-cluster/src/local_cluster.rs +++ b/local-cluster/src/local_cluster.rs @@ -173,6 +173,7 @@ impl LocalCluster { leader_node.info.rpc.port(), leader_node.info.rpc_pubsub.port(), )); + leader_config.account_paths = vec![leader_ledger_path.join("accounts")]; let leader_server = Validator::new( leader_node, &leader_keypair, @@ -300,6 +301,7 @@ impl LocalCluster { validator_node.info.rpc_pubsub.port(), )); let voting_keypair = Arc::new(voting_keypair); + config.account_paths = vec![ledger_path.join("accounts")]; let validator_server = Validator::new( validator_node, &validator_keypair, @@ -558,7 +560,8 @@ impl Cluster for LocalCluster { // Restart the node let validator_info = &cluster_validator_info.info; - + cluster_validator_info.config.account_paths = + vec![validator_info.ledger_path.join("accounts")]; let restarted_node = Validator::new( node, &validator_info.keypair, diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index cdc4ffc945..d08e6b70b2 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -1182,9 +1182,15 @@ fn wait_for_next_snapshot( } } +fn farf_dir() -> PathBuf { + std::env::var("FARF_DIR") + .unwrap_or_else(|_| "farf".to_string()) + .into() +} + fn generate_account_paths(num_account_paths: usize) -> (Vec, Vec) { let account_storage_dirs: Vec = (0..num_account_paths) - .map(|_| TempDir::new().unwrap()) + .map(|_| tempfile::tempdir_in(farf_dir()).unwrap()) .collect(); let account_storage_paths: Vec<_> = account_storage_dirs .iter() @@ -1205,8 +1211,8 @@ fn setup_snapshot_validator_config( num_account_paths: usize, ) -> SnapshotValidatorConfig { // Create the snapshot config - let snapshot_dir = TempDir::new().unwrap(); - let snapshot_output_path = TempDir::new().unwrap(); + let snapshot_dir = tempfile::tempdir_in(farf_dir()).unwrap(); + let snapshot_output_path = tempfile::tempdir_in(farf_dir()).unwrap(); let snapshot_config = SnapshotConfig { snapshot_interval_slots, snapshot_package_output_path: PathBuf::from(snapshot_output_path.path()), diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index e40e4a9f72..928cd75f86 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -222,7 +222,7 @@ pub fn archive_snapshot_package(snapshot_package: &AccountsPackage) -> Result<() fs::create_dir_all(tar_dir)?; // Create the staging directories - let staging_dir = TempDir::new()?; + let staging_dir = tempfile::tempdir_in(tar_dir)?; let staging_accounts_dir = staging_dir.path().join(TAR_ACCOUNTS_DIR); let staging_snapshots_dir = staging_dir.path().join(TAR_SNAPSHOTS_DIR); let staging_version_file = staging_dir.path().join(TAR_VERSION_FILE);