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
23 changes: 20 additions & 3 deletions .github/workflows/nightly-dst.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
description: "Seeds per scenario per topology"
required: false
default: "500"
start_seed:
description: "Starting seed (defaults to a new window for each run)"
required: false

permissions:
contents: read
Expand All @@ -29,9 +32,23 @@ jobs:
- uses: Swatinem/rust-cache@v2

- name: Run multi-seed DST campaign
env:
DST_SEEDS: ${{ inputs.seeds || '500' }}
DST_START_SEED: ${{ inputs.start_seed }}
DST_TOPOLOGY: ${{ matrix.topology }}
run: |
SEEDS="${{ github.event.inputs.seeds || '500' }}"
mkdir -p dst-artifacts
start_seed="${DST_START_SEED:-$(((GITHUB_RUN_NUMBER - 1) * 500 + 1))}"
cargo run --release -p rustfs-dst-cli -- run \
--scenario all \
--topology "${{ matrix.topology }}" \
--seeds "$SEEDS"
--topology "$DST_TOPOLOGY" \
--start-seed "$start_seed" \
--seeds "$DST_SEEDS" \
--json > "dst-artifacts/$DST_TOPOLOGY.json"

- name: Upload campaign report
if: always()
uses: actions/upload-artifact@v4
with:
name: dst-campaign-${{ matrix.topology }}
path: dst-artifacts/*.json
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**RustFS DST** is the official Deterministic Simulation Testing (DST) framework, runtime trait abstraction layer, virtual fault simulator, and multi-seed correctness verifier for [RustFS](https://github.com/rustfs/rustfs).

Inspired by FoundationDB's Flow simulator, Tokio [`turmoil`](https://github.com/tokio-rs/turmoil), [`madsim`](https://github.com/madsim-rs/madsim), and [Antithesis](https://antithesis.com/), RustFS DST abstracts every source of non-determinism in a distributed storage engine behind clean Rust traits so complex multi-node failure modes execute deterministically inside a single process and reproduce bit-for-bit from a single `u64` seed.
Inspired by FoundationDB's Flow simulator, Tokio [`turmoil`](https://github.com/tokio-rs/turmoil), [`madsim`](https://github.com/madsim-rs/madsim), and [Antithesis](https://antithesis.com/), RustFS DST uses runtime traits to run a storage model against seeded faults. The scenarios execute `SimECStore` or the Turmoil quorum model. The [upstream adoption plan](docs/architecture.md) describes how to apply these runtime traits to RustFS itself.

## Core Architecture

Expand Down Expand Up @@ -38,8 +38,8 @@ Inspired by FoundationDB's Flow simulator, Tokio [`turmoil`](https://github.com/

## Verified Invariants

1. **Linearizability & Monotonic Read-After-Write**: Readers never observe a generation older than an acknowledged write or delete, even across degraded quorums (`W + R > N`).
2. **Bit-Exact Data Integrity**: Every readable object matches the exact SHA-256 of a submitted payload; silent bitrot up to the parity limit is detected and reconstructed transparently.
1. **Sequential S3 Read-After-Write Consistency**: GET responses must match a possible current version after acknowledged or indeterminate writes and deletes. LIST is checked against acknowledged live keys and their version metadata before repair.
2. **Bit-Exact Data Integrity**: Every readable object matches the exact SHA-256 of an acknowledged or indeterminate write for that version. Silent bitrot up to the parity limit is detected and reconstructed transparently.
3. **Crash Atomicity (Old-or-New-Never-Mixed)**: Abrupt power loss (`SimDiskIo::crash_and_reboot`) at any RustFS `xl.meta` commit window drops un-fsynced page-cache state without corrupting previously committed versions.
4. **Quorum Safety**: Writes fail closed on minority partitions and roll back partial drive writes cleanly; reply drops after remote apply are modeled as indeterminate outcomes.
5. **Distributed Lock Mutual Exclusion & Monotonic Fencing**: Monotonic-clock quorum leases remain immune to wall-clock skew jumps and issue strictly increasing fencing epochs.
Expand All @@ -51,7 +51,7 @@ Inspired by FoundationDB's Flow simulator, Tokio [`turmoil`](https://github.com/
# Run the full unit and integration test suite
cargo test --workspace

# Prove bit-for-bit determinism across every scenario
# Compare two passing reports for every scenario
cargo run --release -p rustfs-dst-cli -- verify-determinism --topology 4x4 --seed 2026

# Run a 100-seed parallel DST campaign on 4x4 and 3x2 topologies
Expand Down
148 changes: 124 additions & 24 deletions crates/rustfs-dst-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
use clap::{Parser, Subcommand};
use rayon::prelude::*;
use rustfs_dst_faults::probe::ProbeRegistry;
use rustfs_dst_sim::oracle::InvariantViolation;
use rustfs_dst_sim::scenarios::{ScenarioKind, ScenarioReport, run_scenario};
use rustfs_dst_sim::topology::TopologyKind;
use std::ops::RangeInclusive;
use std::panic::{UnwindSafe, catch_unwind};
use std::process::ExitCode;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -62,7 +65,7 @@ enum Command {
#[arg(long)]
seed: u64,
},
/// Execute each scenario twice with the same seed and verify identical SHA-256 trace hashes.
/// Execute each scenario twice with the same seed and compare both passing reports.
VerifyDeterminism {
#[arg(long, default_value = "4x4")]
topology: TopologyKind,
Expand All @@ -82,6 +85,46 @@ fn parse_scenarios(raw: &str) -> Result<Vec<ScenarioKind>, String> {
.collect::<Result<Vec<_>, _>>()
}

fn seed_range(start_seed: u64, count: u64) -> Result<RangeInclusive<u64>, &'static str> {
let last_offset = count.checked_sub(1).ok_or("--seeds must be at least 1")?;
let last_seed = start_seed
.checked_add(last_offset)
.ok_or("seed range exceeds u64::MAX")?;
Ok(start_seed..=last_seed)
}

fn run_case(
scenario: ScenarioKind,
topology: TopologyKind,
seed: u64,
simulate: impl FnOnce(ScenarioKind, TopologyKind, u64) -> ScenarioReport + UnwindSafe,
) -> ScenarioReport {
match catch_unwind(|| simulate(scenario, topology, seed)) {
Ok(report) => report,
Err(panic) => {
let detail = panic
.downcast_ref::<String>()
.map(String::as_str)
.or_else(|| panic.downcast_ref::<&str>().copied())
.unwrap_or("simulation panicked");
ScenarioReport {
scenario,
topology: topology.to_string(),
seed,
passed: false,
operations: 0,
trace_sha256: String::new(),
violations: vec![InvariantViolation {
invariant: "simulation_panic".to_string(),
key: "scenario".to_string(),
detail: detail.to_string(),
}],
probes: Default::default(),
}
}
}
}

fn main() -> ExitCode {
let cli = Cli::parse();
match cli.command {
Expand All @@ -97,7 +140,7 @@ fn main() -> ExitCode {
topology,
seed,
} => {
let report = run_scenario(scenario, topology, seed);
let report = run_case(scenario, topology, seed, run_scenario);
println!(
"{}",
serde_json::to_string_pretty(&report).expect("serialize ScenarioReport")
Expand All @@ -111,13 +154,19 @@ fn main() -> ExitCode {
Command::VerifyDeterminism { topology, seed } => {
let mut ok = true;
for scenario in ScenarioKind::ALL {
let r1 = run_scenario(scenario, topology, seed);
let r2 = run_scenario(scenario, topology, seed);
if !r1.passed || r1.trace_sha256 != r2.trace_sha256 {
let r1 = run_case(scenario, topology, seed, run_scenario);
let r2 = run_case(scenario, topology, seed, run_scenario);
if !r1.passed || r1 != r2 {
eprintln!(
"FAIL determinism check: scenario={scenario} topo={topology} seed={seed} passed={} h1={} h2={}",
r1.passed, r1.trace_sha256, r2.trace_sha256
"FAIL replay: scenario={scenario} topo={topology} seed={seed} passed_1={} passed_2={} trace_1={} trace_2={}",
r1.passed, r2.passed, r1.trace_sha256, r2.trace_sha256
);
for (replay, report) in [(1, r1), (2, r2)] {
eprintln!(
" replay {replay} operations={} probes={:?} violations={:?}",
report.operations, report.probes, report.violations
);
}
ok = false;
} else {
println!(
Expand Down Expand Up @@ -148,32 +197,53 @@ fn main() -> ExitCode {
return ExitCode::FAILURE;
}
};
let work: Vec<(ScenarioKind, u64)> = scenarios
.iter()
.flat_map(|&sc| (start_seed..start_seed + seeds).map(move |seed| (sc, seed)))
.collect();
let range = match seed_range(start_seed, seeds) {
Ok(range) => range,
Err(err) => {
eprintln!("error: {err}");
return ExitCode::FAILURE;
}
};
let Some((seeds_per_scenario, total_runs)) =
usize::try_from(seeds).ok().and_then(|count| {
count
.checked_mul(scenarios.len())
.map(|total| (count, total))
})
else {
eprintln!("error: campaign run count exceeds platform capacity");
return ExitCode::FAILURE;
};

let reports: Vec<ScenarioReport> = work
.par_iter()
.map(|&(sc, seed)| run_scenario(sc, topology, seed))
let reports: Vec<_> = (0..total_runs)
.into_par_iter()
.map(|index| {
let scenario = scenarios[index / seeds_per_scenario];
let seed = range.start() + (index % seeds_per_scenario) as u64;
run_case(scenario, topology, seed, run_scenario)
})
.collect();

let aggregate_probes = ProbeRegistry::new();
let mut failures = Vec::new();
let mut total_ops = 0u64;
for rep in &reports {
total_ops += rep.operations;
aggregate_probes.merge_from(&rep.probes);
if !rep.passed {
failures.push(rep);
for report in reports {
total_ops += report.operations;
aggregate_probes.merge_from(&report.probes);
if !report.passed {
failures.push(report);
}
}

if json {
let summary = serde_json::json!({
"topology": topology.to_string(),
"total_runs": reports.len(),
"passed_runs": reports.len() - failures.len(),
"scenarios": scenarios.iter().map(|scenario| scenario.slug()).collect::<Vec<_>>(),
"start_seed": range.start(),
"end_seed": range.end(),
"seeds_per_scenario": seeds,
"total_runs": total_runs,
"passed_runs": total_runs - failures.len(),
"failed_runs": failures.len(),
"total_operations": total_ops,
"probes": aggregate_probes.snapshot(),
Expand All @@ -185,9 +255,9 @@ fn main() -> ExitCode {
);
} else {
println!(
"RustFS DST Summary: topology={topology} runs={} passed={} failed={} ops={total_ops}",
reports.len(),
reports.len() - failures.len(),
"RustFS DST Summary: topology={topology} seeds={range:?} runs={} passed={} failed={} ops={total_ops}",
total_runs,
total_runs - failures.len(),
failures.len(),
);
let probes = aggregate_probes.snapshot();
Expand Down Expand Up @@ -227,3 +297,33 @@ fn main() -> ExitCode {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn rejects_empty_or_overflowing_campaigns_and_accepts_the_final_seed() {
assert!(seed_range(1, 0).is_err());
assert!(seed_range(u64::MAX, 2).is_err());
assert_eq!(
seed_range(u64::MAX, 1).unwrap().collect::<Vec<_>>(),
vec![u64::MAX]
);
}

#[test]
fn turns_a_scenario_panic_into_a_reproducible_failure_report() {
let scenario = ScenarioKind::ErasureQuorum;
let topology = TopologyKind::FourByFour;
let report = run_case(scenario, topology, 55, |_, _, _| {
panic!("initial write failed");
});
assert!(!report.passed);
assert_eq!(report.scenario, scenario);
assert_eq!(report.topology, topology.to_string());
assert_eq!(report.seed, 55);
assert_eq!(report.violations[0].invariant, "simulation_panic");
assert_eq!(report.violations[0].detail, "initial write failed");
}
}
Loading
Loading