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
15 changes: 14 additions & 1 deletion crates/rustfs-dst-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ fn main() -> ExitCode {
}
}

let unhit = if seeds >= 5 {
aggregate_probes.unhit_must_hit()
} else {
Vec::new()
};

if json {
let summary = serde_json::json!({
"topology": topology.to_string(),
Expand All @@ -280,6 +286,7 @@ fn main() -> ExitCode {
"failed_runs": failures.len(),
"total_operations": total_ops,
"probes": aggregate_probes.snapshot(),
"unhit_must_hit_probes": unhit,
"failures": failures,
});
println!(
Expand All @@ -306,6 +313,12 @@ fn main() -> ExitCode {
);
}
}
for st in &unhit {
eprintln!(
"UNHIT MUST-HIT PROBE: [{:?}] {} had pass_count=0 across {seeds} seeds",
st.kind, st.id
);
}
for fail in &failures {
eprintln!(
"FAILURE: scenario={} topology={} seed={} -> repro: rustfs-dst repro --scenario {} --topology {} --seed {}",
Expand All @@ -322,7 +335,7 @@ fn main() -> ExitCode {
}
}

if failures.is_empty() {
if failures.is_empty() && unhit.is_empty() {
ExitCode::SUCCESS
} else {
ExitCode::FAILURE
Expand Down
15 changes: 15 additions & 0 deletions crates/rustfs-dst-faults/src/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ impl ProbeRegistry {
.cloned()
.collect()
}

/// Return any registered `Sometimes` or `Reachable` assertion whose
/// `pass_count == 0` across a multi-seed campaign (dead / unexercised branch).
pub fn unhit_must_hit(&self) -> Vec<ProbeStats> {
self.stats
.lock()
.expect("ProbeRegistry lock poisoned")
.values()
.filter(|s| {
matches!(s.kind, AssertionKind::Sometimes | AssertionKind::Reachable)
&& s.pass_count == 0
})
.cloned()
.collect()
}
}

#[cfg(test)]
Expand Down
52 changes: 41 additions & 11 deletions crates/rustfs-dst-runtime/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ struct SimClockInner {
/// Optional per-node monotonic drift multiplier in parts-per-million
/// relative to 1_000_000 (e.g., +50_000 = 5% fast, -50_000 = 5% slow).
node_drift_ppm: HashMap<String, i64>,
/// Incrementally accumulated per-node monotonic nanoseconds so changing or
/// clearing `node_drift_ppm` never causes a monotonic clock to jump backward.
node_accumulated_ns: HashMap<String, u64>,
/// Wake-up waiters indexed by deadline instant.
waiters: BTreeMap<u64, Vec<Arc<Notify>>>,
}
Expand Down Expand Up @@ -159,6 +162,7 @@ impl SimClock {
now_ns: 0,
node_skew_ms: HashMap::new(),
node_drift_ppm: HashMap::new(),
node_accumulated_ns: HashMap::new(),
waiters: BTreeMap::new(),
})),
node_id: None,
Expand Down Expand Up @@ -194,12 +198,19 @@ impl SimClock {
/// (clamped to `[-500_000, +500_000]`).
pub fn set_node_drift_ppm(&self, node_id: impl Into<String>, drift_ppm: i64) {
let mut inner = self.inner.lock().expect("SimClock lock poisoned");
let id = node_id.into();
let cur_ns = inner.now_ns;
inner
.node_accumulated_ns
.entry(id.clone())
.or_insert(cur_ns);
inner
.node_drift_ppm
.insert(node_id.into(), drift_ppm.clamp(-500_000, 500_000));
.insert(id, drift_ppm.clamp(-500_000, 500_000));
}

/// Reset all injected skews and drifts across all nodes.
/// Reset all injected skews and drifts across all nodes without moving any
/// node's accumulated monotonic instant backward.
pub fn clear_faults(&self) {
let mut inner = self.inner.lock().expect("SimClock lock poisoned");
inner.node_skew_ms.clear();
Expand All @@ -212,6 +223,13 @@ impl SimClock {
let to_wake = {
let mut inner = self.inner.lock().expect("SimClock lock poisoned");
inner.now_ns = inner.now_ns.saturating_add(delta_ns);
let drifts = inner.node_drift_ppm.clone();
for (id, acc_ns) in &mut inner.node_accumulated_ns {
let ppm = drifts.get(id).copied().unwrap_or(0);
let scaled = (delta_ns as i128) * (1_000_000 + i128::from(ppm)) / 1_000_000;
let step = u64::try_from(scaled.max(0)).unwrap_or(u64::MAX);
*acc_ns = acc_ns.saturating_add(step);
}
let now = inner.now_ns;
let ready_keys: Vec<u64> = inner.waiters.range(..=now).map(|(&k, _)| k).collect();
let mut wakes = Vec::new();
Expand Down Expand Up @@ -242,17 +260,12 @@ impl SimClock {
}

fn effective_instant(&self, inner: &SimClockInner) -> SimInstant {
let base_ns = inner.now_ns;
let drift_ppm = self
let ns = self
.node_id
.as_ref()
.and_then(|id| inner.node_drift_ppm.get(id).copied())
.unwrap_or(0);
if drift_ppm == 0 {
return SimInstant(base_ns);
}
let scaled = (base_ns as i128) * (1_000_000 + i128::from(drift_ppm)) / 1_000_000;
SimInstant(u64::try_from(scaled.max(0)).unwrap_or(u64::MAX))
.and_then(|id| inner.node_accumulated_ns.get(id).copied())
.unwrap_or(inner.now_ns);
SimInstant(ns)
}
}

Expand Down Expand Up @@ -360,4 +373,21 @@ mod tests {
let finished_ms = handle.await.unwrap();
assert_eq!(finished_ms, 3_000);
}

#[test]
fn clearing_drift_never_moves_monotonic_clock_backward() {
let clock = SimClock::new();
let n1 = clock.for_node("n1");
clock.set_node_drift_ppm("n1", 100_000);
clock.advance(Duration::from_secs(10));
let before_clear = n1.now_instant();
assert_eq!(before_clear.as_millis(), 11_000);

clock.clear_faults();
let after_clear = n1.now_instant();
assert_eq!(after_clear, before_clear);

clock.advance(Duration::from_secs(5));
assert_eq!(n1.now_instant().as_millis(), 16_000);
}
}
58 changes: 54 additions & 4 deletions crates/rustfs-dst-runtime/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,30 @@ impl Network for SimNetwork {
|| return_profile.partitioned
|| self.rng.gen_bool(profile.post_apply_reply_drop_prob)
{
self.record(from, to, &method, "reply_dropped_after_apply");
return Err(NetError::ReplyDroppedAfterApply {
from: from.to_string(),
to: to.to_string(),
// Only classify as ReplyDroppedAfterApply when the remote handler
// actually succeeded (`Ok`). If the handler failed (`Err`), nothing
// was applied remotely so reporting ReplyDroppedAfterApply would
// falsely mark an unapplied write as indeterminate!
if response.is_ok() {
self.record(from, to, &method, "reply_dropped_after_apply");
return Err(NetError::ReplyDroppedAfterApply {
from: from.to_string(),
to: to.to_string(),
});
}
self.record(from, to, &method, "handler_err_reply_lost");
if to_crashed_mid_flight {
return Err(NetError::NodeDown(to.to_string()));
}
if return_profile.partitioned {
return Err(NetError::Partitioned {
from: to.to_string(),
to: from.to_string(),
});
}
return Err(NetError::PacketDropped {
from: to.to_string(),
to: from.to_string(),
});
}

Expand All @@ -370,3 +390,33 @@ impl Network for SimNetwork {
response
}
}

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

struct FailingHandler;

#[async_trait]
impl RpcHandler for FailingHandler {
async fn handle(&self, _from: &str, _req: RpcFrame) -> Result<RpcFrame, NetError> {
Err(NetError::Io("disk offline".to_string()))
}
}

#[tokio::test]
async fn handler_error_with_dropped_return_link_is_never_marked_applied() {
let clock = SimClock::new();
let net = SimNetwork::new(clock, SimRng::from_seed(7));
net.register("n2", Arc::new(FailingHandler));
net.partition_one_way("n2", "n1");

let res = net
.call("n1", "n2", RpcFrame::new("commit", Vec::new()))
.await;
assert!(
!matches!(res, Err(NetError::ReplyDroppedAfterApply { .. })),
"unapplied handler error falsely reported as ReplyDroppedAfterApply: {res:?}"
);
}
}
Loading
Loading