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
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions torture/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions torture/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -186,6 +187,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
Expand Down Expand Up @@ -223,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<Output = ()> + Send + 'static,
Expand Down Expand Up @@ -339,6 +368,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);
Expand Down Expand Up @@ -501,6 +532,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<message::HashTableUtilization> {
// UNWRAP: `nomt` is always `Some` except recreation.
let nomt = self.nomt.as_ref().unwrap();
Expand Down
5 changes: 5 additions & 0 deletions torture/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -237,6 +240,8 @@ pub enum ToSupervisor {
QueryValue(Option<Value>),
/// 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),
}
6 changes: 6 additions & 0 deletions torture/src/supervisor/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
}
11 changes: 11 additions & 0 deletions torture/src/supervisor/comms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions torture/src/supervisor/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions torture/src/supervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
69 changes: 68 additions & 1 deletion torture/src/supervisor/workload.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -35,15 +37,45 @@ struct Snapshot {
sync_seqn: u32,
/// The state of the database at this snapshot.
state: OrdMap<[u8; 32], Option<Vec<u8>>>,
/// The hash of every value present in `state`, kept to compute the expected root.
value_hashes: OrdMap<[u8; 32], [u8; 32]>,
}

impl Snapshot {
fn empty() -> Self {
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<Vec<u8>>) {
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::<Blake3Hasher>(
0,
self.value_hashes
.iter()
.map(|(key, value_hash)| (*key, *value_hash)),
|_| {},
)
}
}

enum Resources {
Expand Down Expand Up @@ -182,6 +214,7 @@ impl Workload {
workload_dir: TempDir,
workload_id: u64,
ensure_snapshot: bool,
max_iterations: Option<usize>,
assigned_disk: u64,
assigned_memory: u64,
) -> Self {
Expand All @@ -192,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,
Expand Down Expand Up @@ -444,6 +480,7 @@ impl Workload {
} else {
self.ensure_changeset_reverted(&changeset).await?;
}
self.ensure_root().await?;

Ok(())
}
Expand Down Expand Up @@ -625,6 +662,7 @@ impl Workload {
}
}

self.ensure_root().await?;
self.ensure_snapshot_validity().await?;
Ok(())
}
Expand Down Expand Up @@ -686,6 +724,7 @@ impl Workload {

self.reconcile_hashtable_growth(old_hashtable_buckets, new_hashtable_buckets)
.await?;
self.ensure_root().await?;
self.ensure_snapshot_validity().await?;
Ok(())
}
Expand Down Expand Up @@ -847,6 +886,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(());
Expand Down Expand Up @@ -1008,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()
Expand Down Expand Up @@ -1052,7 +1118,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 {
Expand Down Expand Up @@ -1213,6 +1279,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) {
Expand Down