pub struct Pool<M: Manage, X: Exchange<M> = NoExchange> { /* private fields */ }Expand description
A sharded connection pool for compio.
Cheap to clone and Send + Sync: clone it onto every compio thread. Each
thread transparently gets its own shard, so the acquire fast path touches no
atomics and no locks.
The X parameter selects the cross-thread strategy. The default,
NoExchange, keeps threads fully independent. Swap in a
Reservoir — which requires Detach —
to let idle connections migrate to whichever thread needs them.
Implementations§
Source§impl<M: Manage, X: Exchange<M>> Pool<M, X>
impl<M: Manage, X: Exchange<M>> Pool<M, X>
Sourcepub fn with_exchange(manager: M, config: Config, exchange: X) -> Self
pub fn with_exchange(manager: M, config: Config, exchange: X) -> Self
Builds a pool with an explicit cross-thread Exchange.
Sourcepub fn manager(&self) -> &M
pub fn manager(&self) -> &M
The manager, for callers that need to reach configuration through it.
Sourcepub fn local_size(&self) -> usize
pub fn local_size(&self) -> usize
Connections owned by this thread’s shard, idle plus checked out.
Sourcepub fn local_idle(&self) -> usize
pub fn local_idle(&self) -> usize
Idle connections sitting in this thread’s shard.
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Retires every connection created before this call.
Live checkouts keep working and are closed when returned. Use after a credential rotation or a failover, where existing sockets point at the wrong place but the pool itself is still wanted.
Sourcepub fn close(&self)
pub fn close(&self)
Closes the pool.
Subsequent acquire calls fail with
Error::Closed. This thread’s idle connections are closed
immediately; other threads’ are closed when they next touch the pool or
when their thread exits.