···8899[dependencies]
1010bincode = { version = "2.0.1", features = ["serde"] }
1111-fjall = "3.0.0"
1111+fjall = { version = "2.11.2", default-features = false }
1212futures = "0.3.31"
1313futures-core = "0.3.31"
1414ipld-core = { version = "0.4.2", features = ["serde"] }
1515iroh-car = "0.5.1"
1616log = "0.4.28"
1717multibase = "0.9.2"
1818-rusqlite = "0.37.0"
1918serde = { version = "1.0.228", features = ["derive"] }
2019serde_bytes = "0.11.19"
2120serde_ipld_dagcbor = "0.6.4"
+5-1
examples/disk-read-file/main.rs
···3333 // in this example we only bother handling CARs that are too big for memory
3434 // `noop` helper means: do no block processing, store the raw blocks
3535 let driver = match DriverBuilder::new()
3636- .with_mem_limit_mb(10) // how much memory can be used before disk spill
3636+ .with_mem_limit_mb(32) // how much memory can be used before disk spill
3737 .load_car(reader)
3838 .await?
3939 {
···8181 }
82828383 log::info!("arrived! ({:?}) joining rx...", t0.elapsed());
8484+8585+ let driver = join.await?;
8686+8787+ driver.reset_store().await?;
84888589 log::info!("done. n={n} zeros={zeros}");
8690
···335335 // move store in and back out so we can manage lifetimes
336336 // dump mem blocks into the store
337337 store = tokio::task::spawn(async move {
338338- let mut writer = store.get_writer()?;
339339-340338 let kvs = self
341339 .mem_blocks
342340 .into_iter()
343341 .map(|(k, v)| Ok(encode(v).map(|v| (k.to_bytes(), v))?));
344342345345- writer.put_many(kvs)?;
343343+ store.put_many(kvs)?;
346344 Ok::<_, DriveError>(store)
347345 })
348346 .await??;
···350348 let (tx, mut rx) = mpsc::channel::<Vec<(Cid, MaybeProcessedBlock<T>)>>(1);
351349352350 let store_worker = tokio::task::spawn_blocking(move || {
353353- let mut writer = store.get_writer()?;
354354-355351 while let Some(chunk) = rx.blocking_recv() {
356352 let kvs = chunk
357353 .into_iter()
358354 .map(|(k, v)| Ok(encode(v).map(|v| (k.to_bytes(), v))?));
359359- writer.put_many(kvs)?;
355355+ store.put_many(kvs)?;
360356 }
361357 Ok::<_, DriveError>(store)
362358 }); // await later
···465461 // comes out again.
466462 let (state, res) = tokio::task::spawn_blocking(
467463 move || -> (BigState, Result<BlockChunk<T>, DriveError>) {
468468- let mut reader_res = state.store.get_reader();
469469- let reader: &mut _ = match reader_res {
470470- Ok(ref mut r) => r,
471471- Err(ref mut e) => {
472472- // unfortunately we can't return the error directly because
473473- // (for some reason) it's attached to the lifetime of the
474474- // reader?
475475- // hack a mem::swap so we can get it out :/
476476- let e_swapped = e.steal();
477477- // the pain: `state` *has to* outlive the reader
478478- drop(reader_res);
479479- return (state, Err(e_swapped.into()));
480480- }
481481- };
482482-483464 let mut out = Vec::with_capacity(n);
484465485466 for _ in 0..n {
486467 // walk as far as we can until we run out of blocks or find a record
487487- let step = match state.walker.disk_step(reader, process) {
468468+ let step = match state.walker.disk_step(&mut state.store, process) {
488469 Ok(s) => s,
489470 Err(e) => {
490490- // the pain: `state` *has to* outlive the reader
491491- drop(reader_res);
492471 return (state, Err(e.into()));
493472 }
494473 };
495474 match step {
496475 Step::Missing(cid) => {
497497- // the pain: `state` *has to* outlive the reader
498498- drop(reader_res);
499476 return (state, Err(DriveError::MissingBlock(cid)));
500477 }
501478 Step::Finish => break,
···503480 };
504481 }
505482506506- // `state` *has to* outlive the reader
507507- drop(reader_res);
508508-509483 (state, Ok::<_, DriveError>(out))
510484 },
511485 )
···529503 tx: mpsc::Sender<Result<BlockChunk<T>, DriveError>>,
530504 ) -> Result<(), mpsc::error::SendError<Result<BlockChunk<T>, DriveError>>> {
531505 let BigState { store, walker } = self.state.as_mut().expect("valid state");
532532- let mut reader = match store.get_reader() {
533533- Ok(r) => r,
534534- Err(e) => return tx.blocking_send(Err(e.into())),
535535- };
536506537507 loop {
538508 let mut out: BlockChunk<T> = Vec::with_capacity(n);
···540510 for _ in 0..n {
541511 // walk as far as we can until we run out of blocks or find a record
542512543543- let step = match walker.disk_step(&mut reader, self.process) {
513513+ let step = match walker.disk_step(store, self.process) {
544514 Ok(s) => s,
545515 Err(e) => return tx.blocking_send(Err(e.into())),
546516 };