Expand description
Incremental projection rebuild and invalidation.
On startup, instead of replaying the entire event log, we read the
projection cursor (byte offset + last event hash) from
projection_meta and replay only events after that point.
§Safety checks
Before doing an incremental apply, several invariants are verified:
-
Schema version — the DB schema version must match
migrations::LATEST_SCHEMA_VERSION. A mismatch means the code has been upgraded and a full rebuild is needed. -
Cursor hash found — the
last_event_hashstored in the cursor must appear in the shard content at the expected byte offset. If the hash cannot be found the shard was modified (e.g. deleted/rotated) and incremental replay is unsafe. -
Sealed shard manifest integrity — for every sealed shard that has a
.manifestfile, the recordedbyte_lenmust match the actual file size. A mismatch indicates shard corruption or tampering. -
Projection tracking table — the
projected_eventstable must exist. If it doesn’t, we can’t deduplicate and must rebuild.
When any check fails, incremental_apply falls back to a full rebuild
automatically, returning the reason in ApplyReport::full_rebuild_reason.
Structs§
- Apply
Report - Report from an incremental apply operation.
- Event
Hash - Identifies the last event that was successfully applied to the projection.
Stored in the
projection_metatable inSQLite.
Functions§
- check_
incremental_ safety - Check if incremental apply is safe or if full rebuild is needed.
- incremental_
apply - Apply only events newer than the high-water mark to the projection.
- read_
hwm - Read the current high-water mark from the
SQLitemetadata table. ReturnsNoneif no events have been applied (fresh DB). - write_
hwm - Write the high-water mark after successful apply.