pub struct SessionPool<S = SnowflakeSession> { /* private fields */ }Expand description
A bounded pool of authenticated sessions for one (account, user).
Generic over the session type for testability; the engine uses
SessionPool<SnowflakeSession>.
Implementations§
Source§impl<S> SessionPool<S>
impl<S> SessionPool<S>
Sourcepub fn new(
id: u64,
key: SessionKey,
max: usize,
now: DateTime<Utc>,
auth_gate: Arc<TokioMutex<()>>,
) -> Self
pub fn new( id: u64, key: SessionKey, max: usize, now: DateTime<Utc>, auth_gate: Arc<TokioMutex<()>>, ) -> Self
Builds an empty pool with capacity max (clamped to ≥ 1), sharing the
given auth gate.
Sourcepub async fn checkout<F, Fut, E>(&self, create: F) -> Result<Checkout<S>, E>
pub async fn checkout<F, Fut, E>(&self, create: F) -> Result<Checkout<S>, E>
Checks out a session: reuses the most-recently-returned idle one (LIFO,
good temporal affinity), or creates a new one via create if none is idle
and the pool is under capacity.
create returns the session and its concrete base context. It is only
invoked while holding a permit with no idle session available, so the live
count never exceeds max.
§Errors
Propagates create’s error (e.g. authentication failure).
Sourcepub fn checkout_all_idle(&self) -> Vec<Checkout<S>>
pub fn checkout_all_idle(&self) -> Vec<Checkout<S>>
Checks out every currently-idle session without waiting or creating.
Used by the keep-alive heartbeat: each borrowed session holds a real
permit, so a concurrent checkout briefly waits for
restore instead of authenticating a duplicate session
(a spurious browser SSO). Busy sessions are skipped — the query path
keeps them alive itself.
Sourcepub fn restore(&self, checkout: Checkout<S>)
pub fn restore(&self, checkout: Checkout<S>)
Returns a borrowed session to its slot untouched — unlike
checkin it preserves last_used and the recorded
context, because a keep-alive heartbeat is not a query.
Sourcepub fn checkin(&self, checkout: Checkout<S>, current: QueryContext)
pub fn checkin(&self, checkout: Checkout<S>, current: QueryContext)
Returns a session to its slot with the context now applied to it.
Sourcepub fn start_query(&self, member_id: u64, sql: String)
pub fn start_query(&self, member_id: u64, sql: String)
Records that a checked-out member has started running sql (a truncated
preview), so menus/status can show what each busy session is doing.
Sourcepub fn discard(&self, checkout: Checkout<S>)
pub fn discard(&self, checkout: Checkout<S>)
Discards a session — e.g. after expiry — removing its slot (releases the permit and frees its capacity for a fresh auth).
Sourcepub fn info(&self) -> SessionInfo
pub fn info(&self) -> SessionInfo
A serializable snapshot of the pool, including each member.