# When a dirty mark cannot recover an old block

This worked example isolates an information requirement. It is exact byte algebra,
not a disk benchmark, reliability estimate, AFRAID implementation or power-loss test.

## One unchanged value is lost

Three data symbols A=1, B=2 and C=4 have XOR parity P=7. Values are decimal bytes.
Replace A with 9 without changing P, then lose the member holding unchanged B.

| Available recovery information | Operation | Result |
| --- | --- | --- |
| Stale parity and current survivors | 7 XOR 9 XOR 4 | 10, not B=2 |
| Same values plus a persistent dirty mark | No additional byte equation | B is undetermined |
| Same values plus retained delta 1 XOR 9 = 8 | 7 XOR 8 XOR 9 XOR 4 | B=2 |

The dirty mark tells a reader not to trust stale parity. It cannot supply the
missing value. A second history proves this: starting with A=0, B=3, C=4 also
gives P=7. After A becomes 9 and B is lost, the visible survivors, parity and mark
are identical, but the required answer is B=3. No deterministic decoder using
only that visible state can always choose correctly.

With retained update information, P XOR old_A XOR new_A is current parity.
For repeated updates all outstanding deltas must be included. If an update
returns A to its old value, the deltas cancel; the example does not imply that
every write necessarily changes the parity bits.

## Design context

[AFRAID](https://www.usenix.org/legacy/publications/library/proceedings/sd96/full_papers/wilkes.pdf)
defers redundancy; [parity logging](https://www.pdl.cmu.edu/PDL-FTP/ParityLogging/ISCA93.pdf)
preserves recovery information in fault-tolerant buffers and logs.
They are different contracts, although both postpone parity writes.

## Reproduce

Use Python 3 and its standard library from this directory:

```sh
python3 -B model.py --check
python3 -B -m unittest -v test_model.py
python3 -B -O -m unittest -v test_model.py
```

Run `python3 -B model.py` to regenerate [results.json](results.json).
The [tests](test_model.py) exhaust all 65,536 combinations of three original
four-bit symbols and one replacement. They verify both the stale-parity error
and recovery after delta replay. The [model](model.py) also rejects non-byte inputs.

The example assumes exact surviving symbols and one missing data symbol. It
does not model atomic update ordering, log corruption, concurrent writes, media
errors, cache flushes, fault domains, repair time or loss probability. A real
implementation must establish its own persistence and failure contract.

Source identities and reviewed sections: [sources.json](sources.json).
The paper PDFs are linked, not redistributed.
