Skip to main content

GraphPool

Struct GraphPool 

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

图数据库连接池

v3.1.0 改进:从 Arc<Mutex<Vec<GraphConnection>>> 改为 Arc<ArrayQueue<GraphConnection>> + AtomicU32 + Notify, 使用无锁 MPMC 队列消除锁竞争,与 sz-orm-core 连接池设计一致。

Implementations§

Source§

impl GraphPool

Source

pub fn new(config: GraphConfig) -> Self

Source

pub fn config(&self) -> &GraphConfig

Source

pub async fn acquire(&self) -> Result<GraphConnection, GraphError>

获取连接

优先从空闲队列取;若空且未超 max_pool_size 则新建; 若已满则等待 release 唤醒。

Source

pub async fn acquire_timeout( &self, timeout: Duration, ) -> Result<GraphConnection, GraphError>

带超时的 acquire

Source

pub async fn release(&self, conn: GraphConnection)

归还连接到空闲队列

Source

pub fn idle_count(&self) -> usize

空闲连接数

Source

pub fn total_count(&self) -> u32

总连接数(idle + borrowed)

Source

pub fn waiters_count(&self) -> u32

等待者数

Source

pub fn close(&self)

关闭连接池

设置 closed 标志,后续 acquire 返回错误,release 直接丢弃。 已借出的连接不受影响(调用方自行 disconnect)。

Source

pub fn is_closed(&self) -> bool

池是否已关闭

Source

pub fn status(&self) -> GraphPoolStatus

获取池状态快照

Trait Implementations§

Source§

impl Clone for GraphPool

Source§

fn clone(&self) -> Self

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§

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> 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, <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.