From 3279d8381ba8a9034d15ac5c16a6df7dd5b466af Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sat, 17 Apr 2021 00:05:08 +0800 Subject: [PATCH] [array_walker] Read multiple array blocks at once --- src/pdata/array_walker.rs | 52 +++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/pdata/array_walker.rs b/src/pdata/array_walker.rs index a9f033b..cd9d5e1 100644 --- a/src/pdata/array_walker.rs +++ b/src/pdata/array_walker.rs @@ -53,29 +53,39 @@ impl<'a, V: Unpack + Copy> NodeVisitor for BlockValueVisitor<'a, V> { let mut errs: Vec = Vec::new(); // TODO: check index continuity - // FIXME: use IoEngine::read_many() - for (n, index) in keys.iter().enumerate() { - // FIXME: count read errors on its parent (BTreeError::IoError) or on its location - // (ArrayError::IoError)? - let b = self.engine.read(values[n]).map_err(|_| btree::io_err(&path)); - if let Err(e) = b { - errs.push(e); - continue; - } - let b = b.unwrap(); - - path.push(values[n]); - match unpack_array_block::(&path, b.get_data()) { - Ok(array_block) => { - if let Err(e) = self.array_visitor.visit(*index, array_block) { - self.array_errs.lock().unwrap().push(e); - } - }, - Err(e) => { - self.array_errs.lock().unwrap().push(e); + match self.engine.read_many(values) { + Err(_) => { + // IO completely failed on all the child blocks + // FIXME: count read errors on its parent (BTreeError::IoError) or on its location + // (ArrayError::IoError)? + for (_i, _b) in values.iter().enumerate() { + errs.push(btree::io_err(&path)); // FIXME: add key_context + } + } + Ok(rblocks) => { + for (i, rb) in rblocks.into_iter().enumerate() { + match rb { + Err(_) => { + errs.push(btree::io_err(&path)); // FIXME: add key_context + }, + Ok(b) => { + path.push(b.loc); + match unpack_array_block::(&path, b.get_data()) { + Ok(array_block) => { + // FIXME: will the returned blocks be reordered? + if let Err(e) = self.array_visitor.visit(keys[i], array_block) { + self.array_errs.lock().unwrap().push(e); + } + }, + Err(e) => { + self.array_errs.lock().unwrap().push(e); + } + } + path.pop(); + }, + } } } - path.pop(); } // FIXME: duplicate to BTreeWalker::build_aggregrate()