Skip to content
Merged
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
2 changes: 1 addition & 1 deletion durable-storage/benches/avl_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn get_operations_batch(mut rng: &mut impl Rng, keys: &[Key], batch_size: usize)
}

cfg_if::cfg_if! {
if #[cfg(feature = "rocksdb")] {
if #[cfg(rocksdb)] {
use octez_riscv_durable_storage::persistence_layer::PersistenceLayer;
use octez_riscv_test_utils::TestableTmpdir;

Expand Down
35 changes: 35 additions & 0 deletions durable-storage/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2026 Nomadic Labs <contact@nomadic-labs.com>
//
// SPDX-License-Identifier: MIT

//! Emits cfg aliases for compound test/feature flags.
//!
//! - `test_utils`: alias for `feature = "unstable-test-utils"`. Thanks to the
//! self dev-dependency in `Cargo.toml`, the feature is always enabled in
//! test builds, so it is also equivalent to `any(test, feature = "unstable-test-utils")`.
//!
//! - `rocksdb`: alias for `feature = "rocksdb"`.
//!
//! - `rocksdb_test_utils`: alias for
//! `all(feature = "unstable-test-utils", feature = "rocksdb")`.

fn main() {
println!("cargo::rustc-check-cfg=cfg(test_utils)");
println!("cargo::rustc-check-cfg=cfg(rocksdb)");
println!("cargo::rustc-check-cfg=cfg(rocksdb_test_utils)");

let test_utils = std::env::var_os("CARGO_FEATURE_UNSTABLE_TEST_UTILS").is_some();
let rocksdb = std::env::var_os("CARGO_FEATURE_ROCKSDB").is_some();

if test_utils {
println!("cargo::rustc-cfg=test_utils");
}

if rocksdb {
println!("cargo::rustc-cfg=rocksdb");
}

if test_utils && rocksdb {
println!("cargo::rustc-cfg=rocksdb_test_utils");
}
}
2 changes: 1 addition & 1 deletion durable-storage/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use octez_riscv_data::hash::Hash;
/// from a `DirectoryManager`.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Encode, Decode, Hash)]
#[cfg_attr(
feature = "unstable-test-utils",
test_utils,
derive(serde::Serialize, serde::Deserialize),
serde(transparent)
)]
Expand Down
6 changes: 3 additions & 3 deletions durable-storage/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ pub(crate) mod tests {
})
}

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
fn new_persistent_database<KV>() -> (
tokio::runtime::Runtime,
KV::Keepalive,
Expand Down Expand Up @@ -1023,7 +1023,7 @@ pub(crate) mod tests {
(original.into_trace(), checked_out.into_trace())
});

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[test]
fn test_database_checkout_missing_root_blob_fails_operationally() {
use rocksdb::ColumnFamilyDescriptor;
Expand Down Expand Up @@ -2235,7 +2235,7 @@ pub(crate) mod tests {
database.into_trace()
});

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
kv_test!(
#[should_panic(expected = "trace mismatch")]
test_database_trace_comparison_detects_divergence,
Expand Down
14 changes: 7 additions & 7 deletions durable-storage/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum OperationalError {
#[error("Commit is missing data for the value of key {key:?}")]
CommitValueMissing { key: Key, source: Box<Error> },

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[error("Unable to create checkpoint: {error}")]
CheckpointCreationFailed { error: rocksdb::Error },

Expand All @@ -47,39 +47,39 @@ pub enum OperationalError {
error: std::io::Error,
},

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[error("Unable to open RocksDB: {error}")]
OpenRocksDbFailed { error: rocksdb::Error },

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[error("Failed to create column family {name}: {error}")]
ColumnFamilyCreationFailed { name: String, error: rocksdb::Error },

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[error("RocksDB lookup failed {key:?} in {column}: {error}")]
GetFailed {
column: String,
key: Vec<u8>,
error: rocksdb::Error,
},

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[error("RocksDB update failed {key:?} in {column}: {error}")]
PutFailed {
column: String,
key: Vec<u8>,
error: rocksdb::Error,
},

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[error("RocksDB delete failed {key:?} in {column}: {error}")]
DeleteFailed {
column: String,
key: Vec<u8>,
error: rocksdb::Error,
},

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[error("RocksDB merge failed {key:?} at {offset}: {error}")]
MergeFailed {
key: Vec<u8>,
Expand Down
4 changes: 2 additions & 2 deletions durable-storage/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ impl<'de, Context> BorrowDecode<'de, Context> for Key {
}
}

#[cfg(feature = "unstable-test-utils")]
#[cfg(test_utils)]
impl serde::Serialize for Key {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(&hex::encode(&self.0))
}
}

#[cfg(feature = "unstable-test-utils")]
#[cfg(test_utils)]
impl<'de> serde::Deserialize<'de> for Key {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
use serde::de::Error;
Expand Down
8 changes: 4 additions & 4 deletions durable-storage/src/merkle_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ mod tests {
key: Key,
},
Hash,
#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
Commit,
Clone,
}
Expand Down Expand Up @@ -502,7 +502,7 @@ mod tests {
assert_eq!(hash1, hash2);
}

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
Self::Commit => {
let options = crate::storage::StoreOptions::default()
.with_deep()
Expand Down Expand Up @@ -546,14 +546,14 @@ mod tests {

let hash = Just(TestCommand::Hash);

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
let commit = Just(TestCommand::Commit);

let clone = Just(TestCommand::Clone);

// The frequencies are chosen to reflect a typical workload.
cfg_if::cfg_if! {
if #[cfg(feature = "rocksdb")] {
if #[cfg(rocksdb)] {
proptest::prop_oneof![
250 => write,
250 => set,
Expand Down
2 changes: 1 addition & 1 deletion durable-storage/src/persistence_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! <rocksdb internals>
//! ```

#![cfg(feature = "rocksdb")]
#![cfg(rocksdb)]

use std::mem::ManuallyDrop;
use std::path::Path;
Expand Down
4 changes: 2 additions & 2 deletions durable-storage/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<KV: BackgroundKeyValueStore> Registry<KV, Normal> {
}

/// Get a [`Handle`] to the registry's runtime.
#[cfg(any(test, feature = "unstable-test-utils"))]
#[cfg(test_utils)]
pub(crate) fn handle(&self) -> &tokio::runtime::Handle {
self.inner.runtime.handle()
}
Expand Down Expand Up @@ -1536,7 +1536,7 @@ pub(super) mod tests {
});
}

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
#[cfg(test)]
mod rocksdb_tests {
use octez_riscv_data::mode::Normal;
Expand Down
14 changes: 7 additions & 7 deletions durable-storage/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub trait PersistentKeyValueStore: KeyValueStore + Sized {

#[cfg(test)]
cfg_if::cfg_if! {
if #[cfg(feature = "rocksdb")] {
if #[cfg(rocksdb)] {
/// Key-value store backend used when the `rocksdb` feature is enabled.
pub(crate) type TestKeyValueStore = crate::persistence_layer::PersistenceLayer;

Expand Down Expand Up @@ -148,7 +148,7 @@ cfg_if::cfg_if! {
}
}

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
impl TestKeyValueStoreSetup for crate::persistence_layer::PersistenceLayer {
type Keepalive = octez_riscv_test_utils::TestableTmpdir;

Expand Down Expand Up @@ -275,15 +275,15 @@ cfg_if::cfg_if! {
$setup
}

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
let rocksdb_setup =
_kv_test_setup::<$crate::persistence_layer::PersistenceLayer>();

let in_memory_setup =
_kv_test_setup::<$crate::storage::in_memory::InMemoryKeyValueStore>();

::proptest::proptest!(|($($arg in $strat),*)| {
#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
let rocksdb_trace = {
type $ty_name = $crate::persistence_layer::PersistenceLayer;
let $setup_values = &rocksdb_setup;
Expand All @@ -299,7 +299,7 @@ cfg_if::cfg_if! {
$body
};

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
::proptest::prop_assert_eq!(
rocksdb_trace, _in_memory_trace,
"trace mismatch"
Expand All @@ -322,7 +322,7 @@ cfg_if::cfg_if! {
$crate::repo::RegistryRepo,
{}

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
let rocksdb_trace = {
type $ty_name = $crate::persistence_layer::PersistenceLayer;
_bound_check::<$ty_name>();
Expand All @@ -337,7 +337,7 @@ cfg_if::cfg_if! {
$body
};

#[cfg(feature = "rocksdb")]
#[cfg(rocksdb)]
assert_eq!(
rocksdb_trace, _in_memory_trace,
"trace mismatch"
Expand Down
10 changes: 5 additions & 5 deletions durable-storage/src/storage/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use crate::errors::OperationalError;
/// Will never write to disk.
#[derive(Debug, Default, Clone)]
pub struct InMemoryRepo {
#[cfg(any(test, feature = "unstable-test-utils"))]
#[cfg(test_utils)]
commits: std::sync::Arc<RwLock<HashMap<crate::commit::CommitId, InMemorySnapshot>>>,

#[cfg(any(test, feature = "unstable-test-utils"))]
#[cfg(test_utils)]
registry_commits: std::sync::Arc<RwLock<HashMap<crate::commit::CommitId, Vec<u8>>>>,
}

Expand Down Expand Up @@ -196,14 +196,14 @@ impl KeyValueStore for InMemoryKeyValueStore {
}

/// Test-only snapshot repository for [`InMemoryRepo`]
#[cfg(any(test, feature = "unstable-test-utils"))]
#[cfg(test_utils)]
#[derive(Debug)]
struct InMemorySnapshot {
blobs: HashMap<Bytes, Bytes>,
values: HashMap<Bytes, BytesMut>,
}

#[cfg(any(test, feature = "unstable-test-utils"))]
#[cfg(test_utils)]
impl super::PersistentKeyValueStore for InMemoryKeyValueStore {
fn commit_to_path(&self, _path: &std::path::Path) -> Result<(), OperationalError> {
unimplemented!("In-memory store cannot commit to disk")
Expand Down Expand Up @@ -254,7 +254,7 @@ impl super::PersistentKeyValueStore for InMemoryKeyValueStore {
}
}

#[cfg(any(test, feature = "unstable-test-utils"))]
#[cfg(test_utils)]
impl crate::repo::RegistryRepo for InMemoryRepo {
fn read_registry_commit(
&self,
Expand Down
2 changes: 1 addition & 1 deletion durable-storage/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// SPDX-License-Identifier: MIT

#![cfg(any(test, feature = "unstable-test-utils"))]
#![cfg(test_utils)]

//! Shared utilities for end to end durable storage property-based tests
//!
Expand Down
2 changes: 1 addition & 1 deletion durable-storage/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use octez_riscv_durable_storage::test_helpers::run_operations;
use proptest::proptest;

cfg_if::cfg_if! {
if #[cfg(feature = "rocksdb")] {
if #[cfg(rocksdb)] {
use octez_riscv_durable_storage::persistence_layer::PersistenceLayer;
use octez_riscv_durable_storage::repo::DirectoryManager;
use octez_riscv_test_utils::TestableTmpdir;
Expand Down
Loading