Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,8 @@ unsafe impl Sync for Connection {}

impl Drop for Connection {
fn drop(&mut self) {
if !self.is_closed() {
// if connection wasn't properly closed, decrement the connection counter
self.db
.n_connections
.fetch_sub(1, std::sync::atomic::Ordering::SeqCst);
if let Err(e) = self.close() {
tracing::error!("Error closing connection: {}", e);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/query_processing/test_write_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,9 @@ fn test_wal_bad_frame() -> anyhow::Result<()> {
conn.execute("INSERT INTO t2(x) VALUES (1)")?;
conn.execute("INSERT INTO t3(x) VALUES (1)")?;
conn.execute("COMMIT")?;
// disalbe auto checkpoint so we keep the state of the WAL file on disk and prevent
// truncate checkpoint automatically on connection drop
conn.wal_auto_checkpoint_disable();
common::run_query_on_row(&tmp_db, &conn, "SELECT count(1) from t2", |row| {
let x = row.get::<i64>(0).unwrap();
assert_eq!(x, 1);
Expand All @@ -791,6 +794,7 @@ fn test_wal_bad_frame() -> anyhow::Result<()> {
assert_eq!(x, 1);
})
.unwrap();

// Now let's modify last frame record
let path = tmp_db.path.clone();
let path = path.with_extension("db-wal");
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/storage/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ fn test_per_page_checksum() -> anyhow::Result<()> {

{
let metadata = std::fs::metadata(&db_path)?;
assert_eq!(metadata.len(), 4096, "db file should be exactly 4096 bytes");
assert_eq!(metadata.len(), 8192, "db file should be exactly 8kb");
}

// let's test that page actually contains checksum bytes
{
let file_contents = std::fs::read(&db_path)?;
assert_eq!(
file_contents.len(),
4096,
8192,
"file contents should be 4096 bytes"
);

// split the page: first 4088 bytes are actual page, last 8 bytes are checksum
let actual_page = &file_contents[..4096 - 8];
let checksum_bytes = &file_contents[4096 - 8..];
let checksum_bytes = &file_contents[4096 - 8..4096];
let stored_checksum = u64::from_le_bytes(checksum_bytes.try_into().unwrap());

let expected_checksum = twox_hash::XxHash3_64::oneshot(actual_page);
Expand Down
Loading