format: v2 B-trees, dense groups and group listings over Storage
BTreeV2Header::parse_in, collect_btree_v2_records_in and find_btree_v2_records_in read one bounded window per node (its size is known from the parent before the node is read; a count stretched past node_size is checked against the end of the file first), with the whole-file bounds errors unchanged. With them, dense attributes, a SOHM B-tree index and huge fractal-heap objects no longer answer ContiguousStorageRequired, and group_v1/group_v2 listings, lookups and path resolution get *_in cores (resolve_group_children_in, resolve_child_in, resolve_path_any_in, ...). The &[u8] functions are thin wrappers, as in M1. The equivalence harness now fails on any ContiguousStorageRequired and compares v2 B-tree headers, records and descents, group listings, child lookups and paths; a unit test compares a two-level tree through a read_at-only storage truncated at every length and with every node byte flipped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -441,6 +441,57 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// A two-level tree read through a `read_at`-only storage gives what
|
||||
/// the slice gives — records, descents and errors — whole, truncated
|
||||
/// at every length, and with each byte of its nodes flipped, and each
|
||||
/// node costs one read.
|
||||
#[test]
|
||||
fn storage_reads_match_slice_reads() {
|
||||
use crate::btree_v2::{
|
||||
collect_btree_v2_records_in, find_btree_v2_records, find_btree_v2_records_in,
|
||||
};
|
||||
use crate::storage::CountingStorage;
|
||||
let (rs, n, base) = (11usize, 120usize, 64usize);
|
||||
let recs = records(n, rs);
|
||||
let tree = build_btree_v2(params(128, 11), &recs, base as u64, 8, 8).unwrap();
|
||||
let mut whole = vec![0u8; base];
|
||||
whole.extend_from_slice(&tree);
|
||||
let hdr = BTreeV2Header::parse(&whole, base, 8, 8).unwrap();
|
||||
assert!(hdr.depth >= 1, "{hdr:?}");
|
||||
let key = |r: &[u8]| u64::from_be_bytes(r[..8].try_into().unwrap());
|
||||
let mut files = Vec::new();
|
||||
for cut in base..=whole.len() {
|
||||
files.push(whole[..cut].to_vec());
|
||||
}
|
||||
for at in base..whole.len() {
|
||||
let mut bad = whole.clone();
|
||||
bad[at] ^= 0x5a;
|
||||
files.push(bad);
|
||||
}
|
||||
let mut ok = 0;
|
||||
for f in &files {
|
||||
let st = CountingStorage::new(f.clone());
|
||||
let want_h = BTreeV2Header::parse(f, base, 8, 8);
|
||||
let got_h = BTreeV2Header::parse_in(&st, base as u64, 8, 8);
|
||||
assert_eq!(format!("{got_h:?}"), format!("{want_h:?}"));
|
||||
// The nodes of the intact header, over each damaged file.
|
||||
let want = collect_btree_v2_records(f, &hdr, 8, 8);
|
||||
st.reset();
|
||||
let got = collect_btree_v2_records_in(&st, &hdr, 8, 8);
|
||||
assert_eq!(format!("{got:?}"), format!("{want:?}"));
|
||||
if want.is_ok() {
|
||||
ok += 1;
|
||||
assert!(st.reads() <= 1 + n as u64 / 3, "{} reads", st.reads());
|
||||
}
|
||||
for k in [0u64, 7, 60, 119, 500] {
|
||||
let want = find_btree_v2_records(f, &hdr, 8, &mut |r: &[u8]| key(r).cmp(&k));
|
||||
let got = find_btree_v2_records_in(&st, &hdr, 8, &mut |r: &[u8]| key(r).cmp(&k));
|
||||
assert_eq!(format!("{got:?}"), format!("{want:?}"));
|
||||
}
|
||||
}
|
||||
assert!(ok > 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_node_too_small_or_too_big_is_an_error() {
|
||||
assert!(build_btree_v2(params(16, 11), &records(1, 11), 0, 8, 8).is_err());
|
||||
|
||||
Reference in New Issue
Block a user