moonpool ~
GitHub →
$ techniques

Reboots

A process starts again with fresh memory and reads its disk. The test goes on.

The problem

A server restarts after a deploy, a crash or a new disk. All that it had in memory is gone. It must read its state from its disk, and that disk can be older than its last answer, or empty. The bugs are in this gap: a server that forgets a write it acknowledged, or a cluster that loses a write when one server comes back with nothing.

The technique

A process is the system under test. Each boot makes a new instance from its factory, so nothing in memory survives a reboot. The disk survives, with the crash model of the storage page. A workload is the test driver. It survives each reboot, keeps its requests going and checks the answers.

Attrition reboots the processes during the chaos time. Each reboot is graceful (a signal, a grace period, then a kill), a crash (a kill at once), or a crash and wipe (a kill, then an empty disk). max_dead is the most processes that are down at the same time, so a quorum can stay up. A process can also be rebooted at a moment its code names with hint!.

The live run

Three servers and one client. At 122 ms a server is crashed and wiped at its own hint, after it wrote a record and before the sync. It boots again with version 0: its disk is empty. Later a crash hits another server, and it boots with the version it synced. The client did not stop, and each read returned the last committed write.

each reboot of a server

The code

The attrition of the site's engine. A wipe needs a budget: a wiped server of the register has no repair, so one wipe at a time can stay unhealed, and each later wipe becomes a crash:

out.push(Chaos::Attrition {
    config: Attrition {
        // A minority at a time, so a quorum can stay up.
        max_dead: (servers - 1) / 2,
        prob_graceful: 0.3,
        prob_crash: if wipes { 0.5 } else { 0.7 },
        prob_wipe: if wipes { 0.2 } else { 0.0 },
        // With wipes, a server comes back within the run, so the
        // page can show a wiped server boot on an empty disk.
        recovery_delay_ms: wipes.then_some(500..2000),
        grace_period_ms: None,
        scope: AttritionScope::PerProcess,
        victims: AttritionVictims::group(SERVER),
        // A wiped server lost its log and has no repair: one wipe
        // per run, never healed, so the others keep each committed
        // write and every later wipe becomes a crash.
        wipe_budget: wipes.then_some(WipeBudget {
            max_unhealed: 1,
            heal: WipeHeal::Signal,
        }),
    },
    mode: ChaosMode::Random,

Each boot of a server starts here, with empty memory. It opens its log, reads it and keeps the newest record that passes its check word:

let storage = ctx.storage();
let file = storage
    .open(FILE, OpenOptions::new().read(true).write(true).create(true))
    .await
    .map_err(|e| io_error(&e))?;
storage.sync_dir(".").await.map_err(|e| io_error(&e))?;
let (mut version, mut value) = Self::load(&file).await?;
assert_sometimes!(version > 0, "a server boots with a stored value");
tracing::info!(version, "server_boot");

In the Guide

All the techniques