pub struct Lsn(/* private fields */);Expand description
Log sequence number.
Monotonically increasing within a single WAL generation; reset to
zero across checkpoints (the salt rotation disambiguates). The
sentinel value Lsn::ZERO represents “no LSN” — returned by
crate::pager::Pager::commit for an empty transaction and by
crate::pager::Pager::reader_snapshot for in-memory pagers
that have no WAL.
Lsn is a #[repr(transparent)] newtype over u64 so the
type-system rejects implicit confusion with page counts, byte
offsets, or page ids (Power-of-Ten Rule 5). The serde encoding is
#[serde(transparent)] — an Lsn round-trips byte-identically to
the bare u64 it wraps, which preserves wire compatibility with
any future on-disk record that names it directly.
Lsn deliberately does NOT implement Add<u64> / AddAssign<u64>
or any other arithmetic trait. Step it through the explicit
Lsn::checked_next / Lsn::prev_saturating helpers so every
mutation is auditable.
Implementations§
Source§impl Lsn
impl Lsn
Sourcepub const ZERO: Self
pub const ZERO: Self
The sentinel “no LSN” value. Returned by
crate::pager::Pager::commit when the transaction was empty
and by crate::pager::Pager::reader_snapshot on in-memory
pagers (no WAL exists).
Sourcepub const fn new(raw: u64) -> Self
pub const fn new(raw: u64) -> Self
Construct an Lsn from a raw u64. The underlying u64
has no invariants — any value (including 0) is valid —
so this is a total function.
Sourcepub const fn get(self) -> u64
pub const fn get(self) -> u64
The raw u64 LSN value. Use this only when crossing into
hand-rolled byte serialization (see
crate::wal::frame::FrameHeader::lsn) or when emitting
diagnostics; arithmetic should go through the explicit step
helpers below.
Sourcepub fn checked_next(self) -> Result<Self>
pub fn checked_next(self) -> Result<Self>
Monotonic step: return the next LSN, or Error::InvalidArgument
on u64 overflow.
§Errors
Returns Error::InvalidArgument when the underlying counter
would wrap past u64::MAX. At 10⁶ commits/sec this is ~584 000
years; the check is defensive (Power-of-Ten Rule 7) and
extremely cheap.
Sourcepub const fn prev_saturating(self) -> Self
pub const fn prev_saturating(self) -> Self
Predecessor LSN, saturating at Lsn::ZERO.
Used by crate::pager::Pager::commit / reader_snapshot
to report the LSN of the last committed frame as
next_lsn - 1, with the special case next_lsn == ZERO
mapping back to ZERO rather than wrapping.