Skip to main content

Pool

Struct Pool 

Source
pub struct Pool { /* private fields */ }

Implementations§

Source§

impl Pool

Source

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.

Source

pub async fn verify(&self) -> Result<()>

Open one connection immediately, so a misconfiguration is reported at boot rather than on the first request.

Source

pub fn driver(&self) -> &Arc<dyn Driver>

Source

pub fn dialect(&self) -> Arc<dyn Dialect>

Source

pub async fn acquire(&self) -> Result<PooledConnection>

Take a connection, opening one if none is idle.

Source

pub async fn idle_count(&self) -> usize

How many connections are currently idle. Used by tests and diagnostics.

Source

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.

Source

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.

Source

pub async fn close(&self)

Close every idle connection.

Source

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.

Trait Implementations§

Source§

impl Clone for Pool

Source§

fn clone(&self) -> Pool

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Pool

§

impl !UnwindSafe for Pool

§

impl Freeze for Pool

§

impl Send for Pool

§

impl Sync for Pool

§

impl Unpin for Pool

§

impl UnsafeUnpin for Pool

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.