[thin_check (rust)] NodeVisitor only needs to see leaf nodes

This commit is contained in:
Joe Thornber 2020-08-20 10:55:38 +01:00
parent 936e06e132
commit a1c206b774
2 changed files with 48 additions and 65 deletions

View File

@ -147,7 +147,7 @@ pub fn unpack_node<V: Unpack>(
//------------------------------------------ //------------------------------------------
pub trait NodeVisitor<V: Unpack> { pub trait NodeVisitor<V: Unpack> {
fn visit(&mut self, node: &Node<V>) -> Result<()>; fn visit(&mut self, header: &NodeHeader, keys: &[u64], values: &[V]) -> Result<()>;
} }
#[derive(Clone)] #[derive(Clone)]
@ -219,22 +219,27 @@ impl BTreeWalker {
NV: NodeVisitor<V>, NV: NodeVisitor<V>,
V: Unpack, V: Unpack,
{ {
use Node::*;
let bt = checksum::metadata_block_type(b.get_data()); let bt = checksum::metadata_block_type(b.get_data());
if bt != checksum::BT::NODE { if bt != checksum::BT::NODE {
return Err(anyhow!("checksum failed for node {}, {:?}", b.loc, bt)); return Err(anyhow!("checksum failed for node {}, {:?}", b.loc, bt));
} }
let node = unpack_node::<V>(&b.get_data(), self.ignore_non_fatal, is_root)?; let node = unpack_node::<V>(&b.get_data(), self.ignore_non_fatal, is_root)?;
visitor.visit(&node)?;
if let Node::Internal { match node {
Internal {
header: _h, header: _h,
keys: _k, keys: _k,
values, values,
} = node } => {
{
self.walk_nodes(visitor, &values)?; self.walk_nodes(visitor, &values)?;
} }
Leaf { header, keys, values } => {
visitor.visit(&header, &keys, &values)?;
}
}
Ok(()) Ok(())
} }
@ -281,19 +286,12 @@ impl<V> ValueCollector<V> {
} }
impl<V: Unpack + Clone> NodeVisitor<V> for ValueCollector<V> { impl<V: Unpack + Clone> NodeVisitor<V> for ValueCollector<V> {
fn visit(&mut self, node: &Node<V>) -> Result<()> { fn visit(&mut self, _h: &NodeHeader, keys: &[u64], values: &[V]) -> Result<()> {
if let Node::Leaf {
header: _h,
keys,
values,
} = node
{
for n in 0..keys.len() { for n in 0..keys.len() {
let k = keys[n]; let k = keys[n];
let v = values[n].clone(); let v = values[n].clone();
self.values.insert(k, v); self.values.insert(k, v);
} }
}
Ok(()) Ok(())
} }

View File

@ -9,7 +9,7 @@ use threadpool::ThreadPool;
use crate::checksum; use crate::checksum;
use crate::io_engine::{AsyncIoEngine, Block, IoEngine, SyncIoEngine}; use crate::io_engine::{AsyncIoEngine, Block, IoEngine, SyncIoEngine};
use crate::pdata::btree::{btree_to_map, btree_to_map_with_sm, BTreeWalker, Node, NodeVisitor}; use crate::pdata::btree::{btree_to_map, btree_to_map_with_sm, BTreeWalker, NodeHeader, NodeVisitor};
use crate::pdata::space_map::*; use crate::pdata::space_map::*;
use crate::pdata::unpack::*; use crate::pdata::unpack::*;
use crate::report::*; use crate::report::*;
@ -50,15 +50,9 @@ struct BottomLevelVisitor {
//------------------------------------------ //------------------------------------------
impl NodeVisitor<BlockTime> for BottomLevelVisitor { impl NodeVisitor<BlockTime> for BottomLevelVisitor {
fn visit(&mut self, node: &Node<BlockTime>) -> Result<()> { fn visit(&mut self, _h: &NodeHeader, _k: &[u64], values: &[BlockTime]) -> Result<()> {
// FIXME: do other checks // FIXME: do other checks
if let Node::Leaf {
header: _h,
keys: _k,
values,
} = node
{
if values.len() == 0 { if values.len() == 0 {
return Ok(()); return Ok(());
} }
@ -80,8 +74,6 @@ impl NodeVisitor<BlockTime> for BottomLevelVisitor {
} }
data_sm.inc(start, len)?; data_sm.inc(start, len)?;
}
Ok(()) Ok(())
} }
} }
@ -132,13 +124,7 @@ impl<'a> OverflowChecker<'a> {
} }
impl<'a> NodeVisitor<u32> for OverflowChecker<'a> { impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
fn visit(&mut self, node: &Node<u32>) -> Result<()> { fn visit(&mut self, _h: &NodeHeader, keys: &[u64], values: &[u32]) -> Result<()> {
if let Node::Leaf {
header: _h,
keys,
values,
} = node
{
for n in 0..keys.len() { for n in 0..keys.len() {
let k = keys[n]; let k = keys[n];
let v = values[n]; let v = values[n];
@ -148,7 +134,6 @@ impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
k, expected, v)); k, expected, v));
} }
} }
}
Ok(()) Ok(())
} }