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,
abort: Option<AbortHandle>,
)
pub fn start_query( &self, member_id: u64, sql: String, abort: Option<AbortHandle>, )
Records that a checked-out member has started running sql (a truncated
preview), so menus/status can show what each busy session is doing, and
stores an abort handle so a concurrent cancel can stop it. abort is
None for members with no cancellation support (e.g. the test pool).
Sourcepub fn abort_handles(&self, member: Option<u64>) -> Vec<AbortHandle>
pub fn abort_handles(&self, member: Option<u64>) -> Vec<AbortHandle>
Cloned abort handles for the pool’s currently-running statements — the one
member when member is Some, else every busy member with a handle.
Snapshotted under the slot lock and returned by value so the caller can
await each abort without holding the (non-async) lock.
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.
Auto Trait Implementations§
impl<S = SnowflakeSession> !Freeze for SessionPool<S>
impl<S = SnowflakeSession> !RefUnwindSafe for SessionPool<S>
impl<S = SnowflakeSession> !UnwindSafe for SessionPool<S>
impl<S> Send for SessionPool<S>
impl<S> Sync for SessionPool<S>
impl<S> Unpin for SessionPool<S>
impl<S> UnsafeUnpin for SessionPool<S>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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