refactor: simplify span usage in remove_pin
@@ -461,11 +461,10 @@ impl<Types: IpfsTypes> Ipfs<Types> {
self.repo.remove_pin(cid, PinKind::Direct).await
} else {
let span = tracing::debug_span!("remove recursive pin", cid = %cid);
-
+ async move {
let (cid, kind) = self
.repo
.query_pins(vec![cid.to_owned()], None)
- .instrument(span.clone())
.await?
.swap_remove(0);
@@ -475,6 +474,7 @@ impl<Types: IpfsTypes> Ipfs<Types> {
PinKind::RecursiveIntention => {
// there may still be some stragglers so perhaps remove them
// but we dont know how many should we expect to find
+ debug!("detected previous incomplete pinning");
None
}
PinKind::Recursive(count) => Some(count),
@@ -483,7 +483,7 @@ impl<Types: IpfsTypes> Ipfs<Types> {
}
};
- // start walking refs of the root
+ // start walking refs of the root after loading it
let Block { data, .. } = match self.repo.get_block_now(&cid).await? {
Some(b) => b,
@@ -503,13 +503,9 @@ impl<Types: IpfsTypes> Ipfs<Types> {
let mut count = 0u64;
- while let Some(crate::refs::Edge { destination, .. }) =
- st.try_next().instrument(span.clone()).await?
- {
- // we probably don't need to worry about rollback here, if we wrote a
+ while let Some(crate::refs::Edge { destination, .. }) = st.try_next().await? {
self.repo
.remove_pin(&destination, PinKind::IndirectFrom(&cid))
- .instrument(span.clone())
.await?;
count += 1;
@@ -521,26 +517,20 @@ impl<Types: IpfsTypes> Ipfs<Types> {
PinKind::RecursiveIntention
};
- self.repo
- .remove_pin(&cid, removed)
- .instrument(span.clone())
- .await?;
+ self.repo.remove_pin(&cid, removed).await?;
match expected_count {
Some(x) if x == count => {
- // good, we removed as many as we were supposed to
info!(count = x, "removed as many indirect pins as were meant to");
}
Some(x) => {
- // bad
- error!(
+ warn!(
expected = x,
actual = count,
"removed unexpected number of indirect pins",
);
}
None => {
- // well, we cleared out the previous partial operation! good
info!(
cleared_out = count,
"cleaned up and removed previous partial pinning",
@@ -550,6 +540,9 @@ impl<Types: IpfsTypes> Ipfs<Types> {
Ok(())
}
+ .instrument(span)
+ .await
+ }
}
/// Checks whether a given block is pinned. At the moment does not support incomplete recursive
