# Restartable parity repair

This is a deterministic arithmetic demonstration, not a filesystem reproduction,
a test of Linux MD/CrookFS, or a measured failure probability. Created 2026-11-09.
Python 3 standard library only; no devices, root access, network or random seed.

## Reproduce

```sh
python3 -B model.py --output results.json
python3 -B test_model.py
python3 -B -O test_model.py
```

The executable results are integers. The article shows hexadecimal bytes.
The example has old data 0x3c, unchanged-data XOR 0xa5, replacement data 0x96,
old parity 0x99 and replacement parity 0x33.

## Explicit contract

There is one changed whole block D and the XOR U of all untouched blocks.
P0=D0 XOR U. A committed, selected update requires D1.
D and P each persist atomically, independently, as old or new: four states.
All reads and retained records are correct; there are no torn blocks,
concurrent writers, device loss, changing untouched blocks or damaged journals.

Three operations answer different questions:
- Current-operand redo reads current D/P and sets P=P XOR D XOR D1, D=D1.
- Logged-old-value redo recomputes the fixed target from retained P0,D0,D1.
- Parity-only repair sets P=D XOR U without replacing D. This illustrates only
  PPL's arithmetic distinction, not its implementation or degraded-array logic.

After a partial original write, current-operand redo can finish with wrong parity.
A further uninterrupted retry is then a fixed point at that wrong parity.
Thus an idempotent *resulting retry* is not enough to establish correctness.

Logged redo always assigns the same two target values. The finite closure under
any subset of those assignments has four states; every complete final replay
reaches the target. This is a safety argument under the assumptions, not a
liveness guarantee when crashes continue forever. It does not prove the actual
journal's ordering, integrity, atomic record format, version selection or reuse.

The stale-record control replays generation 7 after generation 8 data exists.
Unchecked replay restores consistent but stale data. The model's explicit
active-generation check rejects it; real generation discovery is assumed,
not implemented. A log must not become an unbounded license to replay.

## Validation

Ten unittest methods include 16,384 exhaustive four-bit/input/persistence cases,
65,536 byte-pair target checks against a bit-sum oracle, no-change controls,
closure checks and rejected invalid inputs. These are test-space counts,
not independent samples or empirical fault rates. No confidence interval applies.

## Source synthesis

CrookFS section 4.1.4 retains old values with versions for restartable parity
policy execution. Its mechanism belongs to the historical research prototype.
Linux MD PPL instead stores the untouched chunks' XOR and does not promise to
preserve all in-flight data. The RAID cache journal records data/parity with
identification and integrity information. These mechanisms are not synonyms.

See sources.json for exact URLs, versions, sections, access date and source hashes.
Original papers and kernel source files are not bundled. Existing Hesela concepts:
https://hesela.dev/terms/idempotency/
https://hesela.dev/terms/io-shepherding/
https://hesela.dev/terms/partial-parity-log/
https://hesela.dev/terms/read-modify-write/
