Repository navigation
Commit d4a68ed
feat(publish): prototype generation-directory publish (not wired), with experiments and a model check (#275)
**Prototype, kept as a draft until the maintainer decides the open
design questions.** Nothing calls it yet.
## Why
On #264 the maintainer chose to replace
per-file output writes with a **generation-directory publish**. This
prototype tests that design on evidence first.
The publish is meant to close three gaps that exist in every output mode
today:
- **Check-then-write race:** a symbolic link swapped in between the
preflight check and the write.
- **Partial files after a crash.**
- **Interleaving between concurrent runs.**
## What is here
### `src/publish.rs`
For a report `D/S.json`, the layout is:
- `D/S.gen/<id>/`: one complete generation per directory.
- `D/S.gen/CURRENT`: a JCS manifest naming the current generation and
the SHA-256 of each of its files.
- Mirrors at `D/S.json` and the other output names: hard links into the
current generation, with copies where linking fails.
A publish runs in this order:
1. Write the generation into `<id>.partial/`, syncing each file.
2. Rename it to `<id>`.
3. Under a `File::lock`:
- refuse if `CURRENT` names a newer generation (ids sort by run start);
- otherwise replace `CURRENT` by temp file and rename;
- refresh the mirrors;
- collect old generations (default: keep 1 older).
Readers take no lock. When the generation `CURRENT` named has been
collected, they retry from `CURRENT`.
### `examples/publish_stress.rs`
Compares three strategies: `inplace` (`fs::write`, as on main),
`perfile` (rename each file) and `genset` (this prototype). It runs a
multi-process race, kill -9 crash trials and a latency bench.
### `tests/publish_model.rs`
An exhaustive explicit-state check of the protocol, reported as
**TESTED** with these bounds:
- up to 3 writers and 1 reader, 2 files;
- a crash at every writer step;
- garbage collection of crashed **and live** writers' partial
generations;
- 13,427 states at most.
Results:
- **P1–P3 hold:** `CURRENT` names only complete generations, it never
moves backwards, and manifest readers never fail or return a partial
set.
- **P4 fails, as expected:** after a crash the mirrors can be torn.
- **Three deliberate mutants are each caught**, showing that the
invariants are not trivially true.
## Measured on Linux 6.18, ext4, 4 cores
| | inplace | perfile | genset (mirrors) | genset (manifest) |
|---|---|---|---|---|
| race, 3 writers × 150 + readers: partial reads | 7931 / 8424 | 0 /
3209 | 0 / 6058 | **0 / 2500** |
| race: torn sets | 182 | 3008 | 67 | **0** |
| kill -9, 300 trials: partial / torn left behind | 176 / 13 | 0 / 155 |
0 / 3 | **0 / 0** |
| 100 races: torn final state | 0 | 7 | 0 | **0** |
| p50 latency, 1 KiB / 256 KiB / 4 MiB | 0.27 / 1.0 / 12.5 ms | 1.2 /
3.2 / 23.8 ms | 2.7 / 4.6 / 33.7 ms | |
Defects the experiments found, each fixed here with a test that fails
without the fix:
- GC raced a writer renaming its own `.partial` directory, so a writer
crashed with NotFound in 1 of 40 races.
- A reader could lose a generation to GC: 1 in 2,500 reads. It now
retries, and was 0 in about 11,200 reads afterwards.
## Open before this can be wired
- **Mirrors torn after a crash** (P4). The options are to document it,
to use one `current` symlink pointer (crash-consistent on Unix), or to
drop the mirrors.
- **Proof legs** under `PROOF-POLICY` §1.2 and §4:
- a TLA+ spec checked by TLC (the policy's worked exception), which was
not runnable in this session;
- Creusot/Pearlite and Verus for the pure selection logic, still OPEN.
- **Other questions:**
- the generation id format (UUIDv7 or v8 per the estate ID policy);
- Windows behaviour (no Windows run yet);
- power-loss durability (fsync ordering is not tested; kill -9 tests
process crashes only);
- what a replacement keeps: ACLs, xattrs, labels and ownership.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01PFaqv6iBXrt3W5Akd1Fq5k)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e12b823 commit d4a68ed
17 files changed
Lines changed: 1717 additions & 0 deletions
File tree
- .github/workflows
- docs/design
- examples
- src
- tests
- verification/proofs/tlaplus
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
84 | 104 | | |
85 | 105 | | |
86 | 106 | | |
87 | 107 | | |
88 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
89 | 115 | | |
90 | 116 | | |
91 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
0 commit comments