pub struct Position(/* private fields */);Expand description
A global coordinate: the order an event was committed in, across every stream of one database.
Positions are dense and gap-free as read: a reader never observes
n + 1 while n is still uncommitted, so a subscription is a plain
position > cursor range read with no grace window.
The mechanism is narrower than “one writer”, and worth stating precisely
because the narrower version is also stronger. The position is allocated
inside the transaction that commits it, and that transaction holds
SQLite’s write lock from BEGIN, because every write the backend makes is
IMMEDIATE. Allocation order and commit order therefore cannot diverge —
and that argument does not depend on there being one connection. It holds
for two processes on one file, and it is measured: 120 appends through two
separately-opened logs come back as exactly 1..=120, in order.
What a second connection does cost is the wake-up, not the order — see
crate::log::EventLog::subscribe.
Implementations§
Source§impl Position
impl Position
Sourcepub const BEGINNING: Position
pub const BEGINNING: Position
Before the first event. Where a consumer with no checkpoint starts.
pub const fn new(value: u64) -> Self
pub const fn get(self) -> u64
Sourcepub fn as_stored(self) -> Option<i64>
pub fn as_stored(self) -> Option<i64>
The value as SQLite stores it, or None when it does not fit.
A position is a rowid, so every position the store ever assigns is in
range. Position::new is public, though, and a u64 above
i64::MAX would bind as a negative number: position > -1 reads the
whole log rather than nothing, and a checkpoint written from one would
silently replay everything through the exactly-once path. Callers that
bind a position use this and refuse rather than wrap.