added update_rule for incremental change
This commit is contained in:
25
data_updating_rule.md
Normal file
25
data_updating_rule.md
Normal 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
|
||||
Reference in New Issue
Block a user