pub struct ConnectionPool { /* private fields */ }Expand description
Connection Pool Manager
Implementations§
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn new(config: PoolConfig) -> Self
pub fn new(config: PoolConfig) -> Self
Create a new connection pool
Sourcepub fn with_backend_template(self, template: BackendConfig) -> Self
pub fn with_backend_template(self, template: BackendConfig) -> Self
Attach a backend-connection template. With a template and a
per-node endpoint (set via add_node_with_endpoint), the pool
opens real PG connections via crate::backend::BackendClient.
Without a template the pool stays in skeleton mode — existing
tests that use synthetic NodeIds keep passing unchanged.
Sourcepub async fn add_node(&self, node_id: NodeId)
pub async fn add_node(&self, node_id: NodeId)
Add a node to the pool (skeleton mode — no real backend).
Sourcepub async fn add_node_with_endpoint(
&self,
node_id: NodeId,
host: impl Into<String>,
port: u16,
)
pub async fn add_node_with_endpoint( &self, node_id: NodeId, host: impl Into<String>, port: u16, )
Add a node with endpoint info. When combined with
with_backend_template, create_connection opens a live
BackendClient against the given host:port.
Sourcepub async fn remove_node(&self, node_id: &NodeId)
pub async fn remove_node(&self, node_id: &NodeId)
Remove a node from the pool
Sourcepub async fn get_connection(&self, node_id: &NodeId) -> Result<PooledConnection>
pub async fn get_connection(&self, node_id: &NodeId) -> Result<PooledConnection>
Get a connection from the pool
Sourcepub async fn return_connection(&self, conn: PooledConnection)
pub async fn return_connection(&self, conn: PooledConnection)
Return a connection to the pool
Sourcepub async fn close_connection(&self, conn: PooledConnection)
pub async fn close_connection(&self, conn: PooledConnection)
Close a connection (don’t return to pool)
Sourcepub async fn validate_connection(&self, conn: &PooledConnection) -> Result<bool>
pub async fn validate_connection(&self, conn: &PooledConnection) -> Result<bool>
Validate a connection.
When a live backend client is attached, runs SELECT 1. When
no client is attached, falls back to the pre-T0-TR1 state
check — useful for tests that don’t stand up a real backend.
Sourcepub async fn run_reset_query(
&self,
conn: &mut PooledConnection,
query: &str,
) -> Result<()>
pub async fn run_reset_query( &self, conn: &mut PooledConnection, query: &str, ) -> Result<()>
Run a reset query on a connection (if live) before returning it
to the pool. Used by pool-modes release for Transaction and
Statement modes.
Sourcepub async fn evict_idle(&self)
pub async fn evict_idle(&self)
Evict idle connections that have exceeded idle timeout
Sourcepub async fn total_connections(&self) -> usize
pub async fn total_connections(&self) -> usize
Get total connections
Sourcepub async fn active_connections(&self) -> usize
pub async fn active_connections(&self) -> usize
Get active connections
Sourcepub async fn metrics(&self) -> PoolMetrics
pub async fn metrics(&self) -> PoolMetrics
Get pool metrics
Sourcepub async fn node_stats(&self, node_id: &NodeId) -> Option<NodePoolStats>
pub async fn node_stats(&self, node_id: &NodeId) -> Option<NodePoolStats>
Get per-node statistics
Auto Trait Implementations§
impl !Freeze for ConnectionPool
impl !RefUnwindSafe for ConnectionPool
impl Send for ConnectionPool
impl Sync for ConnectionPool
impl Unpin for ConnectionPool
impl UnsafeUnpin for ConnectionPool
impl !UnwindSafe for ConnectionPool
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