test_snapshots_restart_validity now passes (#5644)

automerge
This commit is contained in:
Michael Vines 2019-08-25 21:33:41 -07:00 committed by Grimes
parent ef8eff69e4
commit 52da207f83
2 changed files with 63 additions and 58 deletions

View File

@ -370,65 +370,56 @@ fn get_bank_forks(
genesis_block: &GenesisBlock, genesis_block: &GenesisBlock,
blocktree: &Blocktree, blocktree: &Blocktree,
account_paths: Option<String>, account_paths: Option<String>,
snapshot_config: Option<SnapshotConfig>, snapshot_config: Option<&SnapshotConfig>,
verify_ledger: bool, verify_ledger: bool,
dev_halt_at_slot: Option<Slot>, dev_halt_at_slot: Option<Slot>,
) -> (BankForks, Vec<BankForksInfo>, LeaderScheduleCache) { ) -> (BankForks, Vec<BankForksInfo>, LeaderScheduleCache) {
let (mut bank_forks, bank_forks_info, leader_schedule_cache) = { if let Some(snapshot_config) = snapshot_config.as_ref() {
if let Some(snapshot_config) = snapshot_config.as_ref() { info!(
info!( "Initializing snapshot path: {:?}",
"Initializing snapshot path: {:?}", snapshot_config.snapshot_path
snapshot_config.snapshot_path );
); let _ = fs::remove_dir_all(&snapshot_config.snapshot_path);
let _ = fs::remove_dir_all(&snapshot_config.snapshot_path); fs::create_dir_all(&snapshot_config.snapshot_path)
fs::create_dir_all(&snapshot_config.snapshot_path) .expect("Couldn't create snapshot directory");
.expect("Couldn't create snapshot directory");
let tar = snapshot_utils::get_snapshot_tar_path( let tar =
&snapshot_config.snapshot_package_output_path, snapshot_utils::get_snapshot_tar_path(&snapshot_config.snapshot_package_output_path);
); if tar.exists() {
if tar.exists() { info!("Loading snapshot package: {:?}", tar);
info!("Loading snapshot package: {:?}", tar); // Fail hard here if snapshot fails to load, don't silently continue
// Fail hard here if snapshot fails to load, don't silently continue let deserialized_bank = snapshot_utils::bank_from_archive(
let deserialized_bank = snapshot_utils::bank_from_archive( account_paths
account_paths .clone()
.clone() .expect("Account paths not present when booting from snapshot"),
.expect("Account paths not present when booting from snapshot"), snapshot_config,
snapshot_config, &tar,
&tar, )
) .expect("Load from snapshot failed");
.expect("Load from snapshot failed");
return blocktree_processor::process_blocktree_from_root( return blocktree_processor::process_blocktree_from_root(
blocktree, blocktree,
Arc::new(deserialized_bank), Arc::new(deserialized_bank),
verify_ledger, verify_ledger,
dev_halt_at_slot, dev_halt_at_slot,
) )
.expect("processing blocktree after loading snapshot failed"); .expect("processing blocktree after loading snapshot failed");
} else {
info!("Snapshot package does not exist: {:?}", tar);
}
} else { } else {
info!("Snapshots disabled"); info!("Snapshot package does not exist: {:?}", tar);
} }
} else {
info!("Processing ledger from genesis"); info!("Snapshots disabled");
blocktree_processor::process_blocktree(
&genesis_block,
&blocktree,
account_paths,
verify_ledger,
dev_halt_at_slot,
)
.expect("process_blocktree failed")
};
if snapshot_config.is_some() {
bank_forks.set_snapshot_config(snapshot_config.unwrap());
} }
(bank_forks, bank_forks_info, leader_schedule_cache) info!("Processing ledger from genesis");
blocktree_processor::process_blocktree(
&genesis_block,
&blocktree,
account_paths,
verify_ledger,
dev_halt_at_slot,
)
.expect("process_blocktree failed")
} }
#[cfg(not(unix))] #[cfg(not(unix))]
@ -504,15 +495,19 @@ pub fn new_banks_from_blocktree(
let (blocktree, ledger_signal_receiver, completed_slots_receiver) = let (blocktree, ledger_signal_receiver, completed_slots_receiver) =
Blocktree::open_with_signal(blocktree_path).expect("Failed to open ledger database"); Blocktree::open_with_signal(blocktree_path).expect("Failed to open ledger database");
let (bank_forks, bank_forks_info, leader_schedule_cache) = get_bank_forks( let (mut bank_forks, bank_forks_info, leader_schedule_cache) = get_bank_forks(
&genesis_block, &genesis_block,
&blocktree, &blocktree,
account_paths, account_paths,
snapshot_config, snapshot_config.as_ref(),
verify_ledger, verify_ledger,
dev_halt_at_slot, dev_halt_at_slot,
); );
if snapshot_config.is_some() {
bank_forks.set_snapshot_config(snapshot_config.unwrap());
}
( (
genesis_blockhash, genesis_blockhash,
bank_forks, bank_forks,

View File

@ -300,10 +300,11 @@ fn test_listener_startup() {
#[test] #[test]
#[serial] #[serial]
fn test_snapshots_restart_validity() { fn test_snapshots_restart_validity() {
solana_logger::setup();
let temp_dir = TempDir::new().unwrap(); let temp_dir = TempDir::new().unwrap();
let snapshot_path = temp_dir.path().join("bank_states"); let snapshot_path = temp_dir.path().join("bank_states");
let snapshot_package_output_path = temp_dir.path().join("tar"); let snapshot_package_output_path = temp_dir.path().join("tar");
let snapshot_interval_slots = 25; let snapshot_interval_slots = 10;
// Create the snapshot directories // Create the snapshot directories
fs::create_dir_all(&snapshot_path).expect("Failed to create snapshots bank state directory"); fs::create_dir_all(&snapshot_path).expect("Failed to create snapshots bank state directory");
@ -334,7 +335,8 @@ fn test_snapshots_restart_validity() {
let num_runs = 3; let num_runs = 3;
let mut expected_balances = HashMap::new(); let mut expected_balances = HashMap::new();
let mut cluster = LocalCluster::new(&config); let mut cluster = LocalCluster::new(&config);
for _ in 0..num_runs { for i in 1..num_runs {
info!("run {}", i);
// Push transactions to one of the nodes and confirm that transactions were // Push transactions to one of the nodes and confirm that transactions were
// forwarded to and processed. // forwarded to and processed.
trace!("Sending transactions"); trace!("Sending transactions");
@ -356,12 +358,20 @@ fn test_snapshots_restart_validity() {
// Wait for a snapshot for a bank >= last_slot to be made so we know that the snapshot // Wait for a snapshot for a bank >= last_slot to be made so we know that the snapshot
// must include the transactions just pushed // must include the transactions just pushed
let tar = snapshot_utils::get_snapshot_tar_path(&snapshot_package_output_path); let tar = snapshot_utils::get_snapshot_tar_path(&snapshot_package_output_path);
trace!("Waiting for tar to be generated"); trace!(
"Waiting for snapshot tar to be generated with slot > {}",
last_slot
);
loop { loop {
if tar.exists() && snapshot_utils::bank_slot_from_archive(&tar).unwrap() >= last_slot { if tar.exists() {
break; trace!("snapshot tar exists");
let slot = snapshot_utils::bank_slot_from_archive(&tar).unwrap();
if slot >= last_slot {
break;
}
trace!("snapshot tar slot {} < last_slot {}", slot, last_slot);
} }
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(5000));
} }
// Create new account paths since fullnode exit is not guaranteed to cleanup RPC threads, // Create new account paths since fullnode exit is not guaranteed to cleanup RPC threads,