Skip to main content

SessionPool

Struct SessionPool 

Source
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>

Source

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.

Source

pub async fn checkout<F, Fut, E>(&self, create: F) -> Result<Checkout<S>, E>
where F: FnOnce() -> Fut, Fut: Future<Output = Result<(S, QueryContext), 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).

Source

pub fn checkin(&self, checkout: Checkout<S>, current: QueryContext)

Returns a session to its slot with the context now applied to it.

Source

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.

Source

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).

Source

pub fn touch(&self)

Records that the pool served a query.

Source

pub fn id(&self) -> u64

The pool id.

Source

pub fn live(&self) -> usize

The number of live sessions (idle + checked out).

Source

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>
where S: Send,

§

impl<S> Sync for SessionPool<S>
where S: Send,

§

impl<S> Unpin for SessionPool<S>

§

impl<S> UnsafeUnpin for SessionPool<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more