panic on corruption

This commit is contained in:
Pere Diaz Bou
2025-04-10 15:59:47 +02:00
parent b35d805a81
commit 62d0febdb6
2 changed files with 27 additions and 3 deletions

View File

@@ -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);

View File

@@ -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<dyn std::error::Error + Send + Sync>> {
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<dyn std::error::Error + Send + Sync>> {
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<dyn std::error::Error + Send + Sync>>(())