Skip to main content

PoolManager

Struct PoolManager 

Source
pub struct PoolManager { /* private fields */ }
Expand description

Manages connection pools keyed by (node, database, user). Each upstream node gets its own pool, enabling per-node failover and separate primary/replica connection limits.

Implementations§

Source§

impl PoolManager

Source

pub async fn checkout( self: &Arc<Self>, client: &ClientGuard, database: &str, user: &str, read_only: bool, ) -> Result<ConnGuard>

Source§

impl PoolManager

Source

pub async fn warm_up(self: &Arc<Self>)

Open idle connections at startup based on min_connections config.

Source

pub fn scavenge_idle(&self) -> u32

Remove idle connections that exceed max_lifetime or whose socket is dead, then apply idle_timeout only to connections in excess of min_connections for that pool entry.

max_lifetime and dead-socket detection always apply because those represent unhealthy connections. idle_timeout represents excess capacity that can be released — so it must respect the floor set by min_connections, otherwise warm-up connections decay away even when the user explicitly asked for a minimum.

Returns the number of connections removed across all pool entries. Normally invoked from PoolManager::run_scavenger; exposed so tests can drive it directly without spinning up the full background task.

Source

pub async fn run_scavenger(self: &Arc<Self>)

Run the idle scavenger and refill loop at a fixed interval.

Each tick prunes expired idle connections (preserving the min_connections floor), then refills any pool entry below its floor by fanning every spawn_connections call into a JoinSet and awaiting them concurrently — matching PoolManager::warm_up. Running them in series here would let a single slow node blow most of the 30-second budget and leave unrelated pools under their min_connections floor. The per-tick state is logged at debug level so the loop is visible without needing trace-level filters.

Source§

impl PoolManager

Source

pub fn new( config: Arc<ArcSwap<Config>>, topology: Arc<TopologyManager>, pgpass: Arc<Pgpass>, ) -> Self

Source

pub fn config(&self) -> &Arc<ArcSwap<Config>>

Access the shared config handle. Used by the reload path to atomically swap in a new Config via store; callers that just want to read the current config should use load_full() on the returned handle for intra-operation consistency.

Source

pub fn pgpass(&self) -> &Pgpass

Access the pgpass store.

Source

pub fn shutdown(&self)

Signal that halephant is shutting down: set the shutdown flag and wake every queued waiter so they return a classified error immediately instead of sitting on the queue until checkout_timeout expires or they get force-aborted.

Called from the graceful shutdown path in main right after the accept loop exits, before draining client tasks.

Source

pub fn resolve( &self, database: &str, routing: Routing, ) -> Result<String, ResolveError>

Resolve a routing target for a database. Returns the upstream address as an owned string.

Returns a specific ResolveError if the database is unknown, the primary has not been discovered, or no healthy replica is available.

Source

pub fn drain_node(&self, node: &str)

Drain idle connections for a specific node across all databases/users. Called when topology detects a node role change or unreachability.

Source

pub fn drain_all(&self)

Source

pub fn pool_stats(&self) -> Vec<(PoolKeyInfo, PoolStats)>

Returns a snapshot of all pool states for metrics reporting.

Source

pub fn queue_stats(&self) -> Vec<QueueInfo>

Returns a snapshot of every non-empty wait queue, broken down per user within each (database, role) queue.

Source

pub fn pool_limits(&self) -> Vec<PoolLimits>

Returns the configured connection limits for each pool.

Auto Trait Implementations§

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,