-
Notifications
You must be signed in to change notification settings - Fork 171
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
Conversation
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.
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when would this happen?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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>
insteadof 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