pub struct TenantPoolRegistry { /* private fields */ }Expand description
租户连接池注册表
按 tenant_id 维护独立的 Pool,各租户池共享 PoolConfig。
租户切换原子(RAII 守卫),路由开销 ≤ 50μs(HashMap 查找 + Arc clone)。
Implementations§
Source§impl TenantPoolRegistry
impl TenantPoolRegistry
Sourcepub fn new(pool_config: PoolConfig) -> Self
pub fn new(pool_config: PoolConfig) -> Self
创建新的租户连接池注册表
Sourcepub fn get_or_create(
&self,
tenant_id: i64,
factory: &Arc<dyn ConnectionFactory>,
) -> Result<Arc<Pool>, PoolError>
pub fn get_or_create( &self, tenant_id: i64, factory: &Arc<dyn ConnectionFactory>, ) -> Result<Arc<Pool>, PoolError>
获取或创建租户连接池
Pool 已存在时返回既有 Pool;不存在时创建新 Pool 并插入 HashMap。 使用读锁优先 + 写锁降级策略避免不必要的写锁竞争。
Sourcepub fn switch(
&self,
tenant_id: i64,
factory: &Arc<dyn ConnectionFactory>,
) -> Result<TenantPoolGuard<'_>, PoolError>
pub fn switch( &self, tenant_id: i64, factory: &Arc<dyn ConnectionFactory>, ) -> Result<TenantPoolGuard<'_>, PoolError>
原子切换到指定租户的连接池
返回 RAII 守卫,在 Drop 时切换回原租户。
Sourcepub fn tenant_count(&self) -> usize
pub fn tenant_count(&self) -> usize
获取已注册的租户数量
Sourcepub fn config(&self) -> &PoolConfig
pub fn config(&self) -> &PoolConfig
获取连接池配置
Auto Trait Implementations§
impl !Freeze for TenantPoolRegistry
impl !RefUnwindSafe for TenantPoolRegistry
impl !UnwindSafe for TenantPoolRegistry
impl Send for TenantPoolRegistry
impl Sync for TenantPoolRegistry
impl Unpin for TenantPoolRegistry
impl UnsafeUnpin for TenantPoolRegistry
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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