properly set last_checksum after recovering wal

We store `last_checksum` to do cumulative checksumming. After reading
wal for recovery, we didn't set last checksum properly in case there
were no frames so this cause us to not initialize last_checksum
properly.
This commit is contained in:
Pere Diaz Bou
2025-07-10 12:15:00 +02:00
parent 91fff1d2b3
commit 9258d33d8b
3 changed files with 46 additions and 2 deletions

View File

@@ -734,6 +734,34 @@ fn test_wal_bad_frame() -> anyhow::Result<()> {
Ok(())
}
#[test]
fn test_read_wal_dumb_no_frames() -> anyhow::Result<()> {
maybe_setup_tracing();
let _ = env_logger::try_init();
let db_path = {
let tmp_db = TempDatabase::new_empty(false);
let conn = tmp_db.connect_limbo();
conn.close()?;
let db_path = tmp_db.path.clone();
db_path
};
// Second connection must recover from the WAL file. Last checksum should be filled correctly.
{
let tmp_db = TempDatabase::new_with_existent(&db_path, false);
let conn = tmp_db.connect_limbo();
conn.execute("CREATE TABLE t0(x)")?;
conn.close()?;
}
{
let tmp_db = TempDatabase::new_with_existent(&db_path, false);
let conn = tmp_db.connect_limbo();
conn.execute("INSERT INTO t0(x) VALUES (1)")?;
conn.close()?;
}
Ok(())
}
fn run_query(tmp_db: &TempDatabase, conn: &Arc<Connection>, query: &str) -> anyhow::Result<()> {
run_query_core(tmp_db, conn, query, None::<fn(&Row)>)
}