Struct JournaledSession
pub struct JournaledSession {
memory: InMemory,
log: Log,
}alloc only.Expand description
A State wrapper that records every mutation as a Op.
The inner InMemory is updated immediately so that queries always
reflect the latest state. Each mutation is also appended to an internal op
log, exposed as pending_ops. The persistence layer
consumes those ops (encoding them with encode_frames for a file, or
applying them as rows for a SQL store) and then calls clear
once they are durable.
This is a sans-io building block. It does not use files or async.
Fields§
§memory: InMemory§log: LogImplementations§
§impl JournaledSession
impl JournaledSession
pub const fn new() -> Self
pub const fn new() -> Self
Creates a new journaled session with an empty in-memory state.
pub const fn from_memory(memory: InMemory) -> Self
pub const fn from_memory(memory: InMemory) -> Self
Creates a journaled session wrapping an existing in-memory session.
Use this when reloading persisted state: first rebuild the
InMemory, then wrap it so that future mutations are recorded.
pub const fn with_pending_limit(self, bytes: usize) -> Self
pub const fn with_pending_limit(self, bytes: usize) -> Self
Limits the pending ops to bytes.
An op that would exceed the limit is not recorded, and
pending_ops returns
IncompleteLog::LimitReached until the next clear.
This bounds the memory used between persists, for example while the
storage keeps failing. By default there is no limit.
pub fn pending_ops(&self) -> Result<&Ops, IncompleteLog>
pub fn pending_ops(&self) -> Result<&Ops, IncompleteLog>
Borrows the ops recorded since the last clear, in
order.
The persistence layer persists these (framing them with
encode_frames for a file, or applying them as rows for a SQL store)
and then calls clear. To make retries safe, call
clear only after the write succeeds. After a failed
write, the ops remain buffered for the next attempt.
§Errors
Returns IncompleteLog if an op could not be recorded. Persist a
full snapshot of memory instead, then call
clear.
pub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true if nothing needs to be persisted since the last
clear.
pub fn clear(&mut self)
pub fn clear(&mut self)
Discards the recorded ops after they, or a full snapshot, have been persisted.
Trait Implementations§
§impl Debug for JournaledSession
impl Debug for JournaledSession
§impl Default for JournaledSession
impl Default for JournaledSession
§impl State for JournaledSession
impl State for JournaledSession
§type Error = TryReserveError
type Error = TryReserveError
§fn modify(&mut self, op: Modify<'_>) -> Applied
fn modify(&mut self, op: Modify<'_>) -> Applied
§fn for_each_outbox_entry(&self, f: &mut dyn FnMut(PacketId, OutboxEntry<'_>))
fn for_each_outbox_entry(&self, f: &mut dyn FnMut(PacketId, OutboxEntry<'_>))
§fn drain_outbox(
&mut self,
visit: &mut dyn FnMut(PacketId, OutboxEntry<'_>) -> DrainAction,
)
fn drain_outbox( &mut self, visit: &mut dyn FnMut(PacketId, OutboxEntry<'_>) -> DrainAction, )
DrainAction the visitor
returns. Sent marks it in-flight and was_sent.
Discard removes it.
Stop halts the walk. This is the only outbound
send path, so the visitor is the only place that writes a publish to
the wire.§fn reset_in_flight(&mut self)
fn reset_in_flight(&mut self)
§fn has_outbox_entry(&self, packet_id: PacketId) -> bool
fn has_outbox_entry(&self, packet_id: PacketId) -> bool
true if the outbox contains a publish under packet_id.§fn has_pubrel_pending(&self, packet_id: PacketId) -> bool
fn has_pubrel_pending(&self, packet_id: PacketId) -> bool
true if a PUBREL is pending for packet_id (the QoS 2
publish is in the awaiting-PUBCOMP phase). Read more§fn for_each_pubrel_pending(&self, f: &mut dyn FnMut(PacketId))
fn for_each_pubrel_pending(&self, f: &mut dyn FnMut(PacketId))
§fn drain_pubrel(&mut self, visit: &mut dyn FnMut(PacketId) -> DrainAction)
fn drain_pubrel(&mut self, visit: &mut dyn FnMut(PacketId) -> DrainAction)
DrainAction. Mirrors
drain_outbox for the QoS 2 PUBREL resend.§fn has_incoming_qos2(&self, packet_id: PacketId) -> bool
fn has_incoming_qos2(&self, packet_id: PacketId) -> bool
QoS 2 packet identifier is stored (i.e.,
PUBREC was already sent for this packet ID).§fn for_each_incoming_qos2(&self, f: &mut dyn FnMut(PacketId))
fn for_each_incoming_qos2(&self, f: &mut dyn FnMut(PacketId))
QoS 2 packet identifier.§fn get_filter_entry(&self, filter: &TopicFilter) -> Option<FilterEntry<'_>>
fn get_filter_entry(&self, filter: &TopicFilter) -> Option<FilterEntry<'_>>
None if it
has not been touched. Used by the client to determine the filter’s
current state before recording an UNSUBSCRIBE transition.§fn resolve_pending(
&mut self,
packet_id: PacketId,
decide: &mut dyn FnMut(FilterEntry<'_>, usize) -> Resolution,
)
fn resolve_pending( &mut self, packet_id: PacketId, decide: &mut dyn FnMut(FilterEntry<'_>, usize) -> Resolution, )
Subscribing or
Unsubscribing) under packet_id, in packet order, and applies the
returned Resolution. decide also receives the position of the
entry as pending_filters reports it.§fn for_each_filter_entry(&self, f: &mut dyn FnMut(FilterEntry<'_>))
fn for_each_filter_entry(&self, f: &mut dyn FnMut(FilterEntry<'_>))
§fn first_pending_group(&self) -> Option<PendingMeta>
fn first_pending_group(&self) -> Option<PendingMeta>
None
when none remain. This is a read-only peek; the caller iterates the
group’s filters with pending_filters,
enqueues the packet, then commits the group with
mark_subscription_in_flight. Read more§fn pending_filters(
&self,
packet_id: PacketId,
) -> impl Iterator<Item = (FilterEntry<'_>, usize)>
fn pending_filters( &self, packet_id: PacketId, ) -> impl Iterator<Item = (FilterEntry<'_>, usize)>
packet_id, in
packet order, each with its position in the packet. Once the request
is marked with
mark_subscription_in_flight,
the position is the one at that time, even if filters have left the
request since. It is the position of the filter’s reason code in the
SUBACK or UNSUBACK.§fn has_resubscribe(&self) -> bool
fn has_resubscribe(&self) -> bool
true if a Resubscribing
filter waits to be sent again.§fn start_resubscribe(&mut self, packet_id: PacketId) -> Option<FilterEntry<'_>>
fn start_resubscribe(&mut self, packet_id: PacketId) -> Option<FilterEntry<'_>>
Resubscribing filter under the free
packet_id. The new state is the one FilterState::resubscribe
returns. Returns the changed entry, or None if no filter waits to
be resubscribed. Never allocates.§fn forget_server_state(&mut self)
fn forget_server_state(&mut self)
§fn mark_subscription_in_flight(&mut self, packet_id: PacketId)
fn mark_subscription_in_flight(&mut self, packet_id: PacketId)
packet_id in flight, so the next
first_pending_group skips the group
until reset_in_flight re-arms it. Also
records the position of each filter in the packet for
resolve_pending. Called once the group’s
packet has been enqueued.§fn is_packet_id_in_use(&self, packet_id: PacketId) -> bool
fn is_packet_id_in_use(&self, packet_id: PacketId) -> bool
true if packet_id is currently occupied by any tracked
operation. This includes outbox entries, PUBREL-pending entries and
in-flight SUBSCRIBE/UNSUBSCRIBE requests. Read moreAuto Trait Implementations§
impl Freeze for JournaledSession
impl RefUnwindSafe for JournaledSession
impl Send for JournaledSession
impl Sync for JournaledSession
impl Unpin for JournaledSession
impl UnsafeUnpin for JournaledSession
impl UnwindSafe for JournaledSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more