use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::thread;
use std::time::Duration;
fn main() {
println!("Buggy Server v0.1 - Simulating production workload...");
println!("Watch for anomalies in the TUI!");
let mut iteration = 0u64;
loop {
iteration += 1;
for _ in 0..100 {
fast_operation();
}
if iteration % 50 == 0 {
println!("[ANOMALY] Iteration {}: Triggering slow path...", iteration);
slow_buggy_operation();
}
if iteration % 200 == 0 {
println!("[CRITICAL] Iteration {}: Synchronous disk flush!", iteration);
catastrophic_flush();
}
thread::sleep(Duration::from_millis(10));
}
}
fn fast_operation() {
let _ = std::fs::metadata("/tmp");
if let Ok(mut f) = File::open("/dev/null") {
let mut buf = [0u8; 64];
let _ = f.read(&mut buf);
}
}
fn slow_buggy_operation() {
let path = "/tmp/renacer_demo_largefile";
if let Ok(mut f) = OpenOptions::new().write(true).create(true).truncate(true).open(path) {
let data = vec![0xABu8; 1024 * 1024];
let _ = f.write_all(&data);
let _ = f.sync_all(); }
if let Ok(mut f) = File::open(path) {
let mut buf = Vec::new();
let _ = f.read_to_end(&mut buf);
}
}
fn catastrophic_flush() {
let path = "/tmp/renacer_demo_sync";
if let Ok(mut f) = OpenOptions::new().write(true).create(true).truncate(true).open(path) {
let data = vec![0xFFu8; 4 * 1024 * 1024]; let _ = f.write_all(&data);
let _ = f.sync_all();
}
}