···11//! Consume a CAR from an AsyncRead, producing an ordered stream of records
2233-use crate::link::ObjectLink;
33+use crate::link::{ObjectLink, NodeThing, ThingKind};
44use crate::{
55 Bytes, HashMap, Rkey, Step,
66 disk::{DiskError, DiskStore},
···253253 blocks: mem_blocks,
254254 walker,
255255 process,
256256+ next_missing: None,
256257 },
257258 ))
258259 }
···276277 blocks: HashMap<ObjectLink, MaybeProcessedBlock>,
277278 walker: Walker,
278279 process: fn(Bytes) -> Bytes,
280280+ next_missing: Option<NodeThing>,
279281}
280282281283impl MemDriver {
282284 /// Step through the record outputs, in rkey order
283285 pub async fn next_chunk(&mut self, n: usize) -> Result<Step<BlockChunk>, DriveError> {
286286+ if let Some(missing) = &self.next_missing {
287287+ println!("other side???");
288288+ // TODO: make the walker finish walking to verify no more present blocks (oops sparse tree)
289289+ // HACK: just get the last rkey if it's there -- i think we might actually need to walk for it though
290290+ // ...and walk to verify rkey order of the rest of the nodes anyway?
291291+ return Ok(match &missing.kind {
292292+ ThingKind::ChildNode => Step::End(None),
293293+ ThingKind::Record(rkey) => Step::End(Some(rkey.clone())),
294294+ });
295295+ }
296296+ println!("stepping in...");
284297 let mut out = Vec::with_capacity(n);
298298+ // let mut err;
285299 for _ in 0..n {
286286- // walk as far as we can until we run out of blocks or find a record
287287- let Step::Value(output) = self.walker.step(&self.blocks, self.process)? else {
288288- break;
289289- };
290290- out.push(output);
300300+ match self.walker.step(&self.blocks, self.process) {
301301+ Ok(Step::Value(record)) => {
302302+ println!("got one! {record:?}");
303303+ out.push(record);
304304+ },
305305+ Ok(Step::End(None)) => break,
306306+ Ok(Step::End(_)) => todo!("actually this should be unreachable?"),
307307+ Err(WalkError::MissingBlock(missing)) => {
308308+ eprintln!("got missing so we should be bailing normally now");
309309+ self.next_missing = Some(*missing);
310310+ return Ok(Step::Value(out)) // nb: might be empty!
311311+ }
312312+ Err(other) => {
313313+ eprintln!("wait we errored??? {other:?}");
314314+ return Err(other.into())
315315+ },
316316+ }
291317 }
292318 if out.is_empty() {
293319 Ok(Step::End(None))