Create all shared buffer readers before spawning threads (#27512)

* Create all shared buffer readers before spawning threads

* Allow 'needless' collect - clippy is wrong

* move clippy allow, spacing
This commit is contained in:
apfitzge 2022-08-31 22:49:02 -05:00 committed by GitHub
parent 66717ff87d
commit af971e63ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -1203,15 +1203,24 @@ fn streaming_unarchive_snapshot(
let ledger_dir = Arc::new(ledger_dir);
let shared_buffer = untar_snapshot_create_shared_buffer(&snapshot_archive_path, archive_format);
(0..num_threads)
.map(|thread_index| {
// All shared buffer readers need to be created before the threads are spawned
#[allow(clippy::needless_collect)]
let archives: Vec<_> = (0..num_threads)
.map(|_| {
let reader = SharedBufferReader::new(&shared_buffer);
Archive::new(reader)
})
.collect();
archives
.into_iter()
.enumerate()
.map(|(thread_index, archive)| {
let parallel_selector = Some(ParallelSelector {
index: thread_index,
divisions: num_threads,
});
let reader = SharedBufferReader::new(&shared_buffer);
let archive = Archive::new(reader);
spawn_unpack_snapshot_thread(
file_sender.clone(),
account_paths.clone(),