Skip to content

Commit

Permalink
use exit signal for acct idx bg threads (solana-labs#27483)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Sep 12, 2022
1 parent f0770c1 commit 765c628
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 41 deletions.
1 change: 1 addition & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ fn load_blockstore(
.cache_block_meta_sender
.as_ref(),
accounts_update_notifier,
exit,
);

// Before replay starts, set the callbacks in each of the banks in BankForks so that
Expand Down
3 changes: 3 additions & 0 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ fn restore_from_snapshot(
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
&Arc::default(),
)
.unwrap();

Expand Down Expand Up @@ -849,6 +850,7 @@ fn restore_from_snapshots_and_check_banks_are_equal(
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
&Arc::default(),
)?;

assert_eq!(bank, &deserialized_bank);
Expand Down Expand Up @@ -1044,6 +1046,7 @@ fn test_snapshots_with_background_services(
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
&Arc::default(),
)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ fn load_bank_forks(
&process_options,
None,
accounts_update_notifier,
&Arc::default(),
);

let (snapshot_request_sender, snapshot_request_receiver) = crossbeam_channel::unbounded();
Expand Down
9 changes: 8 additions & 1 deletion ledger/src/bank_forks_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use {
fs,
path::PathBuf,
process, result,
sync::{Arc, RwLock},
sync::{atomic::AtomicBool, Arc, RwLock},
},
};

Expand Down Expand Up @@ -50,6 +50,7 @@ pub fn load(
transaction_status_sender: Option<&TransactionStatusSender>,
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
exit: &Arc<AtomicBool>,
) -> LoadResult {
let (bank_forks, leader_schedule_cache, starting_snapshot_hashes, ..) = load_bank_forks(
genesis_config,
Expand All @@ -60,6 +61,7 @@ pub fn load(
&process_options,
cache_block_meta_sender,
accounts_update_notifier,
exit,
);

blockstore_processor::process_blockstore_from_root(
Expand All @@ -84,6 +86,7 @@ pub fn load_bank_forks(
process_options: &ProcessOptions,
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
exit: &Arc<AtomicBool>,
) -> (
Arc<RwLock<BankForks>>,
LeaderScheduleCache,
Expand Down Expand Up @@ -124,6 +127,7 @@ pub fn load_bank_forks(
snapshot_config.as_ref().unwrap(),
process_options,
accounts_update_notifier,
exit,
)
} else {
let maybe_filler_accounts = process_options
Expand All @@ -143,6 +147,7 @@ pub fn load_bank_forks(
process_options,
cache_block_meta_sender,
accounts_update_notifier,
exit,
);
bank_forks
.read()
Expand Down Expand Up @@ -186,6 +191,7 @@ fn bank_forks_from_snapshot(
snapshot_config: &SnapshotConfig,
process_options: &ProcessOptions,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
exit: &Arc<AtomicBool>,
) -> (Arc<RwLock<BankForks>>, Option<StartingSnapshotHashes>) {
// Fail hard here if snapshot fails to load, don't silently continue
if account_paths.is_empty() {
Expand Down Expand Up @@ -214,6 +220,7 @@ fn bank_forks_from_snapshot(
process_options.verify_index,
process_options.accounts_db_config.clone(),
accounts_update_notifier,
exit,
)
.expect("Load from snapshot failed");

Expand Down
72 changes: 52 additions & 20 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use {
collections::{HashMap, HashSet},
path::PathBuf,
result,
sync::{Arc, Mutex, RwLock},
sync::{atomic::AtomicBool, Arc, Mutex, RwLock},
time::{Duration, Instant},
},
thiserror::Error,
Expand Down Expand Up @@ -722,6 +722,7 @@ pub fn test_process_blockstore(
genesis_config: &GenesisConfig,
blockstore: &Blockstore,
opts: &ProcessOptions,
exit: &Arc<AtomicBool>,
) -> (Arc<RwLock<BankForks>>, LeaderScheduleCache) {
let (bank_forks, leader_schedule_cache, ..) = crate::bank_forks_utils::load_bank_forks(
genesis_config,
Expand All @@ -732,6 +733,7 @@ pub fn test_process_blockstore(
opts,
None,
None,
exit,
);
process_blockstore_from_root(
blockstore,
Expand All @@ -753,6 +755,7 @@ pub(crate) fn process_blockstore_for_bank_0(
opts: &ProcessOptions,
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
exit: &Arc<AtomicBool>,
) -> Arc<RwLock<BankForks>> {
// Setup bank for slot 0
let bank0 = Bank::new_with_paths(
Expand All @@ -767,6 +770,7 @@ pub(crate) fn process_blockstore_for_bank_0(
false,
opts.accounts_db_config.clone(),
accounts_update_notifier,
exit,
);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0)));

Expand Down Expand Up @@ -1842,7 +1846,7 @@ pub mod tests {
AccessType::Primary | AccessType::PrimaryForMaintenance => {
// Attempting to open a second Primary access would fail, so
// just pass the original session if it is a Primary variant
test_process_blockstore(genesis_config, blockstore, opts)
test_process_blockstore(genesis_config, blockstore, opts, &Arc::default())
}
AccessType::Secondary => {
let secondary_blockstore = Blockstore::open_with_options(
Expand All @@ -1853,7 +1857,12 @@ pub mod tests {
},
)
.expect("Unable to open access to blockstore");
test_process_blockstore(genesis_config, &secondary_blockstore, opts)
test_process_blockstore(
genesis_config,
&secondary_blockstore,
opts,
&Arc::default(),
)
}
}
}
Expand Down Expand Up @@ -1962,6 +1971,7 @@ pub mod tests {
poh_verify: true,
..ProcessOptions::default()
},
&Arc::default(),
);
assert_eq!(frozen_bank_slots(&bank_forks.read().unwrap()), vec![0]);

Expand All @@ -1976,6 +1986,7 @@ pub mod tests {
poh_verify: true,
..ProcessOptions::default()
},
&Arc::default(),
);

// One valid fork, one bad fork. process_blockstore() should only return the valid fork
Expand Down Expand Up @@ -2030,7 +2041,8 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
assert_eq!(frozen_bank_slots(&bank_forks.read().unwrap()), vec![0]);
}

Expand Down Expand Up @@ -2094,7 +2106,8 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());

assert_eq!(frozen_bank_slots(&bank_forks.read().unwrap()), vec![0]); // slot 1 isn't "full", we stop at slot zero

Expand All @@ -2113,7 +2126,8 @@ pub mod tests {
};
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 3, 0, blockhash);
// Slot 0 should not show up in the ending bank_forks_info
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());

// slot 1 isn't "full", we stop at slot zero
assert_eq!(frozen_bank_slots(&bank_forks.read().unwrap()), vec![0, 3]);
Expand Down Expand Up @@ -2179,7 +2193,8 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
let bank_forks = bank_forks.read().unwrap();

// One fork, other one is ignored b/c not a descendant of the root
Expand Down Expand Up @@ -2258,7 +2273,8 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
let bank_forks = bank_forks.read().unwrap();

assert_eq!(frozen_bank_slots(&bank_forks), vec![1, 2, 3, 4]);
Expand Down Expand Up @@ -2314,8 +2330,12 @@ pub mod tests {
blockstore.set_dead_slot(2).unwrap();
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 3, 1, slot1_blockhash);

let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &ProcessOptions::default());
let (bank_forks, ..) = test_process_blockstore(
&genesis_config,
&blockstore,
&ProcessOptions::default(),
&Arc::default(),
);
let bank_forks = bank_forks.read().unwrap();

assert_eq!(frozen_bank_slots(&bank_forks), vec![0, 1, 3]);
Expand Down Expand Up @@ -2359,8 +2379,12 @@ pub mod tests {
blockstore.set_dead_slot(4).unwrap();
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 3, 1, slot1_blockhash);

let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &ProcessOptions::default());
let (bank_forks, ..) = test_process_blockstore(
&genesis_config,
&blockstore,
&ProcessOptions::default(),
&Arc::default(),
);
let bank_forks = bank_forks.read().unwrap();

// Should see the parent of the dead child
Expand Down Expand Up @@ -2407,8 +2431,12 @@ pub mod tests {
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 2, 0, blockhash);
blockstore.set_dead_slot(1).unwrap();
blockstore.set_dead_slot(2).unwrap();
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &ProcessOptions::default());
let (bank_forks, ..) = test_process_blockstore(
&genesis_config,
&blockstore,
&ProcessOptions::default(),
&Arc::default(),
);
let bank_forks = bank_forks.read().unwrap();

// Should see only the parent of the dead children
Expand Down Expand Up @@ -2459,7 +2487,8 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
let bank_forks = bank_forks.read().unwrap();

// There is one fork, head is last_slot + 1
Expand Down Expand Up @@ -2603,7 +2632,8 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
let bank_forks = bank_forks.read().unwrap();

assert_eq!(frozen_bank_slots(&bank_forks), vec![0, 1]);
Expand Down Expand Up @@ -2633,7 +2663,8 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
let bank_forks = bank_forks.read().unwrap();

assert_eq!(frozen_bank_slots(&bank_forks), vec![0]);
Expand All @@ -2653,7 +2684,7 @@ pub mod tests {
..ProcessOptions::default()
};
let (_bank_forks, leader_schedule) =
test_process_blockstore(&genesis_config, &blockstore, &opts);
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
assert_eq!(leader_schedule.max_schedules(), std::usize::MAX);
}

Expand Down Expand Up @@ -2712,7 +2743,7 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
test_process_blockstore(&genesis_config, &blockstore, &opts);
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
assert_eq!(*callback_counter.write().unwrap(), 2);
}

Expand Down Expand Up @@ -3366,7 +3397,8 @@ pub mod tests {
accounts_db_test_hash_calculation: true,
..ProcessOptions::default()
};
let (bank_forks, ..) = test_process_blockstore(&genesis_config, &blockstore, &opts);
let (bank_forks, ..) =
test_process_blockstore(&genesis_config, &blockstore, &opts, &Arc::default());
let bank_forks = bank_forks.read().unwrap();

// Should be able to fetch slot 0 because we specified halting at slot 0, even
Expand Down
1 change: 1 addition & 0 deletions local-cluster/tests/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,7 @@ fn create_snapshot_to_hard_fork(
None,
None,
None,
&Arc::default(),
)
.unwrap();
let bank = bank_forks.read().unwrap().get(snapshot_slot).unwrap();
Expand Down
6 changes: 5 additions & 1 deletion runtime/benches/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use {
},
},
solana_sdk::{account::AccountSharedData, pubkey},
std::sync::Arc,
test::Bencher,
};

Expand All @@ -23,7 +24,10 @@ fn bench_accounts_index(bencher: &mut Bencher) {
const NUM_FORKS: u64 = 16;

let mut reclaims = vec![];
let index = AccountsIndex::<AccountInfo>::new(Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS));
let index = AccountsIndex::<AccountInfo>::new(
Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS),
&Arc::default(),
);
for f in 0..NUM_FORKS {
for pubkey in pubkeys.iter().take(NUM_PUBKEYS) {
index.upsert(
Expand Down
Loading

0 comments on commit 765c628

Please sign in to comment.