From 62d0febdb64d96f3bacacea1251ab80d7da5de3d Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Thu, 10 Apr 2025 15:59:47 +0200 Subject: [PATCH] panic on corruption --- core/storage/btree.rs | 7 ++++++- stress/main.rs | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/storage/btree.rs b/core/storage/btree.rs index 7b722d348..31aa6b2f8 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -2534,6 +2534,7 @@ impl BTreeCursor { // Let's now make a in depth check that we in fact added all possible cells somewhere and they are not lost for (page_idx, page) in pages_to_balance_new.iter().enumerate() { let contents = page.get_contents(); + debug_validate_cells!(contents, self.usable_space() as u16); // Cells are distributed in order for cell_idx in 0..contents.cell_count() { let (cell_start, cell_len) = contents.cell_get_raw_region( @@ -4370,7 +4371,11 @@ fn free_cell_range( } } if removed_fragmentation > page.num_frag_free_bytes() { - return_corrupt!("Invalid fragmentation count"); + return_corrupt!(format!( + "Invalid fragmentation count. Had {} and removed {}", + page.num_frag_free_bytes(), + removed_fragmentation + )); } let frag = page.num_frag_free_bytes() - removed_fragmentation; page.write_u8(PAGE_HEADER_OFFSET_FRAGMENTED_BYTES_COUNT, frag); diff --git a/stress/main.rs b/stress/main.rs index 1dd0943c2..75a61c4ba 100644 --- a/stress/main.rs +++ b/stress/main.rs @@ -4,6 +4,7 @@ use anarchist_readable_name_generator_lib::readable_name_custom; use antithesis_sdk::random::{get_random, AntithesisRng}; use antithesis_sdk::*; use clap::Parser; +use core::panic; use hex; use limbo::Builder; use opts::Opts; @@ -417,7 +418,16 @@ async fn main() -> Result<(), Box> { for stmt in &plan.ddl_statements { println!("executing ddl {}", stmt); if let Err(e) = conn.execute(stmt, ()).await { - println!("Error creating table: {}", e); + match e { + limbo::Error::SqlExecutionFailure(e) => { + if e.contains("Corrupt database") { + panic!("Error creating table: {}", e); + } else { + println!("Error creating table: {}", e); + } + } + _ => panic!("Error creating table: {}", e), + } } } @@ -430,7 +440,16 @@ async fn main() -> Result<(), Box> { let sql = &plan.queries_per_thread[thread][query_index]; println!("executing: {}", sql); if let Err(e) = conn.execute(&sql, ()).await { - println!("Error: {}", e); + match e { + limbo::Error::SqlExecutionFailure(e) => { + if e.contains("Corrupt database") { + panic!("Error executing query: {}", e); + } else { + println!("Error executing query: {}", e); + } + } + _ => panic!("Error executing query: {}", e), + } } } Ok::<_, Box>(())