Struct SessionEngine
pub struct SessionEngine<C, R> { /* private fields */ }Expand description
The shared session engine: owns session metadata + the parked queue + id minting + the
deadline; drives a SessionBackend for everything that touches the transaction. Generic
over the server’s parked one-shot command C and its deferred responder R.
Implementations§
§impl<C, R> SessionEngine<C, R>where
R: SessionResponder,
impl<C, R> SessionEngine<C, R>where
R: SessionResponder,
pub fn new(session_deadline: Duration) -> SessionEngine<C, R>
pub fn with_id_prefix(
session_deadline: Duration,
prefix: impl Into<String>,
) -> SessionEngine<C, R>
pub fn with_id_prefix( session_deadline: Duration, prefix: impl Into<String>, ) -> SessionEngine<C, R>
Construct an engine whose session ids are namespaced by prefix (for example ms3-).
Only the id spelling changes; scheduling, deadlines, and wire replies are identical.
pub fn session_open(&self) -> bool
pub fn session_open(&self) -> bool
Whether a session currently holds the writer — the server’s loop checks this to park one-shot writes instead of running them.
pub fn owns_session(&self, session_id: &str) -> bool
pub fn owns_session(&self, session_id: &str) -> bool
Whether this engine owns the named open session. Pooled dispatchers use this for connection affinity; callers learn nothing about the backend transaction itself.
pub fn has_public_terminal(&self, session_id: &str, operation_id: &str) -> bool
pub fn has_public_terminal(&self, session_id: &str, operation_id: &str) -> bool
Whether this engine retained the terminal reply for a completed public commit operation. The pooled dispatcher uses this to route a response-loss retry back to the connection that produced the original answer even though the transaction itself is already closed.
pub fn wait(&self) -> Option<Duration>
pub fn wait(&self) -> Option<Duration>
How long the loop may sleep before the open session’s deadline (recv_timeout bound);
None when no session is open (block on recv as usual).
pub fn park_one_shot(&mut self, cmd: C)
pub fn park_one_shot(&mut self, cmd: C)
Park a one-shot server command while a session is open (the caller checked
session_open). Deferred — no thread is held — and the server’s
admission cap bounds the queue (every parked command still owns its inflight slot).
pub fn take_parked_for_reopen(&mut self) -> Option<SessionEngine<C, R>>
pub fn take_parked_for_reopen(&mut self) -> Option<SessionEngine<C, R>>
Move only the admitted FIFO into a fresh engine generation. A host that must replace its storage engine between two one-shots uses this while no session is open: queued responders retain their order, while session ids and terminal-reply caches remain generation-scoped and are deliberately reset just as they are on an ordinary restart.
pub fn expire_if_due(&mut self, be: &mut impl SessionBackend) -> Option<String>
pub fn expire_if_due(&mut self, be: &mut impl SessionBackend) -> Option<String>
Expire the open session if its deadline passed: RAII rollback via the backend. Returns the dead session’s id for the server to log (each server has its own log prefix); the caller then runs its drain pump. Called from the loop’s timeout wake AND before each command, so expiry cannot be starved by unrelated traffic.
pub fn handle(&mut self, be: &mut impl SessionBackend, op: SessionOp, resp: R)
pub fn handle(&mut self, be: &mut impl SessionBackend, op: SessionOp, resp: R)
Route one session op. A begin while a session is open PARKS (FIFO with one-shot
writes); everything else resolves against the open session or answers gone. After any
call that can close the session (commit/rollback/a poisoning error), the server
runs its drain pump (next_parked) — calling it unconditionally
is cheap (an open session or empty queue returns Idle immediately).
pub fn next_parked(&mut self, be: &mut impl SessionBackend) -> ParkedNext<C>
pub fn next_parked(&mut self, be: &mut impl SessionBackend) -> ParkedNext<C>
The drain pump, run by the server in a loop after session close points: handles parked
session ops INTERNALLY in strict FIFO (a parked begin that opens the next session
stops the drain; an absorbed/gap/failed one answers and the drain continues), and hands
each parked one-shot back for the server to run — returning it (rather than taking a
run closure) sidesteps the double-&mut-self borrow a callback would force on servers
whose one-shot executor is a method of the struct owning this engine.
pub fn pop_parked_one_shot_if(
&mut self,
pred: impl FnOnce(&C) -> bool,
) -> Option<C>
pub fn pop_parked_one_shot_if( &mut self, pred: impl FnOnce(&C) -> bool, ) -> Option<C>
Pop the next parked command IF it is a one-shot matching pred — the server’s
group-commit fold peek (rindled folds a contiguous parked /execute-sql-txn run into
one commit, exactly as a channel backlog would). Never crosses a parked session op.