Add streaming_unpack_snapshot to send entry files during unpack (#26781)

* Add streaming_unpack_snapshot to send entry files during unpack

* Update unpack tests to call internal function
This commit is contained in:
apfitzge 2022-07-26 14:09:28 -05:00 committed by GitHub
parent 0d9d7f044c
commit 5de1a7accf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 1 deletions

View File

@ -300,6 +300,7 @@ impl ParallelSelector {
}
}
/// Unpacks snapshot and collects AppendVec file names & paths
pub fn unpack_snapshot<A: Read>(
archive: &mut Archive<A>,
ledger_dir: &Path,
@ -321,6 +322,28 @@ pub fn unpack_snapshot<A: Read>(
.map(|_| unpacked_append_vec_map)
}
/// Unpacks snapshots and sends entry file paths through the `sender` channel
pub fn streaming_unpack_snapshot<A: Read>(
archive: &mut Archive<A>,
ledger_dir: &Path,
account_paths: &[PathBuf],
parallel_selector: Option<ParallelSelector>,
sender: &crossbeam_channel::Sender<PathBuf>,
) -> Result<()> {
unpack_snapshot_with_processors(
archive,
ledger_dir,
account_paths,
parallel_selector,
|_, _| {},
|entry_path_buf| {
if entry_path_buf.is_file() {
sender.send(entry_path_buf).unwrap();
}
},
)
}
fn unpack_snapshot_with_processors<A, F, G>(
archive: &mut Archive<A>,
ledger_dir: &Path,
@ -760,7 +783,7 @@ mod tests {
fn finalize_and_unpack_snapshot(archive: tar::Builder<Vec<u8>>) -> Result<()> {
with_finalize_and_unpack(archive, |a, b| {
unpack_snapshot(a, b, &[PathBuf::new()], None).map(|_| ())
unpack_snapshot_with_processors(a, b, &[PathBuf::new()], None, |_, _| {}, |_| {})
})
}