[thin_check (rust)] NodeVisitor only needs to see leaf nodes
This commit is contained in:
parent
936e06e132
commit
a1c206b774
@ -147,7 +147,7 @@ pub fn unpack_node<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)]
|
||||
@ -219,22 +219,27 @@ impl BTreeWalker {
|
||||
NV: NodeVisitor<V>,
|
||||
V: Unpack,
|
||||
{
|
||||
use Node::*;
|
||||
|
||||
let bt = checksum::metadata_block_type(b.get_data());
|
||||
if bt != checksum::BT::NODE {
|
||||
return Err(anyhow!("checksum failed for node {}, {:?}", b.loc, bt));
|
||||
}
|
||||
|
||||
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,
|
||||
keys: _k,
|
||||
values,
|
||||
} = node
|
||||
{
|
||||
} => {
|
||||
self.walk_nodes(visitor, &values)?;
|
||||
}
|
||||
Leaf { header, keys, values } => {
|
||||
visitor.visit(&header, &keys, &values)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -281,19 +286,12 @@ impl<V> ValueCollector<V> {
|
||||
}
|
||||
|
||||
impl<V: Unpack + Clone> NodeVisitor<V> for ValueCollector<V> {
|
||||
fn visit(&mut self, node: &Node<V>) -> Result<()> {
|
||||
if let Node::Leaf {
|
||||
header: _h,
|
||||
keys,
|
||||
values,
|
||||
} = node
|
||||
{
|
||||
fn visit(&mut self, _h: &NodeHeader, keys: &[u64], values: &[V]) -> Result<()> {
|
||||
for n in 0..keys.len() {
|
||||
let k = keys[n];
|
||||
let v = values[n].clone();
|
||||
self.values.insert(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use threadpool::ThreadPool;
|
||||
|
||||
use crate::checksum;
|
||||
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::unpack::*;
|
||||
use crate::report::*;
|
||||
@ -50,15 +50,9 @@ struct 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
|
||||
|
||||
if let Node::Leaf {
|
||||
header: _h,
|
||||
keys: _k,
|
||||
values,
|
||||
} = node
|
||||
{
|
||||
if values.len() == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
@ -80,8 +74,6 @@ impl NodeVisitor<BlockTime> for BottomLevelVisitor {
|
||||
}
|
||||
|
||||
data_sm.inc(start, len)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -132,13 +124,7 @@ impl<'a> OverflowChecker<'a> {
|
||||
}
|
||||
|
||||
impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
|
||||
fn visit(&mut self, node: &Node<u32>) -> Result<()> {
|
||||
if let Node::Leaf {
|
||||
header: _h,
|
||||
keys,
|
||||
values,
|
||||
} = node
|
||||
{
|
||||
fn visit(&mut self, _h: &NodeHeader, keys: &[u64], values: &[u32]) -> Result<()> {
|
||||
for n in 0..keys.len() {
|
||||
let k = keys[n];
|
||||
let v = values[n];
|
||||
@ -148,7 +134,6 @@ impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
|
||||
k, expected, v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user