[thin_check (rust)] Walk the top level and bottom level of the mapping tree separately
This commit is contained in:
parent
4ac428128a
commit
1d44025584
@ -6,6 +6,8 @@ use std::sync::{Arc, Mutex};
|
|||||||
use crate::block_manager::*;
|
use crate::block_manager::*;
|
||||||
use crate::checksum;
|
use crate::checksum;
|
||||||
|
|
||||||
|
// FIXME: check that keys are in ascending order between nodes.
|
||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|
||||||
pub trait ValueType {
|
pub trait ValueType {
|
||||||
@ -186,6 +188,23 @@ impl BTreeWalker {
|
|||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_with_seen(
|
||||||
|
engine: Arc<AsyncIoEngine>,
|
||||||
|
seen: Arc<Mutex<FixedBitSet>>,
|
||||||
|
ignore_non_fatal: bool,
|
||||||
|
) -> BTreeWalker {
|
||||||
|
{
|
||||||
|
let seen = seen.lock().unwrap();
|
||||||
|
assert_eq!(seen.len(), engine.get_nr_blocks() as usize);
|
||||||
|
}
|
||||||
|
|
||||||
|
BTreeWalker {
|
||||||
|
engine,
|
||||||
|
seen,
|
||||||
|
ignore_non_fatal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn walk_nodes<NV, V>(&mut self, visitor: &mut NV, bs: &Vec<u64>) -> Result<()>
|
fn walk_nodes<NV, V>(&mut self, visitor: &mut NV, bs: &Vec<u64>) -> Result<()>
|
||||||
where
|
where
|
||||||
NV: NodeVisitor<V>,
|
NV: NodeVisitor<V>,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
use fixedbitset::FixedBitSet;
|
||||||
use nom::{number::complete::*, IResult};
|
use nom::{number::complete::*, IResult};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@ -12,6 +13,31 @@ use crate::thin::superblock::*;
|
|||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|
||||||
|
struct TopLevelVisitor<'a> {
|
||||||
|
roots: &'a mut HashMap<u32, u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NodeVisitor<u64> for TopLevelVisitor<'a> {
|
||||||
|
fn visit(&mut self, w: &BTreeWalker, _b: &Block, node: &Node<u64>) -> Result<()> {
|
||||||
|
if let Node::Leaf {
|
||||||
|
header: _h,
|
||||||
|
keys,
|
||||||
|
values,
|
||||||
|
} = node
|
||||||
|
{
|
||||||
|
for n in 0..keys.len() {
|
||||||
|
let k = keys[n];
|
||||||
|
let root = values[n];
|
||||||
|
self.roots.insert(k as u32, root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
struct BlockTime {
|
struct BlockTime {
|
||||||
block: u64,
|
block: u64,
|
||||||
@ -38,54 +64,6 @@ impl ValueType for BlockTime {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TopLevelVisitor {}
|
|
||||||
|
|
||||||
impl NodeVisitor<u64> for TopLevelVisitor {
|
|
||||||
fn visit(&mut self, w: &BTreeWalker, _b: &Block, node: &Node<u64>) -> Result<()> {
|
|
||||||
if let Node::Leaf {
|
|
||||||
header: _h,
|
|
||||||
keys,
|
|
||||||
values,
|
|
||||||
} = node
|
|
||||||
{
|
|
||||||
let mut blocks = Vec::new();
|
|
||||||
let mut thin_ids = Vec::new();
|
|
||||||
let seen = w.seen.lock().unwrap();
|
|
||||||
for n in 0..keys.len() {
|
|
||||||
let b = values[n];
|
|
||||||
if !seen[b as usize] {
|
|
||||||
thin_ids.push(keys[n]);
|
|
||||||
blocks.push(Block::new(b));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
drop(seen);
|
|
||||||
|
|
||||||
w.engine.read_many(&mut blocks)?;
|
|
||||||
|
|
||||||
// FIXME: with a thread pool we need to return errors another way.
|
|
||||||
let nr_workers = 4;
|
|
||||||
let pool = ThreadPool::new(nr_workers);
|
|
||||||
|
|
||||||
let mut n = 0;
|
|
||||||
for b in blocks {
|
|
||||||
let thin_id = thin_ids[n];
|
|
||||||
n += 1;
|
|
||||||
|
|
||||||
let mut w = w.clone();
|
|
||||||
pool.execute(move || {
|
|
||||||
let mut v = BottomLevelVisitor {};
|
|
||||||
let result = w.walk_b(&mut v, &b).expect("walk failed"); // FIXME: return error
|
|
||||||
eprintln!("checked thin_dev {} -> {:?}", thin_id, result);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pool.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BottomLevelVisitor {}
|
struct BottomLevelVisitor {}
|
||||||
|
|
||||||
impl NodeVisitor<BlockTime> for BottomLevelVisitor {
|
impl NodeVisitor<BlockTime> for BottomLevelVisitor {
|
||||||
@ -141,12 +119,17 @@ impl DeviceVisitor {
|
|||||||
|
|
||||||
impl NodeVisitor<DeviceDetail> for DeviceVisitor {
|
impl NodeVisitor<DeviceDetail> for DeviceVisitor {
|
||||||
fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node<DeviceDetail>) -> Result<()> {
|
fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node<DeviceDetail>) -> Result<()> {
|
||||||
if let Node::Leaf {header: _h, keys, values} = node {
|
if let Node::Leaf {
|
||||||
for n in 0..keys.len() {
|
header: _h,
|
||||||
let k = keys[n] as u32;
|
keys,
|
||||||
let v = values[n].clone();
|
values,
|
||||||
self.devs.insert(k, v.clone());
|
} = node
|
||||||
}
|
{
|
||||||
|
for n in 0..keys.len() {
|
||||||
|
let k = keys[n] as u32;
|
||||||
|
let v = values[n].clone();
|
||||||
|
self.devs.insert(k, v.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -162,21 +145,42 @@ pub fn check(dev: &Path) -> Result<()> {
|
|||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?;
|
let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?;
|
||||||
eprintln!("{:?}", sb);
|
eprintln!("{:?}", sb);
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut visitor = DeviceVisitor::new();
|
let mut visitor = DeviceVisitor::new();
|
||||||
let mut w = BTreeWalker::new(engine.clone(), false);
|
let mut w = BTreeWalker::new(engine.clone(), false);
|
||||||
w.walk(&mut visitor, sb.details_root)?;
|
w.walk(&mut visitor, sb.details_root)?;
|
||||||
println!("found {} devices", visitor.devs.len());
|
println!("found {} devices", visitor.devs.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut roots = HashMap::new();
|
||||||
{
|
{
|
||||||
let mut visitor = TopLevelVisitor {};
|
let mut visitor = TopLevelVisitor { roots: &mut roots };
|
||||||
let mut w = BTreeWalker::new(engine.clone(), false);
|
let mut w = BTreeWalker::new(engine.clone(), false);
|
||||||
let _result = w.walk(&mut visitor, sb.mapping_root)?;
|
let _result = w.walk(&mut visitor, sb.mapping_root)?;
|
||||||
println!("read mapping tree in {} ms", now.elapsed().as_millis());
|
println!("read mapping tree in {} ms", now.elapsed().as_millis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: with a thread pool we need to return errors another way.
|
||||||
|
{
|
||||||
|
let nr_workers = 4;
|
||||||
|
let pool = ThreadPool::new(nr_workers);
|
||||||
|
let mut seen = Arc::new(Mutex::new(FixedBitSet::with_capacity(
|
||||||
|
engine.get_nr_blocks() as usize,
|
||||||
|
)));
|
||||||
|
|
||||||
|
for (thin_id, root) in roots {
|
||||||
|
let mut w = BTreeWalker::new_with_seen(engine.clone(), seen.clone(), false);
|
||||||
|
pool.execute(move || {
|
||||||
|
let mut v = BottomLevelVisitor {};
|
||||||
|
let result = w.walk(&mut v, root).expect("walk failed"); // FIXME: return error
|
||||||
|
eprintln!("checked thin_dev {} -> {:?}", thin_id, result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pool.join();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user