From 46104a283601ee56903285609d7d0f7c4fcd8d5a Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 2 Jan 2025 23:54:37 +0100 Subject: [PATCH] Update sanity checks --- crates/milli/src/update/facet/mod.rs | 47 +++++++++++++++++----------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/crates/milli/src/update/facet/mod.rs b/crates/milli/src/update/facet/mod.rs index b9481c739..922e7111d 100644 --- a/crates/milli/src/update/facet/mod.rs +++ b/crates/milli/src/update/facet/mod.rs @@ -720,24 +720,6 @@ pub(crate) fn sanity_checks( panic!("wrong parent left bound"); } - if let Some(current_parent_facet_value) = current_parent_facet_value { - if current_parent_facet_value.field_id != parent_facet_value.field_id { - panic!("wrong parent parent fid"); - } - if current_parent_facet_value.level + 1 != parent_facet_value.level { - panic!("wrong parent parent level"); - } - if current_parent_facet_value.left_bound < parent_facet_value.left_bound { - panic!("wrong parent parent level"); - } - } - - if let Some(current_parent_docids) = current_parent_docids { - if !current_parent_docids.bitmap.is_superset(&parent_docids.bitmap) { - panic!("missing docids in parent parent"); - } - } - if !leaf_docids.bitmap.is_subset(&parent_docids.bitmap) { panic!( "missing docids from leaf in parent, current_level={}, parent={}, child={}, missing={missing:?}, child_len={}, child={:?}", @@ -750,6 +732,30 @@ pub(crate) fn sanity_checks( ) } + if let Some(current_parent_facet_value) = current_parent_facet_value { + if current_parent_facet_value.field_id != parent_facet_value.field_id { + panic!("wrong parent parent fid"); + } + if current_parent_facet_value.level + 1 != parent_facet_value.level { + panic!("wrong parent parent level"); + } + if current_parent_facet_value.left_bound < parent_facet_value.left_bound { + panic!("wrong parent parent left bound"); + } + } + + if let Some(current_parent_docids) = current_parent_docids { + if !current_parent_docids.bitmap.is_subset(&parent_docids.bitmap) { + panic!("missing docids from intermediate node in parent, parent_level={}, parent={}, intermediate={}, missing={missing:?}, intermediate={:?}", + parent_facet_value.level, + facet_to_string(parent_facet_value.left_bound, facet_type), + facet_to_string(current_parent_facet_value.unwrap().left_bound, facet_type), + current_parent_docids.bitmap.clone(), + missing=current_parent_docids.bitmap - parent_docids.bitmap, + ); + } + } + current_parent_facet_value = Some(parent_facet_value); current_parent_docids = Some(parent_docids); } @@ -829,6 +835,9 @@ pub(crate) fn sanity_checks( fn facet_to_string(facet_value: &[u8], facet_type: FacetType) -> String { match facet_type { FacetType::String => bstr::BStr::new(facet_value).to_string(), - FacetType::Number => OrderedF64Codec::bytes_decode(facet_value).unwrap().to_string(), + FacetType::Number => match OrderedF64Codec::bytes_decode(facet_value) { + Ok(value) => value.to_string(), + Err(e) => format!("error: {e} (bytes: {facet_value:?}"), + }, } }