pub struct ResourcePool { /* private fields */ }Expand description
One (ResourceKey, generation) map for the lifetime of
one session. Owns lazy init, refcount transitions, and
the close trigger.
The pool is Send + Sync and intended to be held in an
Arc from the session root (executor’s ExecCtx or
equivalent). Each phase activation calls
attach for the adapter names it needs;
the returned AttachGuard holds a clone of the
per-phase DriverAdapter shell and detaches on drop.
Implementations§
Source§impl ResourcePool
impl ResourcePool
pub fn new() -> Self
Sourcepub fn total_attaches(&self) -> usize
pub fn total_attaches(&self) -> usize
Total attach count since pool construction. Useful for tests and post-mortem diagnostics.
Sourcepub fn live_entries(&self) -> usize
pub fn live_entries(&self) -> usize
Number of distinct entries currently live in the
pool. One per (key, generation) that’s been
attached at least once and not yet fully drained.
Sourcepub async fn shutdown(self: &Arc<Self>)
pub async fn shutdown(self: &Arc<Self>)
Drain every live entry, awaiting each resource’s
close() and removing the entry from the map. Call
at session end so Shared-policy entries — which
the per-attach detach intentionally keeps alive
across phases — release their network resources
before the process exits.
Emits resource.close.started reason=session-end
per entry, then resource.close.completed /
resource.close.failed after each resource’s
close() future resolves. Returns Ok(()) even if
individual close calls fail — the failures are
logged and accounted, but the pool always finishes
the drain so the executor can move on.
Sourcepub fn declare_pending_use(&self, key: ResourceKey, policy: ResourceSharePolicy)
pub fn declare_pending_use(&self, key: ResourceKey, policy: ResourceSharePolicy)
SRD-35 Push D: declare a predicted future attach for
key under policy. Called by the pre-map walker
once per phase that will eventually attach this key
— the per-key counter accumulates so a Shared
entry attached by 50 phases starts the run with
pending_uses = 50. Each attach decrements
eagerly; the entry’s close trigger fires the moment
pending == 0 && live == 0, releasing the resource
the instant its last user is done rather than holding
it until session end.
Idempotent for a given (key, policy) — the entry is
created on first call, then increments on subsequent
calls. The pre-map walker is the only declared caller;
adapters never invoke this directly.
Sourcepub fn complete_pending_use(&self, key: &ResourceKey) -> bool
pub fn complete_pending_use(&self, key: &ResourceKey) -> bool
SRD-35 Push D: explicit per-key pending_uses
decrement, mirroring Self::declare_pending_use.
Most callers don’t need this — the AttachGuard
detach path already decrements via the attach-time
“slot consumed” semantic, and the close trigger
observes the resulting pending == 0 && live == 0
invariant. Provided so external callers (tests, future
pre-map invalidation paths) can adjust the counter
explicitly. Saturating at 0 — calling this on a key
with no pending uses left is a no-op, not an
underflow.
Returns true when the call drove pending to 0
AND live was already 0 (so the entry was eligible
for close). Doesn’t itself trigger close — the close
path runs on detach. Tests that exercise the
counter-only lifecycle use the return to assert the
“eligible for close” gate without setting up a real
attach.
Sourcepub fn pending_uses_for(&self, key: &ResourceKey) -> Option<usize>
pub fn pending_uses_for(&self, key: &ResourceKey) -> Option<usize>
SRD-35 Push D introspection helper: how many predicted
future attaches remain on the entry for key (gen 0).
Returns None when no entry exists for the key.
Tests use this to assert pre-map walker correctness
without poking the pool internals.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ResourcePool
impl Forget for ResourcePool
impl Move for ResourcePool
impl RefUnwindSafe for ResourcePoolwhere
Mutex<PoolInner>: RefUnwindSafe,
impl Send for ResourcePool
impl Sync for ResourcePool
impl Unpin for ResourcePool
impl UnsafeUnpin for ResourcePoolwhere
Align4<u32>: UnsafeUnpin,
Align1<u8>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<((ResourceKey, usize), Arc<Entry>)>: UnsafeUnpin,
impl UnwindSafe for ResourcePoolwhere
Mutex<PoolInner>: UnwindSafe,
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
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> ⓘ
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