Skip to content

refactor: Remove slot mutex and simplfy per blob state #104

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

Draft
wants to merge 13 commits into
base: slim-down-state
Choose a base branch
from

Conversation

rklaehn
Copy link
Collaborator

@rklaehn rklaehn commented Jul 10, 2025

Description

Before, the state we kept per hash was a bit convoluted. The entry point was a Slot, which contained a tokio mutex to cover the async loading of an entry state from the metadata db. Then inside that, there was the actual entry state, wrapped in an option to cover the case that we don't have anything about the hash.

This was working, but it was an arc in an arc in an arc, and also led to bugs in the case of trying to export a blob that doesn't exist.

Now all these states are flattened into a single enum, and we can easily define what should happen when we e.g. do an export of an entry that does not exist - return an appropriate io error.

Breaking Changes

None

Notes & open questions

Note: you could remove the Initial and Loading state by using a tokio::sync::OnceCell. But that is a true sync primitive, and we want to use an AtomicRefCell, and also using a OnceLock would come with its own sync primitive (a semaphore) just for init, and then we have our own one for the non-load state changes. I don't think it is that bad...

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

Copy link

github-actions bot commented Jul 10, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh-blobs/pr/104/docs/iroh_blobs/

Last updated: 2025-07-11T11:58:22Z

///
/// You are not allowed to clone the state out of a task, even though that
/// is possible.
fn ref_count(&self) -> usize;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't really needed - just a safeguard to alert people if they clone the state out of a task.

Not sure if I should keep it.

@rklaehn rklaehn changed the title Remove slot mutex refactor: Remove slot mutex and simplfy per blob state Jul 10, 2025
@n0bot n0bot bot added this to iroh Jul 10, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Jul 10, 2025
@@ -213,6 +219,8 @@ mod entity_actor {
)
.await
.ok();
println!("Calling on_shutdown {}", self.state.state.ref_count());
Copy link
Collaborator

Choose a reason for hiding this comment

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

stray println

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

2 participants