From a64e330cfc39b8cf2591b9e6d7aa4e47d442e062 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Tue, 24 Nov 2026 23:29:42 +0100 Subject: [PATCH 1/3] torture: open the database with the generated commit_concurrency and io_workers The supervisor draws commit_concurrency from 1..=64 and io_workers from 1..=32 for every workload and sends them in the open request, but the agent never passed them to Options. Every workload ran with the defaults, one commit worker and three I/O workers, so torture never exercised a multi-worker commit. Co-Authored-By: Claude Fable 5.2 --- torture/src/agent.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torture/src/agent.rs b/torture/src/agent.rs index 2220d5bffd..56ee038eb8 100644 --- a/torture/src/agent.rs +++ b/torture/src/agent.rs @@ -339,6 +339,8 @@ impl Agent { o.path(workdir.join("nomt_db")); o.bitbox_seed(open_params.bitbox_seed); o.hashtable_buckets(open_params.hashtable_buckets); + o.commit_concurrency(open_params.commit_concurrency); + o.io_workers(open_params.io_workers); o.warm_up(open_params.warm_up); o.preallocate_ht(open_params.preallocate_ht); o.page_cache_size(open_params.page_cache_size); From 403ea8722e0b5914d1c4e04ab05e406da03b3821 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Tue, 24 Nov 2026 23:29:55 +0100 Subject: [PATCH 2/3] torture: check the root against a trie built from the expected state After a crash torture compared the sync sequence number and, when asked to, the values. Values are read from the beatree. Nothing looked at the merkle pages, which are written and recovered on their own path: the hash table and its WAL. A database with every value right and a wrong root passed. The agent now reports its root, and the supervisor compares it with the root of a trie built from scratch out of the state it expects, after every commit, rollback and hash table growth, crashed or not. The snapshot keeps the hash of each value, so the expected root costs two hashes per key and no value is hashed twice. Right after opening, the root is read from the root page alone. A wrong page below it shows in the root of a later commit that goes through it. Co-Authored-By: Claude Fable 5.2 --- Cargo.lock | 1 + torture/Cargo.toml | 1 + torture/src/agent.rs | 15 ++++++++ torture/src/message.rs | 5 +++ torture/src/supervisor/comms.rs | 11 ++++++ torture/src/supervisor/workload.rs | 60 +++++++++++++++++++++++++++++- 6 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d5e4763e0d..3cf4f613d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1801,6 +1801,7 @@ dependencies = [ "libc", "nix 0.29.0", "nomt", + "nomt-core", "rand", "rand_distr", "rand_pcg", diff --git a/torture/Cargo.toml b/torture/Cargo.toml index e1c47bdfd5..574c3d6e39 100644 --- a/torture/Cargo.toml +++ b/torture/Cargo.toml @@ -10,6 +10,7 @@ anyhow.workspace = true cfg-if.workspace = true serde.workspace = true nomt = { path = "../nomt" } +nomt-core = { path = "../core" } tokio.workspace = true tokio-util.workspace = true tokio-stream.workspace = true diff --git a/torture/src/agent.rs b/torture/src/agent.rs index 56ee038eb8..b167cb090b 100644 --- a/torture/src/agent.rs +++ b/torture/src/agent.rs @@ -186,6 +186,15 @@ pub async fn run(input: UnixStream) -> Result<()> { }) .await?; } + ToAgent::QueryRoot => { + let root = agent.query_root(); + stream + .send(Envelope { + reqno, + message: ToSupervisor::Root(root), + }) + .await?; + } ToAgent::QueryHashTableUtilization => { let utilization = agent.hash_table_utilization()?; stream @@ -503,6 +512,12 @@ impl Agent { nomt.sync_seqn() } + fn query_root(&mut self) -> [u8; 32] { + // UNWRAP: `nomt` is always `Some` except recreation. + let nomt = self.nomt.as_ref().unwrap(); + nomt.root().into_inner() + } + fn hash_table_utilization(&mut self) -> Result { // UNWRAP: `nomt` is always `Some` except recreation. let nomt = self.nomt.as_ref().unwrap(); diff --git a/torture/src/message.rs b/torture/src/message.rs index 01fd06a132..8128a08c9f 100644 --- a/torture/src/message.rs +++ b/torture/src/message.rs @@ -167,6 +167,9 @@ pub enum ToAgent { /// The supervisor sends this message to the child process to query the current sequence number /// of the database. QuerySyncSeqn, + /// The supervisor sends this message to the child process to query the current root of the + /// database. + QueryRoot, /// The supervisor sends this message to the child process to query hash table utilization. QueryHashTableUtilization, /// The supervisor sends this message to the child process to indicate that the child should @@ -237,6 +240,8 @@ pub enum ToSupervisor { QueryValue(Option), /// The response to a query for the current sequence number of the database. SyncSeqn(u32), + /// The response to a query for the current root of the database. + Root([u8; 32]), /// The response to a query for hash table utilization. HashTableUtilizationResponse(HashTableUtilization), } diff --git a/torture/src/supervisor/comms.rs b/torture/src/supervisor/comms.rs index a4ec44c783..2c75718dad 100644 --- a/torture/src/supervisor/comms.rs +++ b/torture/src/supervisor/comms.rs @@ -107,6 +107,17 @@ impl RequestResponse { } } + /// Requests the current root from the agent. + pub async fn send_query_root(&self) -> anyhow::Result<[u8; 32]> { + match self + .send_request(crate::message::ToAgent::QueryRoot) + .await? + { + crate::message::ToSupervisor::Root(root) => Ok(root), + resp => bail!("unexpected response: {:?}", resp), + } + } + /// Requests the current hash table utilization from the agent. pub async fn send_query_hash_table_utilization( &self, diff --git a/torture/src/supervisor/workload.rs b/torture/src/supervisor/workload.rs index d3e75e5f0d..1db8b1a8f9 100644 --- a/torture/src/supervisor/workload.rs +++ b/torture/src/supervisor/workload.rs @@ -1,5 +1,7 @@ use anyhow::Result; use imbl::OrdMap; +use nomt::hasher::Blake3Hasher; +use nomt_core::hasher::ValueHasher as _; use rand::{distr::weighted::WeightedIndex, prelude::*}; use std::{ collections::HashSet, @@ -35,6 +37,8 @@ struct Snapshot { sync_seqn: u32, /// The state of the database at this snapshot. state: OrdMap<[u8; 32], Option>>, + /// The hash of every value present in `state`, kept to compute the expected root. + value_hashes: OrdMap<[u8; 32], [u8; 32]>, } impl Snapshot { @@ -42,8 +46,36 @@ impl Snapshot { Self { sync_seqn: 0, state: OrdMap::new(), + value_hashes: OrdMap::new(), } } + + /// Record a change of a key, `None` being a deletion. + fn set(&mut self, key: [u8; 32], value: Option>) { + match value { + Some(ref value) => { + self.value_hashes + .insert(key, Blake3Hasher::hash_value(value)); + } + None => { + self.value_hashes.remove(&key); + } + } + self.state.insert(key, value); + } + + /// The root of a trie that holds exactly the values of this snapshot. + /// + /// It is built from scratch, independently of how the database reached this state. + fn root(&self) -> [u8; 32] { + nomt_core::update::build_trie::( + 0, + self.value_hashes + .iter() + .map(|(key, value_hash)| (*key, *value_hash)), + |_| {}, + ) + } } enum Resources { @@ -444,6 +476,7 @@ impl Workload { } else { self.ensure_changeset_reverted(&changeset).await?; } + self.ensure_root().await?; Ok(()) } @@ -625,6 +658,7 @@ impl Workload { } } + self.ensure_root().await?; self.ensure_snapshot_validity().await?; Ok(()) } @@ -686,6 +720,7 @@ impl Workload { self.reconcile_hashtable_growth(old_hashtable_buckets, new_hashtable_buckets) .await?; + self.ensure_root().await?; self.ensure_snapshot_validity().await?; Ok(()) } @@ -847,6 +882,28 @@ impl Workload { Ok(()) } + /// Ensure that the root of the database is the root of a trie built from scratch out of the + /// committed state. + /// + /// The values are read from the beatree and the root is computed from the merkle pages, + /// which are written and recovered separately. No other check looks at the merkle pages. + /// Right after opening, the root is read from the root page alone; the pages below it show + /// in the root of a later commit that goes through them. + async fn ensure_root(&self) -> anyhow::Result<()> { + let root = self.rr().send_query_root().await?; + let expected_root = self.committed.root(); + if root != expected_root { + return Err(anyhow::anyhow!( + "Unexpected root at sync_seqn {} with {} keys,\n expected: {},\n found: {}", + self.committed.sync_seqn, + self.committed.value_hashes.len(), + hex::encode(expected_root), + hex::encode(root), + )); + } + Ok(()) + } + async fn ensure_snapshot_validity(&mut self) -> anyhow::Result<()> { if !self.config.should_ensure_snapshot() && !self.config.sample_snapshot { return Ok(()); @@ -1052,7 +1109,7 @@ impl Workload { break; } - snapshot.state.insert(*change.key(), change.value()); + snapshot.set(*change.key(), change.value()); changes.push(change); if used_keys.len() + new_keys.len() >= changeset_size { @@ -1213,6 +1270,7 @@ impl Workload { // The application of a rollback counts as increased sync_seq. self.committed.sync_seqn += 1; self.committed.state = snapshot.state; + self.committed.value_hashes = snapshot.value_hashes; } fn commit(&mut self, snapshot: Snapshot) { From b9cd2f9aa6214929934bef4f6a555ff286eb88cc Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Tue, 24 Nov 2026 23:30:08 +0100 Subject: [PATCH 3/3] ci: run three torture workloads Nothing ran torture: not CI, not a script. The new job builds it in release mode and runs seeds 6, 7 and 8 for at most 20 iterations each, with every value and the root checked after each rollback and growth. The three take two minutes on a 32-core machine. Three things kept `torture run` from working as a CI step: - A failed workload was printed and the process exited with 0. It now exits with an error. - The length of a workload came from the assigned disk space alone. `--max-iterations` bounds it. - The agent crashes with abort. Where core dumps are collected, dumping it took longer than the five seconds the supervisor waits, and the workload failed with "agent did not die": every run of seed 6 under systemd-coredump. The agent now sets its core limit to zero. `run` also logs the configuration it derived from the seed. A seed fixes the configuration, not the moment a crash lands, so a failure may not repeat. None of the three seeds uses trickfs; the job installs FUSE so that one that does can be added. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++++ torture/src/agent.rs | 20 ++++++++++++++++++++ torture/src/supervisor/cli.rs | 6 ++++++ torture/src/supervisor/config.rs | 5 +++++ torture/src/supervisor/mod.rs | 9 +++++++++ torture/src/supervisor/workload.rs | 9 +++++++++ 6 files changed, 76 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d705813d02..57e32acc1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,33 @@ jobs: - run: cargo test --verbose --workspace # No workspace member enables these features, so `--workspace` doesn't build the decoders. - run: cargo test --verbose -p nomt-core --features borsh,serde + torture: + name: NOMT - torture + runs-on: ubuntu-26.04 + timeout-minutes: 30 + steps: + - uses: actions/checkout@v5 + - uses: ./.github/actions/install-fuse + - uses: dtolnay/rust-toolchain@stable + - run: cargo build --release --locked -p torture + # Each workload commits, rolls back and grows the hash table, crashing the database in + # between, and checks every value and the root against a model. + # + # A seed fixes the configuration of a workload, but not the moment a crash lands. These + # seeds were picked for the features they turn on; none of them uses trickfs. + # 6: updates, commit crashes, hash table growth with crashes + # 7: deletions, commit crashes, rollbacks with crashes + # 8: reads, updates, deletions, overflow values, commit crashes, rollbacks, growth + - name: Run torture workloads + run: | + for seed in 6 7 8; do + ./target/release/torture run "$seed" \ + --assigned-disk $((4 << 30)) --assigned-memory $((2 << 30)) \ + --max-iterations 20 --ensure_snapshot --workdir "$RUNNER_TEMP" + done + - name: Print the log of the failed workload + if: failure() + run: tail -n 300 "$RUNNER_TEMP"/torture-*/log.txt benchtop_check: name: NOMT - check benchtop runs-on: ubuntu-26.04 diff --git a/torture/src/agent.rs b/torture/src/agent.rs index b167cb090b..5027574406 100644 --- a/torture/src/agent.rs +++ b/torture/src/agent.rs @@ -35,6 +35,7 @@ use crate::{ pub async fn run(input: UnixStream) -> Result<()> { let pid = std::process::id(); trace!(pid, "Child process started"); + disable_core_dumps(); let mut stream = Stream::new(input); let workdir = initialize(&mut stream).await?; @@ -232,6 +233,25 @@ pub async fn run(input: UnixStream) -> Result<()> { Ok(()) } +/// Make this process die without a core dump. +/// +/// The agent crashes on purpose, with `abort`. Where core dumps are collected (for example by +/// systemd-coredump), dumping an agent takes longer than the supervisor waits for it to die, +/// and the workload fails with "agent did not die". +fn disable_core_dumps() { + let no_core = libc::rlimit { + rlim_cur: 0, + rlim_max: 0, + }; + // A failure only brings back the slow crash, so it is not worth stopping the agent for. + if unsafe { libc::setrlimit(libc::RLIMIT_CORE, &no_core) } != 0 { + tracing::warn!( + "failed to disable core dumps: {}", + std::io::Error::last_os_error() + ); + } +} + /// Execute the provided `task` and make it crash after the specified `crash_delay`. async fn crash_task( task: impl Future + Send + 'static, diff --git a/torture/src/supervisor/cli.rs b/torture/src/supervisor/cli.rs index 3fb2de3cbd..0fd7957a8d 100644 --- a/torture/src/supervisor/cli.rs +++ b/torture/src/supervisor/cli.rs @@ -62,4 +62,10 @@ pub struct RunParams { /// This applies after every rollback. #[arg(long = "ensure_snapshot", default_value = "false")] pub ensure_snapshot: bool, + + /// Stop the workload after this many iterations. + /// + /// The number of iterations is otherwise derived from the assigned disk space alone. + #[arg(long)] + pub max_iterations: Option, } diff --git a/torture/src/supervisor/config.rs b/torture/src/supervisor/config.rs index b23982bd67..c293fe5107 100644 --- a/torture/src/supervisor/config.rs +++ b/torture/src/supervisor/config.rs @@ -295,6 +295,11 @@ impl WorkloadConfiguration { Self::new_inner(rng, avail_bytes).unwrap() } + /// Limit the number of iterations of the workload. + pub fn limit_iterations(&mut self, max_iterations: usize) { + self.iterations = self.iterations.min(max_iterations); + } + pub fn enable_ensure_snapshot(&mut self) { self.ensure_snapshot = true; } diff --git a/torture/src/supervisor/mod.rs b/torture/src/supervisor/mod.rs index 8f9b74a4ad..156fb7fccf 100644 --- a/torture/src/supervisor/mod.rs +++ b/torture/src/supervisor/mod.rs @@ -350,13 +350,22 @@ async fn run_single_workload( workload_dir, 0, /* workload_id */ run_params.ensure_snapshot, + run_params.max_iterations, run_params.assigned_disk, run_params.assigned_memory, ); + info!( + "Running workload, seed={}: {:#?}", + run_params.seed, + workload.config() + ); let maybe_flag = run_workload(cancel_token.clone(), run_params.seed, 0, workload).await?; if let Some(flag) = maybe_flag { print_flag(&flag); + // A scripted run, such as the one in CI, must see the failure in the exit code. + anyhow::bail!("workload failed, seed={}", run_params.seed); } + info!("Workload finished, seed={}", run_params.seed); Ok(()) } diff --git a/torture/src/supervisor/workload.rs b/torture/src/supervisor/workload.rs index 1db8b1a8f9..7370e3d4ac 100644 --- a/torture/src/supervisor/workload.rs +++ b/torture/src/supervisor/workload.rs @@ -214,6 +214,7 @@ impl Workload { workload_dir: TempDir, workload_id: u64, ensure_snapshot: bool, + max_iterations: Option, assigned_disk: u64, assigned_memory: u64, ) -> Self { @@ -224,6 +225,9 @@ impl Workload { if ensure_snapshot { config.enable_ensure_snapshot(); } + if let Some(max_iterations) = max_iterations { + config.limit_iterations(max_iterations); + } Self::new_inner( rng, @@ -1065,6 +1069,11 @@ impl Workload { self.workload_dir } + /// Return the configuration of the workload. + pub fn config(&self) -> &WorkloadConfiguration { + &self.config + } + /// Return the workload directory path. pub fn workload_dir_path(&self) -> PathBuf { self.workload_dir.path().to_path_buf()