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

refactor(iroh-blobs)!: make TempTag non-Clone #2338

Merged
merged 5 commits into from
Jun 5, 2024
Merged

Conversation

rklaehn
Copy link
Contributor

@rklaehn rklaehn commented Jun 3, 2024

Description

refactor(iroh-blobs): Make TempTag non-Clone

I found that in most places it is not needed, and if somebody needs them to be clone they can always wrap them in an Arc.

Also, this complicates extending the concept of temp tags via the rpc boundary.

With this change if will be possible to use the same TempTag type both in the low level blobs store API and in the higher level blobs API of iroh.

Breaking Changes

Changes the signature of TempTag::new to take a Weak<dyn TagDrop> instead
of an Arc. This will affect projects that write their own store
impl, so none that I am aware of. Nevertheless it is a breaking change.

The high level rpc API is not affected, since it does not know temp tags (yet).

Notes & open questions

Note: this is just part 1/x of changes needed to extend temp tags to the rpc api. On its own it does not provide much value.

Note2: you could be even more radical and give a TempTag a lifetime and a reference to its store. But I am pretty sure that this would not play well with creating bindings and might even be inconvenient from pure rust.

Change checklist

  • Self-review.
  • Documentation updates if relevant.
  • Tests if relevant.
  • All breaking changes documented.

rklaehn added 2 commits June 3, 2024 11:24
I found that in most places it is not needed, and if somebody needs them
to be clone they can always wrap them in an Arc.

Also, this complicates extending the concept of temp tags via the rpc
boundary.

With this change if will be possible to use the same TempTag type both in
the low level blobs store API and in the higher level blobs API of iroh.
@rklaehn rklaehn changed the title Make TempTag non-Clone refactor(iroh-blobs): Make TempTag non-Clone Jun 3, 2024
@rklaehn rklaehn added this to the v0.18.0 milestone Jun 3, 2024
@rklaehn rklaehn requested review from Frando and dignifiedquire June 4, 2024 08:08
@@ -66,7 +66,9 @@ impl TempCounterMap {

fn dec(&mut self, value: &HashAndFormat) {
let HashAndFormat { hash, format } = value;
let counters = self.0.get_mut(hash).unwrap();
let Some(counters) = self.0.get_mut(hash) else {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

when would this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you decrement something that has not been incremented before. It should never happen, but if it happens it's better to just ignore it than to panic. Given that messages that trigger a dec go via the rpc boundary I don't think it is safe to write unreachable here.

Maybe a warning?

Copy link
Contributor

Choose a reason for hiding this comment

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

given that we don't expect this happening, putting in a warning would be good, so we know if it starts happening

@rklaehn rklaehn requested a review from dignifiedquire June 5, 2024 07:02
@dignifiedquire dignifiedquire changed the title refactor(iroh-blobs): Make TempTag non-Clone refactor(iroh-blobs)!: Make TempTag non-Clone Jun 5, 2024
@dignifiedquire dignifiedquire changed the title refactor(iroh-blobs)!: Make TempTag non-Clone refactor(iroh-blobs)!: make TempTag non-Clone Jun 5, 2024
@rklaehn rklaehn enabled auto-merge June 5, 2024 10:02
@rklaehn rklaehn added this pull request to the merge queue Jun 5, 2024
Merged via the queue into main with commit d0662c2 Jun 5, 2024
24 of 25 checks passed
@rklaehn rklaehn deleted the temp-tag-no-clone branch June 5, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants