pub struct EntityLog { /* private fields */ }Expand description
Local view of an entity’s event log.
Implementations§
Source§impl EntityLog
impl EntityLog
Sourcepub fn from_snapshot(
entity_id: EntityId,
snapshot_seq: u64,
head_link: CausalLink,
head_payload: Bytes,
) -> Self
pub fn from_snapshot( entity_id: EntityId, snapshot_seq: u64, head_link: CausalLink, head_payload: Bytes, ) -> Self
Create from a snapshot (for catchup — events after snapshot_seq will be appended).
Sourcepub fn append(&mut self, event: CausalEvent) -> Result<(), LogError>
pub fn append(&mut self, event: CausalEvent) -> Result<(), LogError>
Append a causal event to the log.
Validates chain integrity (origin, sequence, parent_hash). Returns an error if the chain is broken.
Sourcepub fn range(&self, from_seq: u64, to_seq: u64) -> Vec<&CausalEvent>
pub fn range(&self, from_seq: u64, to_seq: u64) -> Vec<&CausalEvent>
Get events in a sequence range (inclusive).
Sourcepub fn after(&self, seq: u64) -> Vec<&CausalEvent>
pub fn after(&self, seq: u64) -> Vec<&CausalEvent>
Get all events after a given sequence.
Sourcepub fn head_link(&self) -> CausalLink
pub fn head_link(&self) -> CausalLink
Get the head (latest) link.
Sourcepub fn origin_hash(&self) -> u64
pub fn origin_hash(&self) -> u64
Get the origin hash.
Sourcepub fn prune_through(&mut self, seq: u64)
pub fn prune_through(&mut self, seq: u64)
Prune events up to and including a sequence number.
Called after a snapshot is taken at that sequence.
snapshot_seq is only advanced when last_pruned.is_some()
— i.e. a real event was actually pruned. The pruning
side-effects (base_link, head_payload) only fire when
at least one event is removed, so unconditionally bumping
snapshot_seq whenever seq > self.snapshot_seq (even on
an empty log, or when seq < first_event.sequence) would
leave base_link.sequence behind, producing a permanent
desync where head_seq().max(snapshot_seq()) returns a
value the next append can’t agree with. Callers that need
to install an externally-coordinated snapshot anchor on an
empty log should use from_snapshot instead.
Sourcepub fn snapshot_seq(&self) -> u64
pub fn snapshot_seq(&self) -> u64
Get the snapshot sequence (events before this have been pruned).