Skip to main content

Module compact

Module compact 

Source
Expand description

Lattice-based log compaction for the bones event log.

Over time the event log grows. Compaction replaces event sequences for completed items with a single item.snapshot event — the semilattice join of all events for that item. Compaction is coordination-free: each replica compacts independently and converges to identical state.

§Snapshot Semantics

Snapshots are lattice elements, not regular updates.

  • For every LWW field the snapshot carries the winning (stamp, wall_ts, agent_id, event_hash, value) tuple — not just the value.
  • For OR-Sets and G-Sets the snapshot carries the full set state.
  • Applying a snapshot uses merge(state, snapshot_state) — a field-wise lattice join, not “overwrite with snapshot clock”.

This is critical: if a snapshot used a single event clock for all fields, it would incorrectly dominate concurrent events that were not observed at compaction time, violating semantic preservation.

§Redaction Interaction

Snapshots check the redaction set before including field values. Compaction must never reintroduce redacted content.

§Audit Metadata

Each snapshot carries _compacted_from (count of original events), _earliest_ts, and _latest_ts timestamps for audit trail.

Structs§

CompactionPolicy
Configuration for the compaction policy.
CompactionReport
Report from compacting eligible items.
LwwSnapshot
Serializable representation of a single LWW register with its clock.
SnapshotPayload
Full snapshot payload encoding every CRDT field with its clock metadata.

Functions§

compact_item
Compact all events for a single item into one item.snapshot event.
compact_items
Compact eligible items from a collection of events grouped by item ID.
extract_snapshot_payload
Extract and deserialize the SnapshotPayload from an item.snapshot event.
is_eligible
Check if a work item is eligible for compaction.
verify_compaction
Verify that compacted state matches uncompacted state.
verify_lattice_join
Verify lattice join property: merge(original, snapshot) == original.