pub struct TenantContext;Expand description
Thread-safe tenant context for scoping store operations.
Uses tokio::task_local! to propagate tenant identity into store calls
without changing the TaskStore trait.
It carries two things. The tenant (current) is what
per-tenant policy reads: the halt switch, concurrency quotas, audit chains,
metric labels. The partition (partition) is what
the tenant-aware stores key records by. They are the same unless the
handler isolates callers (the default with an authenticating interceptor;
see RequestHandlerBuilder::isolate_tasks_by_caller),
in which case the partition also names the authenticated caller, so one
caller’s tasks are not another’s (spec §13.1) while a tenant stays one
tenant for everything else.
Implementations§
Source§impl TenantContext
impl TenantContext
Sourcepub async fn scope<F, R>(tenant: impl Into<String>, f: F) -> Rwhere
F: Future<Output = R>,
pub async fn scope<F, R>(tenant: impl Into<String>, f: F) -> Rwhere
F: Future<Output = R>,
Runs a future within a tenant scope.
All TenantAwareInMemoryTaskStore operations executed within f
will be scoped to the given tenant. A caller scope set outside this
one stays in force inside it.
Sourcepub fn partition() -> String
pub fn partition() -> String
The key the tenant-aware stores partition records by: the tenant, or, inside a caller scope, the tenant and the caller.
Sourcepub fn capture() -> CapturedTenant
pub fn capture() -> CapturedTenant
Snapshots the tenant and caller, to re-enter both in a spawned task:
task-locals do not cross tokio::spawn, and a background processor
that re-entered only the tenant would write the caller’s task into the
tenant’s partition, where its owner could no longer find it.
Auto Trait Implementations§
impl Forget for TenantContext
impl Freeze for TenantContext
impl Move for TenantContext
impl RefUnwindSafe for TenantContext
impl Send for TenantContext
impl Sync for TenantContext
impl Unpin for TenantContext
impl UnsafeUnpin for TenantContext
impl UnwindSafe for TenantContext
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].