Skip to main content

TenantLoader

Struct TenantLoader 

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

Tracks which tenants have been hydrated into memory, serializes concurrent first-loads of the same tenant, and accounts for the approximate bytes each loaded tenant occupies (Step 3 cache budget input).

loaded is the source of truth for “is this tenant warm?”. It’s insert-only until Step 3 #2’s mark_unloaded (eviction) lands.

locks holds one Mutex per tenant ever queried. Concurrent first-queries get the same Mutex; the second waiter re-checks loaded after acquiring it (the standard double-checked-lock pattern, sound here because loaded’s DashMap insert happens-before the lock release).

bytes accumulates per-tenant resident-byte estimates as events get spliced in via append_loaded_event. It’s the input the budget-enforcement step (Step 3 #3) keys off — the LRU eviction policy compares the sum of these counters against the configured byte budget.

Implementations§

Source§

impl TenantLoader

Source

pub fn new() -> Self

Source

pub fn with_timeout(load_timeout: Duration) -> Self

Source

pub fn set_byte_budget(&self, budget: u64)

Set the cache byte budget. 0 disables enforcement.

Source

pub fn byte_budget(&self) -> u64

Source

pub fn over_budget(&self) -> bool

True iff a budget is set AND total resident bytes exceed it.

Source

pub fn touch(&self, tenant_id: &str)

Mark tenant_id as just-used (LRU-Y end of the order). Cheap — single DashMap insert. Called on every query that touches this tenant. If the eviction policy picks an LRU victim, the most-recently-touched tenants are last to go.

Source

pub fn pick_lru_excluding(&self, excluded: &str) -> Option<String>

Pick the loaded tenant with the oldest last_used Instant, excluding excluded (the freshly-loaded tenant we don’t want to immediately evict — would thrash). Returns None if no other tenant is loaded — the caller should accept the over-budget state in that case (a single tenant whose data alone exceeds the budget can’t be evicted in favor of itself).

mark_loaded always stamps last_used, so every loaded tenant has a touch timestamp by construction.

Source

pub fn is_loaded(&self, tenant_id: &str) -> bool

Fast path probe — true if a previous call to mark_loaded has succeeded for this tenant.

Source

pub fn mark_loaded(&self, tenant_id: &str)

Record that this tenant has been hydrated. Idempotent. Also stamps a fresh last_used so the tenant immediately participates in LRU ordering and isn’t picked as an eviction victim before its first explicit touch.

Source

pub fn mark_unloaded(&self, tenant_id: &str)

Reverse of mark_loaded: forget that this tenant is in memory and reset its byte counter to 0. The next call to is_loaded returns false; the next ensure-load will re-walk the tenant’s subtree from disk. Called by the eviction path.

Source

pub fn add_bytes(&self, tenant_id: &str, n: u64)

Add n bytes to the resident-size estimate for tenant_id. Called once per event spliced into memory for that tenant. The total is what the budget check compares against.

Source

pub fn bytes_for(&self, tenant_id: &str) -> u64

Resident-byte estimate for a single tenant. Returns 0 for tenants that have never been loaded (or that were evicted — once eviction lands the counter resets to 0).

Source

pub fn total_bytes(&self) -> u64

Sum of resident-byte estimates across every loaded tenant — the input the budget check compares against. O(loaded tenants), expected to be small.

Source

pub fn bytes_per_tenant(&self) -> Vec<(String, u64)>

Snapshot of (tenant_id, bytes) pairs for every tenant that has any resident bytes. Used by the eviction policy to pick a victim and by metrics endpoints.

Source

pub fn lock_for(&self, tenant_id: &str) -> Arc<Mutex<()>>

Get-or-insert the per-tenant Mutex used for singleflight loading. The first caller for a given tenant creates the Mutex; later callers see the same instance and serialize on it. Returns an Arc so the caller can hold the lock guard without keeping a borrow into the DashMap.

Source

pub fn load_timeout(&self) -> Duration

Trait Implementations§

Source§

impl Default for TenantLoader

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,