pub struct Pool { /* private fields */ }Implementations§
Source§impl Pool
impl Pool
Sourcepub fn new(driver: Arc<dyn Driver>) -> Self
pub fn new(driver: Arc<dyn Driver>) -> Self
Create a pool. No connection is opened until one is needed, so an application still boots when the database is briefly unavailable.
Sourcepub async fn verify(&self) -> Result<()>
pub async fn verify(&self) -> Result<()>
Open one connection immediately, so a misconfiguration is reported at boot rather than on the first request.
pub fn driver(&self) -> &Arc<dyn Driver> ⓘ
pub fn dialect(&self) -> Arc<dyn Dialect> ⓘ
Sourcepub async fn acquire(&self) -> Result<PooledConnection>
pub async fn acquire(&self) -> Result<PooledConnection>
Take a connection, opening one if none is idle.
Sourcepub async fn idle_count(&self) -> usize
pub async fn idle_count(&self) -> usize
How many connections are currently idle. Used by tests and diagnostics.
Sourcepub async fn open_count(&self) -> usize
pub async fn open_count(&self) -> usize
How many sockets this pool is holding open: idle plus borrowed.
The number that matters to the server, which is a different number
from the one the semaphore governs. A permit is held only while a
connection is borrowed, so the semaphore caps concurrent use; a
connection handed back sits in idle holding no permit and a very much
open socket. An application with one pool never has to care. One with a
pool per tenant does: fifty idle pools are five hundred sockets against
a server whose default limit is a hundred, while every semaphore reads
zero.
Sourcepub async fn close_idle(&self, limit: usize) -> usize
pub async fn close_idle(&self, limit: usize) -> usize
Close up to limit idle connections, returning how many went.
Only idle ones: a borrowed connection is in the middle of somebody’s query, and taking it away would turn a capacity problem into a failed request. Freeing what is idle is enough — that is where a pool nobody is using keeps its sockets.
Sourcepub async fn retire_superseded(&self) -> usize
pub async fn retire_superseded(&self) -> usize
Close idle connections belonging to a superseded credential, now.
Pool::acquire already refuses to hand one out, so this is not needed
for correctness — it is for closing the window between a rotation and
the next request on a quiet pool, where an idle session opened with a
revoked account would otherwise sit there until somebody happened to
need it. Connections currently lent out are left alone; they are retired
when their borrower gives them back.
Returns how many were closed.