Skip to content

refactor: Remove slot mutex and simplify 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

Merged
merged 68 commits into from
Aug 6, 2025

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...

Note: a lot of changes are to add the wait_idle fn in the rpc protocol, which isn't really related to the changes in the PR but just a way to get rid of some flaky tests.

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-08-06T12:21:41Z

@rklaehn rklaehn changed the title Remove slot mutex refactor: Remove slot mutex and simplfy per blob state Jul 10, 2025
@rklaehn rklaehn marked this pull request as ready for review August 6, 2025 11:50
@rklaehn rklaehn requested a review from matheus23 August 6, 2025 11:50
@rklaehn rklaehn changed the base branch from slim-down-state to main August 6, 2025 12:08
@rklaehn rklaehn force-pushed the remove-slot-mutex branch from 701cb08 to 5b3953d Compare August 6, 2025 12:20
@matheus23 matheus23 changed the title refactor: Remove slot mutex and simplfy per blob state refactor: Remove slot mutex and simplify per blob state Aug 6, 2025
@rklaehn rklaehn merged commit ee3e710 into main Aug 6, 2025
25 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Aug 6, 2025
@rklaehn rklaehn deleted the remove-slot-mutex branch August 6, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants