Expand description
Generic resource lifecycle and sharing pool — SRD-35 Push A.
§What this module provides
Trait surface and runtime structure for sharing long-lived resources (CQL sessions, HTTP clients, …) across phases of one session, decoupled from per-phase adapter shells. The contract is intentionally generic — nothing here is CQL-specific.
§Core types
SharedResource— the trait every poolable resource implements. CarriesSharedResource::can_share(capability declaration: thread-safe + designed for sharing) andSharedResource::can_support_more_load(driver’s runtime judgement that another instance would relieve knowable, substantial contention) — see the SRD-35 load-bearing rules.ResourceKey— value-equality identity. Two keys compare equal iff their adapter name and fields match exactly. No derived hash function; the contract is structural.ShareCapability— strictest sharing the resource type tolerates. Read by the pool at planning time without an instance.ResourceSharePolicy— user-elevatable isolation policy. Must satisfypolicy >= capability_floor.ResourcePool— owns the(ResourceKey, generation) → Entrymap, tracks refcounts, emits lifecycle events.
§Push A scope
Push A lays the trait foundation, the pool data
structure, the lifecycle event emission, and a
LegacyAdapterResource shim that wraps the existing
Arc<dyn DriverAdapter> factories under PerPhase
policy. Behaviour is byte-identical to today (a fresh
resource per phase) but every phase boundary now emits
the full resource.{attach,init,detach,close} event
sequence.
Push B will migrate the CQL adapter to Shared policy
by splitting CqlAdapter into a per-phase shell + a
CassDriverInstance that implements SharedResource
directly with real async close(). The pool’s
multi-generation machinery is in place but exercised
only by the synthetic mock resource in tests until then.
Structs§
- Attach
Guard - Owns an attached resource for the duration of one phase
activation. Drop emits
resource.detachand, when the entry’s refcount has fully drained, schedules an asyncclose()(and emitsresource.close.*events around it). - Legacy
Adapter Resource - Wraps an
Arc<dyn DriverAdapter>from the existing per-phase factory underPerPhasepolicy. Used until each adapter migrates to a realSharedResourceimpl (Push B for CQL, Push C for HTTP / OpenAPI / stdout). - Resource
Factory - Closure-shaped factory for building a resource the first
time its key is attached. Boxed so the pool can hold it
across
.awaitpoints and so callers don’t have to type the future signature inline. - Resource
Key - Structural value identity for a shared resource.
- Resource
Pool - One
(ResourceKey, generation)map for the lifetime of one session. Owns lazy init, refcount transitions, and the close trigger. - Shared
Adapter Resource - Push B sibling of
LegacyAdapterResource— wraps anArc<dyn DriverAdapter>but declarescan_share()=true. Used when an adapter has registered acrate::adapter::SharedDriverRegistrationopting it into pool-shared semantics. The pool caches the underlyingArc<dyn DriverAdapter>and hands the same clone to every phase whose params produce the sameResourceKey.
Enums§
- Resource
Share Policy - User-selectable isolation. Must satisfy
policy >= capability_floor. - Share
Capability - Strongest sharing the resource type can tolerate.
Declared by the factory at registration time so the pool
can plan the entry layout without configuring or
instantiating any resource. The live instance’s
SharedResource::can_shareis a runtime safety net that aborts the session if it disagrees with this type-level declaration.
Traits§
- Shared
Resource - The trait every poolable resource implements.
Functions§
- attach
- Public attach call. Builds (or reuses) the entry for
keyunderpolicy, lazily realises the resource viafactoryif this is the first attach, emitsresource.attach, and returns a guard that detaches on drop. - attach_
legacy_ adapter - Push A high-level helper for the executor: attach a
legacy adapter through the pool under
PerPhasepolicy and return both the unwrappedArc<dyn DriverAdapter>and the correspondingAttachGuard. - attach_
shared_ adapter - Push B high-level helper: attach a shareable adapter
through the pool under
Sharedpolicy. The first phase whose params producekeytriggersfactory; every subsequent matching phase reuses the sameArc<dyn DriverAdapter>. Each call returns a fresh guard; the pool’s refcount drops the entry only when every guard is released. - capability_
floor - Minimum policy compatible with the given capability. Used by the pool to validate user-supplied policies at session start.
- default_
policy_ for - Default sharing policy — the strongest sharing the capability allows. Used when the user gives no override.
- install_
accessor - SRD-104 — point the resource bridge at
pool. Called once at session start where theResourcePoolis created. - pool_
resources - A resource scope with the pool bridge installed: what every nmbrs
kernel tree is compiled with at its root
(
crate::bindings::compile_scope_kernel). A kernel bound under the tree joins its scope, so a node anywhere in it that capturedctx.resources()resolves pool resources by key. - pre_
map_ pending_ uses - Walk the freshly-pre-mapped scenario tree and seed the
pool’s
pending_usescounter for every phase that will attach a pool-shareable adapter. Called once at session bootstrap, after [crate::executor::pre_map_tree] returns and before the executor begins running any phase.
Type Aliases§
- Resource
Future - One async-init-and-close return type used by the
trait. Returns a
Sendfuture so the pool can hold it across.awaitpoints without runtime fuss.