added update_rule for incremental change

This commit is contained in:
2025-12-15 23:47:28 +01:00
parent d744769138
commit d26e833d93
10 changed files with 566 additions and 241 deletions

25
data_updating_rule.md Normal file
View File

@@ -0,0 +1,25 @@
# Abort-Safe Incremental JSONL Persistence Rule
**Rule:** Persist state using an *append-only, fsync-backed JSONL log with atomic checkpoints*.
**Requirements**
- Write updates as **single-line JSON objects** (one logical mutation per line).
- **Append only** (`O_APPEND`), never modify existing lines.
- After each write batch, call **`fsync`** (or `File::sync_data`) before reporting success.
- Treat a **line as committed only if it ends with `\n`**; ignore trailing partial lines on recovery.
- Periodically create a **checkpoint**:
- Write full state to `state.tmp`
- `fsync`
- **Atomic rename** to `state.jsonl`
- On startup:
- Load last checkpoint
- Replay log lines after it in order
- On abort/panic/crash:
- No truncation
- Replay guarantees no data loss beyond last fsynced line
**Outcome**
- Crash/abort-safe
- O(1) writes
- Deterministic recovery
- Minimal overhead