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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ cargo run --release -p rustfs-dst-cli -- repro --scenario swizzle-clog-chaos --t

## Documentation

- [Complete 26-Scenario Coverage Matrix (7 Core + 19 Enterprise Domains)](docs/coverage-matrix.md)
- [Complete 33-Scenario Coverage Matrix (7 Core + 19 Enterprise + 7 Scanner Chaos)](docs/coverage-matrix.md)
- [Architecture & Upstream Trait Adoption Blueprint (`rustfs/rustfs`)](docs/architecture.md)
- [Simulation Backends: In-Process, Turmoil, Madsim & Antithesis](docs/antithesis.md)
- [Jepsen Distributed Verification Companion (`rustfs/Jepsen`)](https://github.com/rustfs/Jepsen)
Expand Down
1 change: 1 addition & 0 deletions crates/rustfs-dst-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fn parse_scenarios(raw: &str) -> Result<Vec<ScenarioKind>, String> {
"all" => Ok(ScenarioKind::ALL.to_vec()),
"core" => Ok(ScenarioKind::CORE.to_vec()),
"enterprise" => Ok(ScenarioKind::ENTERPRISE.to_vec()),
"scanner" => Ok(ScenarioKind::SCANNER.to_vec()),
"replication" => Ok(vec![
ScenarioKind::SiteReplication,
ScenarioKind::BucketReplication,
Expand Down
95 changes: 87 additions & 8 deletions crates/rustfs-dst-runtime/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,22 @@ impl SimDiskInner {
}

fn total_volatile_bytes(&self) -> u64 {
self.inodes
.values()
.filter(|inode| !inode.is_dir)
.map(|inode| inode.volatile_data.len() as u64)
.sum()
let mut seen = BTreeSet::new();
let mut stack = vec![self.root];
let mut total = 0u64;
while let Some(id) = stack.pop() {
if !seen.insert(id) {
continue;
}
if let Some(inode) = self.inodes.get(&id) {
if inode.is_dir {
stack.extend(inode.volatile_children.values().copied());
} else {
total += inode.volatile_data.len() as u64;
}
}
}
total
}

fn crash_and_reboot(&mut self) {
Expand Down Expand Up @@ -548,6 +559,51 @@ impl SimDiskIo {
true
}

/// Deterministically truncate `trim_bytes` from the tail of `path` on both
/// volatile and durable layers (simulating silent tail-truncation corruption,
/// e.g. `rustfs/rustfs#8005`). Returns `true` if the file was shrunk.
pub fn inject_tail_truncate(&self, path: &str, trim_bytes: usize) -> bool {
if trim_bytes == 0 {
return false;
}
let Ok(norm) = normalize_path(path) else {
return false;
};
let mut inner = self.inner.lock().expect("SimDiskIo lock poisoned");
let Some(id) = inner.lookup(&norm, false) else {
return false;
};
let Some(existing) = inner.inodes.get(&id).and_then(|inode| {
if inode.is_dir || inode.volatile_data.len() <= trim_bytes {
None
} else {
Some(inode.volatile_data.clone())
}
}) else {
return false;
};
let new_len = existing.len() - trim_bytes;
let truncated = existing.slice(..new_len);
let inode = inner.inodes.get_mut(&id).expect("inode");
if inode
.durable_data
.as_ref()
.is_some_and(|durable| durable.len() == existing.len())
{
inode.durable_data = Some(truncated.clone());
}
inode.volatile_data = truncated;
true
}

/// Return current total volatile byte usage across all files on this drive.
pub fn used_bytes(&self) -> u64 {
self.inner
.lock()
.expect("SimDiskIo lock poisoned")
.total_volatile_bytes()
}

/// Wipe the entire drive (simulating drive replacement with a fresh empty disk).
pub fn wipe_drive(&self) {
let mut inner = self.inner.lock().expect("SimDiskIo lock poisoned");
Expand Down Expand Up @@ -956,9 +1012,32 @@ mod tests {
disk.read_file("bucket/obj/xl.meta").await.unwrap(),
Bytes::from_static(b"v1")
);
assert!(matches!(
assert_eq!(
disk.read_file("bucket/obj/xl.meta.next").await,
Err(DiskError::NotFound(_))
));
Err(DiskError::NotFound("bucket/obj/xl.meta.next".to_string()))
);
}

#[tokio::test]
async fn tail_truncate_shrinks_persisted_bytes() {
let disk = SimDiskIo::new("d1", SimRng::from_seed(101));
let payload = Bytes::from_static(b"rustfs-shard-0123456789");
disk.write_file("b/k/part.1", payload.clone())
.await
.unwrap();
disk.fsync_file("b/k/part.1").await.unwrap();
disk.fsync_dir("b/k").await.unwrap();

assert!(disk.inject_tail_truncate("b/k/part.1", 1));
assert_eq!(
disk.read_file("b/k/part.1").await.unwrap().len(),
payload.len() - 1
);
assert_eq!(disk.used_bytes(), (payload.len() - 1) as u64);
disk.crash_and_reboot();
assert_eq!(
disk.read_file("b/k/part.1").await.unwrap().len(),
payload.len() - 1
);
}
}
86 changes: 69 additions & 17 deletions crates/rustfs-dst-sim/src/ecstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ struct ReadShardReq {
#[derive(Clone, Debug, Serialize, Deserialize)]
enum ReadShardResp {
NotFound,
/// `xl.meta` exists on an online drive but failed CRC/JSON decode (`rustfs#5837`).
CorruptMeta,
Found {
meta: XlMeta,
shard_bytes: Option<Vec<u8>>,
Expand Down Expand Up @@ -437,21 +439,22 @@ impl NodeRpcServer {
let resp = match disk.read_file(&dst_meta).await {
Err(DiskError::NotFound(_)) => ReadShardResp::NotFound,
Err(e) => return Err(NetError::Io(e.to_string())),
Ok(bytes) => {
let meta: XlMeta = serde_json::from_slice(&bytes)
.map_err(|e| NetError::Io(format!("corrupt xl.meta: {e}")))?;
let shard_bytes = if req.include_data && !meta.is_delete_marker {
let part_path =
format!("{}/{}/{}/part.1", req.bucket, req.key, meta.version_id);
match disk.read_file(&part_path).await {
Ok(b) => Some(b.to_vec()),
Err(_) => None,
}
} else {
None
};
ReadShardResp::Found { meta, shard_bytes }
}
Ok(bytes) => match serde_json::from_slice::<XlMeta>(&bytes) {
Err(_) => ReadShardResp::CorruptMeta,
Ok(meta) => {
let shard_bytes = if req.include_data && !meta.is_delete_marker {
let part_path =
format!("{}/{}/{}/part.1", req.bucket, req.key, meta.version_id);
match disk.read_file(&part_path).await {
Ok(b) => Some(b.to_vec()),
Err(_) => None,
}
} else {
None
};
ReadShardResp::Found { meta, shard_bytes }
}
},
};
let payload = serde_json::to_vec(&resp).map_err(|e| NetError::Io(e.to_string()))?;
Ok(RpcFrame::new(METHOD_DISK_READ, payload))
Expand Down Expand Up @@ -816,6 +819,46 @@ impl SimCluster {
disk.inject_bitrot(&path)
}

/// Inject silent bitrot directly into `xl.meta` on `(node_id, drive_idx)`
/// (reproduces `rustfs/rustfs#5837`).
pub fn inject_xl_meta_bitrot(
&self,
node_id: &str,
drive_idx: usize,
bucket: &str,
key: &str,
) -> bool {
let Some(env) = self.nodes.get(node_id) else {
return false;
};
let Some(disk) = env.disks.get(drive_idx) else {
return false;
};
let path = format!("{bucket}/{key}/xl.meta");
disk.inject_bitrot(&path)
}

/// Inject silent tail-truncation corruption on an object's shard
/// (reproduces `rustfs/rustfs#8005` 1-byte tail truncation).
pub fn inject_object_tail_truncate(
&self,
node_id: &str,
drive_idx: usize,
bucket: &str,
key: &str,
version_id: &str,
trim_bytes: usize,
) -> bool {
let Some(env) = self.nodes.get(node_id) else {
return false;
};
let Some(disk) = env.disks.get(drive_idx) else {
return false;
};
let path = format!("{bucket}/{key}/{version_id}/part.1");
disk.inject_tail_truncate(&path, trim_bytes)
}

/// Heal all network partitions, restart all downed nodes, bring all drives
/// online, and reset clock skews.
pub fn heal_infrastructure(&self) {
Expand Down Expand Up @@ -853,8 +896,17 @@ impl SimCluster {
&& let Ok(resp) = serde_json::from_slice::<ReadShardResp>(&frame.payload)
{
responded += 1;
if let ReadShardResp::Found { meta, shard_bytes } = resp {
found.push((global_idx, meta, shard_bytes));
match resp {
ReadShardResp::Found { meta, shard_bytes } => {
found.push((global_idx, meta, shard_bytes));
}
ReadShardResp::CorruptMeta => {
self.probes.reachable(
"ecstore.xl_meta_bitrot_detected",
json!({"bucket": bucket, "key": key, "node": node_id, "drive": drive_idx}),
);
}
ReadShardResp::NotFound => {}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rustfs-dst-sim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod lock;
pub mod oracle;
pub mod pools;
pub mod replication;
pub mod scanner;
pub mod scenarios;
pub mod security_obs;
pub mod topology;
Expand Down
Loading
Loading