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
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
90c23be
Add entity-manager dep
rklaehn Jul 8, 2025
90db719
Remove unused dependencies
rklaehn Jul 8, 2025
24c7f2c
Merge branch 'lose-futures-buffered-dep' into entity-manager
rklaehn Jul 8, 2025
126d834
Merge branch 'main' into entity-manager
rklaehn Jul 8, 2025
264ed84
Add import
rklaehn Jul 8, 2025
a859674
Add helpers for set and update
rklaehn Jul 8, 2025
baf4d54
Make bipolar clippy happy again
rklaehn Jul 8, 2025
66f8540
Move message sending into meta
rklaehn Jul 8, 2025
9193b08
Merge branch 'remove-db-public-send' into entity-manager
rklaehn Jul 8, 2025
8cae7cd
WIP
rklaehn Jul 8, 2025
161a70b
Replace slots with EntityHandler
rklaehn Jul 8, 2025
169261a
Get rid of the weak reference
rklaehn Jul 8, 2025
6fe2e07
Inline entity manager and streamline the dispatcher code a bit
rklaehn Jul 9, 2025
fd9faab
revert a few changes to minimize the diff
rklaehn Jul 9, 2025
8ac1b78
codespell
rklaehn Jul 9, 2025
011746d
remove debug code
rklaehn Jul 9, 2025
def9abc
more comments
rklaehn Jul 9, 2025
3d603b0
remove options from BaoFileHandleInner
rklaehn Jul 9, 2025
e65bd07
Get rid of BaoFileHandleInner and all that indirection
rklaehn Jul 9, 2025
e81b1f3
change a few fns to take HashContext directly instead of 2 args
rklaehn Jul 9, 2025
27df6da
more using HashContext instead of TaskContext
rklaehn Jul 9, 2025
77fbb05
First step for removing the slot mutex
rklaehn Jul 9, 2025
ae95f28
prepare BaoFileHandle to be the full state
rklaehn Jul 9, 2025
c786a04
Flatten the state we keep per active blob
rklaehn Jul 10, 2025
94df43f
Remove debug statements
rklaehn Jul 10, 2025
48ffd48
Remove unused code
rklaehn Jul 10, 2025
a540002
Remove more debug code
rklaehn Jul 10, 2025
6e237f8
instrument the per-hash tasks as well
rklaehn Jul 10, 2025
47cab9c
Add property based tests for the entity manager
rklaehn Jul 10, 2025
00c54f3
Add a property based test that tests basic functionality of the entit…
rklaehn Jul 10, 2025
664beb8
clippy
rklaehn Jul 10, 2025
7b1b71b
Merge branch 'main' into entity-manager
rklaehn Jul 10, 2025
e584ad1
fmt
rklaehn Jul 10, 2025
4412be9
Add tests for the busy and dead cases which are hard to trigger witho…
rklaehn Jul 10, 2025
c26e555
clippy again
rklaehn Jul 10, 2025
002469a
Merge branch 'entity-manager' into slim-down-state
rklaehn Jul 11, 2025
7857e38
Merge branch 'slim-down-state' into remove-slot-mutex
rklaehn Jul 11, 2025
f559598
Move things around in preparation for introducing traits
rklaehn Jul 11, 2025
bc6bc71
Group high level fns.
rklaehn Jul 11, 2025
632131f
Introduce traits to structure the API
rklaehn Jul 11, 2025
8004115
Merge branch 'main' into entity-manager
rklaehn Jul 11, 2025
4020bd4
Merge branch 'entity-manager' into slim-down-state
rklaehn Jul 11, 2025
1665781
Merge branch 'slim-down-state' into remove-slot-mutex
rklaehn Jul 11, 2025
9a8547a
clippy
rklaehn Jul 11, 2025
c57f259
Merge branch 'main' into entity-manager
rklaehn Jul 23, 2025
331a3aa
Merge branch 'entity-manager' into slim-down-state
rklaehn Jul 23, 2025
e2b76fb
Merge branch 'slim-down-state' into remove-slot-mutex
rklaehn Jul 23, 2025
42bbbec
Merge branch 'main' into entity-manager
rklaehn Jul 24, 2025
b595923
Merge branch 'entity-manager' into slim-down-state
rklaehn Jul 24, 2025
6d39d40
Merge branch 'slim-down-state' into remove-slot-mutex
rklaehn Jul 24, 2025
d8847ea
Add wait_idle api call.
rklaehn Jul 24, 2025
dcbd83b
Use the shiny new wait_idle in another racy test.
rklaehn Jul 24, 2025
1c62546
remove stray println!
rklaehn Jul 24, 2025
c79a21e
Add more detailed logging for the entty manager proptest
rklaehn Jul 25, 2025
71bf60b
clippy
rklaehn Jul 25, 2025
91af79e
Merge branch 'main' into entity-manager
rklaehn Aug 5, 2025
21dc789
Merge branch 'entity-manager' into slim-down-state
rklaehn Aug 5, 2025
160cfca
Merge branch 'slim-down-state' into remove-slot-mutex
rklaehn Aug 5, 2025
e028496
Merge branch 'main' into slim-down-state
rklaehn Aug 5, 2025
dba9a4c
Merge branch 'slim-down-state' into remove-slot-mutex
rklaehn Aug 5, 2025
1be113a
Update comment to remark that Drop is no longer implemented.
rklaehn Aug 5, 2025
7a9be84
Change panic! into unreachable!
rklaehn Aug 5, 2025
4a09c64
Merge branch 'slim-down-state' into remove-slot-mutex
rklaehn Aug 5, 2025
4529be6
Remove debug code
rklaehn Aug 5, 2025
f0f218d
Address review comments
rklaehn Aug 6, 2025
1f42698
remove parallelism for cross tests again
rklaehn Aug 6, 2025
c9e0aa2
Merge branch 'main' into remove-slot-mutex
rklaehn Aug 6, 2025
5b3953d
Use iroh main
rklaehn Aug 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ iroh-base = "0.90"
reflink-copy = "0.1.24"
irpc = { version = "0.5.0", features = ["rpc", "quinn_endpoint_setup", "message_spans", "stream", "derive"], default-features = false }
iroh-metrics = { version = "0.35" }
hashlink = "0.10.0"
futures-buffered = "0.2.11"

[dev-dependencies]
clap = { version = "4.5.31", features = ["derive"] }
Expand All @@ -60,6 +58,7 @@ testresult = "0.4.1"
tracing-subscriber = { version = "0.3.19", features = ["fmt"] }
tracing-test = "0.2.5"
walkdir = "2.5.0"
atomic_refcell = "0.1.13"

[features]
hide-proto-docs = []
Expand Down
24 changes: 12 additions & 12 deletions src/api/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Blobs {
.await
}

pub fn add_slice(&self, data: impl AsRef<[u8]>) -> AddProgress {
pub fn add_slice(&self, data: impl AsRef<[u8]>) -> AddProgress<'_> {
let options = ImportBytesRequest {
data: Bytes::copy_from_slice(data.as_ref()),
format: crate::BlobFormat::Raw,
Expand All @@ -136,7 +136,7 @@ impl Blobs {
self.add_bytes_impl(options)
}

pub fn add_bytes(&self, data: impl Into<bytes::Bytes>) -> AddProgress {
pub fn add_bytes(&self, data: impl Into<bytes::Bytes>) -> AddProgress<'_> {
let options = ImportBytesRequest {
data: data.into(),
format: crate::BlobFormat::Raw,
Expand All @@ -145,7 +145,7 @@ impl Blobs {
self.add_bytes_impl(options)
}

pub fn add_bytes_with_opts(&self, options: impl Into<AddBytesOptions>) -> AddProgress {
pub fn add_bytes_with_opts(&self, options: impl Into<AddBytesOptions>) -> AddProgress<'_> {
let options = options.into();
let request = ImportBytesRequest {
data: options.data,
Expand All @@ -155,7 +155,7 @@ impl Blobs {
self.add_bytes_impl(request)
}

fn add_bytes_impl(&self, options: ImportBytesRequest) -> AddProgress {
fn add_bytes_impl(&self, options: ImportBytesRequest) -> AddProgress<'_> {
trace!("{options:?}");
let this = self.clone();
let stream = Gen::new(|co| async move {
Expand All @@ -180,7 +180,7 @@ impl Blobs {
AddProgress::new(self, stream)
}

pub fn add_path_with_opts(&self, options: impl Into<AddPathOptions>) -> AddProgress {
pub fn add_path_with_opts(&self, options: impl Into<AddPathOptions>) -> AddProgress<'_> {
let options = options.into();
self.add_path_with_opts_impl(ImportPathRequest {
path: options.path,
Expand All @@ -190,7 +190,7 @@ impl Blobs {
})
}

fn add_path_with_opts_impl(&self, options: ImportPathRequest) -> AddProgress {
fn add_path_with_opts_impl(&self, options: ImportPathRequest) -> AddProgress<'_> {
trace!("{:?}", options);
let client = self.client.clone();
let stream = Gen::new(|co| async move {
Expand All @@ -215,7 +215,7 @@ impl Blobs {
AddProgress::new(self, stream)
}

pub fn add_path(&self, path: impl AsRef<Path>) -> AddProgress {
pub fn add_path(&self, path: impl AsRef<Path>) -> AddProgress<'_> {
self.add_path_with_opts(AddPathOptions {
path: path.as_ref().to_owned(),
mode: ImportMode::Copy,
Expand All @@ -226,7 +226,7 @@ impl Blobs {
pub async fn add_stream(
&self,
data: impl Stream<Item = io::Result<Bytes>> + Send + Sync + 'static,
) -> AddProgress {
) -> AddProgress<'_> {
let inner = ImportByteStreamRequest {
format: crate::BlobFormat::Raw,
scope: Scope::default(),
Expand Down Expand Up @@ -521,7 +521,7 @@ pub struct Batch<'a> {
}

impl<'a> Batch<'a> {
pub fn add_bytes(&self, data: impl Into<Bytes>) -> BatchAddProgress {
pub fn add_bytes(&self, data: impl Into<Bytes>) -> BatchAddProgress<'_> {
let options = ImportBytesRequest {
data: data.into(),
format: crate::BlobFormat::Raw,
Expand All @@ -530,7 +530,7 @@ impl<'a> Batch<'a> {
BatchAddProgress(self.blobs.add_bytes_impl(options))
}

pub fn add_bytes_with_opts(&self, options: impl Into<AddBytesOptions>) -> BatchAddProgress {
pub fn add_bytes_with_opts(&self, options: impl Into<AddBytesOptions>) -> BatchAddProgress<'_> {
let options = options.into();
BatchAddProgress(self.blobs.add_bytes_impl(ImportBytesRequest {
data: options.data,
Expand All @@ -539,7 +539,7 @@ impl<'a> Batch<'a> {
}))
}

pub fn add_slice(&self, data: impl AsRef<[u8]>) -> BatchAddProgress {
pub fn add_slice(&self, data: impl AsRef<[u8]>) -> BatchAddProgress<'_> {
let options = ImportBytesRequest {
data: Bytes::copy_from_slice(data.as_ref()),
format: crate::BlobFormat::Raw,
Expand All @@ -548,7 +548,7 @@ impl<'a> Batch<'a> {
BatchAddProgress(self.blobs.add_bytes_impl(options))
}

pub fn add_path_with_opts(&self, options: impl Into<AddPathOptions>) -> BatchAddProgress {
pub fn add_path_with_opts(&self, options: impl Into<AddPathOptions>) -> BatchAddProgress<'_> {
let options = options.into();
BatchAddProgress(self.blobs.add_path_with_opts_impl(ImportPathRequest {
path: options.path,
Expand Down
41 changes: 40 additions & 1 deletion src/api/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,15 @@ mod tests {
use testresult::TestResult;

use crate::{
api::blobs::Blobs,
protocol::{ChunkRangesSeq, GetRequest},
store::fs::{tests::INTERESTING_SIZES, FsStore},
store::{
fs::{
tests::{create_n0_bao, test_data, INTERESTING_SIZES},
FsStore,
},
mem::MemStore,
},
tests::{add_test_hash_seq, add_test_hash_seq_incomplete},
util::ChunkRangesExt,
};
Expand Down Expand Up @@ -1117,6 +1124,38 @@ mod tests {
Ok(())
}

async fn test_observe_partial(blobs: &Blobs) -> TestResult<()> {
let sizes = INTERESTING_SIZES;
for size in sizes {
let data = test_data(size);
let ranges = ChunkRanges::chunk(0);
let (hash, bao) = create_n0_bao(&data, &ranges)?;
blobs.import_bao_bytes(hash, ranges.clone(), bao).await?;
let bitfield = blobs.observe(hash).await?;
if size > 1024 {
assert_eq!(bitfield.ranges, ranges);
} else {
assert_eq!(bitfield.ranges, ChunkRanges::all());
}
}
Ok(())
}

#[tokio::test]
async fn test_observe_partial_mem() -> TestResult<()> {
let store = MemStore::new();
test_observe_partial(store.blobs()).await?;
Ok(())
}

#[tokio::test]
async fn test_observe_partial_fs() -> TestResult<()> {
let td = tempfile::tempdir()?;
let store = FsStore::load(td.path()).await?;
test_observe_partial(store.blobs()).await?;
Ok(())
}

#[tokio::test]
async fn test_local_info_hash_seq() -> TestResult<()> {
let sizes = INTERESTING_SIZES;
Expand Down
2 changes: 1 addition & 1 deletion src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl From<&[u8; 32]> for Hash {

impl PartialOrd for Hash {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.0.as_bytes().cmp(other.0.as_bytes()))
Some(self.cmp(other))
}
}

Expand Down
1 change: 1 addition & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use iroh_metrics::{Counter, MetricsGroup};

/// Enum of metrics for the module
#[allow(missing_docs)]
#[allow(dead_code)]
#[derive(Debug, Default, MetricsGroup)]
#[metrics(name = "iroh-blobs")]
pub struct Metrics {
Expand Down
Loading
Loading