pub struct ConnectionPoolManager { /* private fields */ }Expand description
Adaptive connection pool with health checking, multiple acquisition policies, idle/lifetime eviction, event streaming, and dynamic resize.
Implementations§
Source§impl ConnectionPoolManager
impl ConnectionPoolManager
Sourcepub fn new(config: CpmPoolConfig) -> Self
pub fn new(config: CpmPoolConfig) -> Self
Create a new pool with the given configuration.
Returns CpmPoolError::InvalidConfiguration if min > max or max == 0.
Sourcepub fn validate_config(config: &CpmPoolConfig) -> Result<(), CpmPoolError>
pub fn validate_config(config: &CpmPoolConfig) -> Result<(), CpmPoolError>
Validate the current configuration.
Sourcepub fn add_connection(
&mut self,
address: String,
tags: Vec<String>,
) -> Result<u64, CpmPoolError>
pub fn add_connection( &mut self, address: String, tags: Vec<String>, ) -> Result<u64, CpmPoolError>
Add a new connection to the pool.
Returns the new connection’s unique ID, or CpmPoolError::PoolExhausted if
max_connections has been reached.
Sourcepub fn add_connection_at(
&mut self,
address: String,
tags: Vec<String>,
created_at: u64,
) -> Result<u64, CpmPoolError>
pub fn add_connection_at( &mut self, address: String, tags: Vec<String>, created_at: u64, ) -> Result<u64, CpmPoolError>
Add a connection with an explicit creation timestamp (useful in tests).
Sourcepub fn acquire(&mut self, current_ts: u64) -> Result<u64, CpmPoolError>
pub fn acquire(&mut self, current_ts: u64) -> Result<u64, CpmPoolError>
Acquire an idle connection according to the configured AcquirePolicy.
Returns the ID of the acquired connection, or an error if:
- No idle connections exist and the pool is at capacity →
CpmPoolError::PoolExhausted - All connections are busy and no idle ones can be selected →
CpmPoolError::AcquireTimeout(usingacquire_timeout_usas the waited value)
Sourcepub fn release(
&mut self,
conn_id: u64,
current_ts: u64,
health_degraded: bool,
) -> Result<(), CpmPoolError>
pub fn release( &mut self, conn_id: u64, current_ts: u64, health_degraded: bool, ) -> Result<(), CpmPoolError>
Release a previously acquired connection back to Idle.
If health_degraded is true, the health score is reduced by 0.1
(floored at 0.0).
Sourcepub fn remove_connection(&mut self, conn_id: u64) -> Result<(), CpmPoolError>
pub fn remove_connection(&mut self, conn_id: u64) -> Result<(), CpmPoolError>
Permanently remove a connection from the pool.
Sourcepub fn health_check(
&mut self,
conn_id: u64,
score: f64,
current_ts: u64,
) -> Result<PoolEvent, CpmPoolError>
pub fn health_check( &mut self, conn_id: u64, score: f64, current_ts: u64, ) -> Result<PoolEvent, CpmPoolError>
Record the result of a health check for the given connection.
If score < 0.3, emits a PoolEvent::HealthCheckFailed and returns it.
Otherwise returns PoolEvent::ConnectionAdded as a no-op sentinel
(callers should match on the returned variant).
Sourcepub fn run_maintenance(&mut self, current_ts: u64) -> Vec<PoolEvent>
pub fn run_maintenance(&mut self, current_ts: u64) -> Vec<PoolEvent>
Evict connections that have exceeded idle or absolute lifetime limits.
Returns a list of PoolEvent::ConnectionRemoved events for each evicted
connection.
Sourcepub fn resize(&mut self, new_max: usize) -> Result<(), CpmPoolError>
pub fn resize(&mut self, new_max: usize) -> Result<(), CpmPoolError>
Resize the pool’s maximum connection limit.
When shrinking, excess idle connections are drained (closed) immediately.
Sourcepub fn drain(&mut self) -> Vec<u64>
pub fn drain(&mut self) -> Vec<u64>
Close all connections in insertion order and return their IDs.
Sourcepub fn connections_with_tag(&self, tag: &str) -> Vec<&PooledConnection>
pub fn connections_with_tag(&self, tag: &str) -> Vec<&PooledConnection>
Return references to all connections that carry the given tag.
Sourcepub fn stats(&self) -> CpmPoolStats
pub fn stats(&self) -> CpmPoolStats
Compute a statistics snapshot.
Sourcepub fn drain_events(&mut self) -> Vec<PoolEvent>
pub fn drain_events(&mut self) -> Vec<PoolEvent>
Drain and return all pending events.
Sourcepub fn connections(&self) -> &HashMap<u64, PooledConnection>
pub fn connections(&self) -> &HashMap<u64, PooledConnection>
Returns a reference to the underlying connection map (read-only).
Sourcepub fn config(&self) -> &CpmPoolConfig
pub fn config(&self) -> &CpmPoolConfig
Returns the current configuration.
Auto Trait Implementations§
impl Freeze for ConnectionPoolManager
impl RefUnwindSafe for ConnectionPoolManager
impl Send for ConnectionPoolManager
impl Sync for ConnectionPoolManager
impl Unpin for ConnectionPoolManager
impl UnsafeUnpin for ConnectionPoolManager
impl UnwindSafe for ConnectionPoolManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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