rotation: tests, replay-base cutoff state fix, formatting
- tests/test_rotation.py covers both framers: history split, idempotent reopen, no-op cases, aged-out reduction to a single snapshot, internal snapshot validation, extension-agnostic rotated naming, and the disabled default. - Fix plan_rotation to seed the cutoff state from the replay base snapshot (previously asserted when the base already covered the cutoff). - docs: snapshots carry the schema version in effect at their position, keeping replay/migration behavior identical to the unrotated file.
This commit is contained in:
+8
-6
@@ -155,16 +155,18 @@ into memory by `open_and_read`; no second disk read is needed.
|
||||
5. **Rewrite the main file in place.** On the locked fd: seek to 0, truncate
|
||||
to 0, write the new content, `fdatasync`. The new content is, in order:
|
||||
1. A **snapshot of the state at the cutoff** — the replayed state after
|
||||
applying all records with `ts < cutoff`, stamped with the **current
|
||||
schema version**. Its `ts` is the **ts of the last pre-cutoff record**
|
||||
(not the rotation time), and this is exactly the timestamp used in the
|
||||
rotated filename. This snapshot is the new replay base and carries the
|
||||
version forward so migrations are not re-run; it is always written.
|
||||
applying all records with `ts < cutoff`, stamped with the **schema
|
||||
version in effect at the cutoff**. Its `ts` is the **ts of the last
|
||||
pre-cutoff record** (not the rotation time), and this is exactly the
|
||||
timestamp used in the rotated filename. This snapshot is the new replay
|
||||
base and carries the version forward so migrations are not re-run; it is
|
||||
always written.
|
||||
2. The retained change records (`ts >= cutoff`), **recreated record by
|
||||
record** — no internal snapshots are carried over, even if the original
|
||||
file had many in the retained range.
|
||||
3. A **final snapshot** of the state after the last retained record,
|
||||
stamped with the current schema version — written **only if** there were
|
||||
stamped with the version of the last retained record — written **only
|
||||
if** there were
|
||||
retained change records (and, in line with the existing snapshot policy
|
||||
in `kanta/snapshot.py`, only when a meaningful number of changes
|
||||
accumulated; a handful of trailing changes need not force one). If no
|
||||
|
||||
Reference in New Issue
Block a user