From 5256f29a9ccfa97df6fdb221acb541f166456d8f Mon Sep 17 00:00:00 2001 From: Avinash Sajjanshetty Date: Wed, 10 Sep 2025 19:39:20 +0530 Subject: [PATCH] Add checksums behind a feature flag --- .github/workflows/rust.yml | 6 +++++- core/Cargo.toml | 1 + core/storage/checksum.rs | 17 +++++++++++++++++ tests/Cargo.toml | 1 + tests/integration/storage/mod.rs | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0eef76c70..d2c6f8edd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -42,10 +42,14 @@ jobs: run: | cargo test --features encryption --color=always --test integration_tests query_processing::encryption cargo test --features encryption --color=always --lib storage::encryption + - name: Test Checksums + run: | + cargo test --features checksum --color=always --lib storage::checksum + cargo test --features checksum --color=always --test integration_tests storage::checksum - name: Test env: RUST_LOG: ${{ runner.debug && 'turso_core::storage=trace' || '' }} - run: cargo test --verbose + run: cargo test --verbose --features checksum timeout-minutes: 20 clippy: diff --git a/core/Cargo.toml b/core/Cargo.toml index ce2025143..e28c64280 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -29,6 +29,7 @@ simulator = ["fuzz", "serde"] serde = ["dep:serde"] series = [] encryption = [] +checksum = [] [target.'cfg(target_os = "linux")'.dependencies] io-uring = { version = "0.7.5", optional = true } diff --git a/core/storage/checksum.rs b/core/storage/checksum.rs index 781ef7b7f..74cb2d518 100644 --- a/core/storage/checksum.rs +++ b/core/storage/checksum.rs @@ -1,3 +1,4 @@ +#![allow(unused_variables, dead_code)] use crate::{CompletionError, Result}; const CHECKSUM_PAGE_SIZE: usize = 4096; @@ -12,6 +13,21 @@ impl ChecksumContext { ChecksumContext {} } + #[cfg(not(feature = "checksum"))] + pub fn add_checksum_to_page(&self, _page: &mut [u8], _page_id: usize) -> Result<()> { + Ok(()) + } + + #[cfg(not(feature = "checksum"))] + pub fn verify_checksum( + &self, + _page: &mut [u8], + _page_id: usize, + ) -> std::result::Result<(), CompletionError> { + Ok(()) + } + + #[cfg(feature = "checksum")] pub fn add_checksum_to_page(&self, page: &mut [u8], _page_id: usize) -> Result<()> { if page.len() != CHECKSUM_PAGE_SIZE { return Ok(()); @@ -27,6 +43,7 @@ impl ChecksumContext { Ok(()) } + #[cfg(feature = "checksum")] pub fn verify_checksum( &self, page: &mut [u8], diff --git a/tests/Cargo.toml b/tests/Cargo.toml index fa3822122..6a30e7509 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -37,3 +37,4 @@ tracing = "0.1.41" [features] encryption = ["turso_core/encryption"] +checksum = ["turso_core/checksum"] diff --git a/tests/integration/storage/mod.rs b/tests/integration/storage/mod.rs index 8f222d1d2..eb366ee72 100644 --- a/tests/integration/storage/mod.rs +++ b/tests/integration/storage/mod.rs @@ -1 +1,2 @@ +#[cfg(feature = "checksum")] mod checksum;