Skip to content

Virtual FileSystem

github-actions[bot] edited this page Dec 2, 2026 · 1 revision

Virtual Filesystem (SimFileSystem)

Every SimHost owns a virtual in-memory filesystem (host.FileSystem) with explicit fsync durability semantics and simulated disk latency:

  • Flushed writes (flush: true or FlushAsync / FlushAllAsync) persist across host.Crash() and host.Restart().
  • Buffered writes (flush: false) are visible to reads while the host is running, but are discarded on host.Crash() (rolling back to the last flushed state).
  • Torn writes (Config.TornWriteProbability) deterministically persist a partial prefix of unflushed bytes on crash, allowing you to test Write-Ahead Log (WAL) framing, checksums, and recovery logic.

Example

var host = sim.AddHost("storage");
host.FileSystem.Config.TornWriteProbability = 0.5;

await host.FileSystem.WriteAllTextAsync("state.dat", "committed", flush: true);
await host.FileSystem.WriteAllTextAsync("wal.log", "unflushed-tail", flush: false);

host.Crash();

// "state.dat" is intact; "wal.log" was dropped or torn deterministically based on the seed.

See samples/Faultline.Samples.WriteAheadLog and samples/Faultline.Samples.LeaderElection for full end-to-end examples.

Clone this wiki locally