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

ThreadPoolBuilder can fail when resources are busy #68

Merged
merged 2 commits into from
Feb 23, 2024
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
22 changes: 17 additions & 5 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,23 @@ fn lookup_txos(
outpoints: &BTreeSet<OutPoint>,
allow_missing: bool,
) -> HashMap<OutPoint, TxOut> {
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(16) // we need to saturate SSD IOPS
.thread_name(|i| format!("lookup-txo-{}", i))
.build()
.unwrap();
let mut loop_count = 10;
let pool = loop {
match rayon::ThreadPoolBuilder::new()
.num_threads(16) // we need to saturate SSD IOPS
.thread_name(|i| format!("lookup-txo-{}", i))
.build()
{
Ok(pool) => break pool,
Err(e) => {
if loop_count == 0 {
panic!("schema::lookup_txos failed to create a ThreadPool: {}", e);
}
std::thread::sleep(std::time::Duration::from_millis(50));
loop_count -= 1;
}
}
};
pool.install(|| {
outpoints
.par_iter()
Expand Down
Loading