Skip to content
Merged
Show file tree
Hide file tree
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
40 changes: 23 additions & 17 deletions src/ipld/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use std::{collections::VecDeque, future::Future, sync::Arc};
use std::ops::DerefMut;
use std::{collections::VecDeque, future::Future, mem, sync::Arc};

use crate::cid_collections::CidHashSet;
use crate::ipld::Ipld;
Expand Down Expand Up @@ -363,18 +364,21 @@ pin_project! {
queue: Vec<Cid>,
fail_on_dead_links: bool,
}
}

impl<DB, T> UnorderedChainStream<DB, T> {
pub fn into_seen(self) -> CidHashSet {
match Arc::try_unwrap(self.seen) {
Ok(v) => v.into_inner(),
Err(v) => v.lock().clone(),
impl<DB, T> PinnedDrop for UnorderedChainStream<DB, T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find doc for implementing PinnedDrop with pin-project-lite, have you verified drop is being called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

fn drop(this: Pin<&mut Self>) {
this.worker_handle.abort()
}
}
}

pub async fn join_workers(self) -> anyhow::Result<()> {
self.worker_handle.await?
impl<DB, T> UnorderedChainStream<DB, T> {
pub fn into_seen(self) -> CidHashSet {
let mut set = CidHashSet::new();
let mut guard = self.seen.lock();
let data = guard.deref_mut();
mem::swap(data, &mut set);
set
}
}

Expand Down Expand Up @@ -476,7 +480,7 @@ impl<DB: Blockstore + Send + Sync + 'static, T: Iterator<Item = Tipset> + Unpin>
let db = db.clone();
let block_sender = block_sender.clone();
handles.spawn(async move {
while let Ok(cid) = extract_receiver.recv_async().await {
'main: while let Ok(cid) = extract_receiver.recv_async().await {
let mut cid_vec = vec![cid];
while let Some(cid) = cid_vec.pop() {
if should_save_block_to_snapshot(cid) && seen.lock().insert(cid) {
Expand All @@ -485,14 +489,16 @@ impl<DB: Blockstore + Send + Sync + 'static, T: Iterator<Item = Tipset> + Unpin>
let mut new_values = extract_cids(&data)?;
cid_vec.append(&mut new_values);
}
block_sender
.send(Ok(CarBlock { cid, data }))
.expect("unreachable");
// Break out of the loop if the receiving end quit.
if block_sender.send(Ok(CarBlock { cid, data })).is_err() {
break 'main;
}
} else if fail_on_dead_links {
block_sender
.send(Err(anyhow::anyhow!("missing key: {}", cid)))
.expect("unreachable");
break;
// If the receiving end has already quit - just ignore it and
// break out of the loop.
let _ = block_sender
.send(Err(anyhow::anyhow!("missing key: {}", cid)));
break 'main;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/tool/subcommands/benchmark_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ async fn benchmark_unordered_graph_traversal(input: Vec<PathBuf>) -> anyhow::Res
while let Some(block) = s.try_next().await? {
sink.write_all(&block.data).await?
}
s.join_workers().await?;

Ok(())
}
Expand Down