pub struct ResourceLedger { /* private fields */ }Expand description
One process or VM accounting scope. A child ledger reserves its parent first, so aggregate process policy and tenant policy cover the same allocation.
Implementations§
Source§impl ResourceLedger
impl ResourceLedger
pub fn root( scope: impl Into<String>, limits: impl IntoIterator<Item = (ResourceClass, ResourceLimit)>, ) -> Self
pub fn root_with_metrics( scope: impl Into<String>, limits: impl IntoIterator<Item = (ResourceClass, ResourceLimit)>, metrics: RuntimeMetrics, ) -> Self
pub fn child( scope: impl Into<String>, limits: impl IntoIterator<Item = (ResourceClass, ResourceLimit)>, parent: Arc<ResourceLedger>, ) -> Self
pub fn scope(&self) -> &str
Sourcepub fn reserve(
&self,
resource: ResourceClass,
amount: usize,
) -> Result<Reservation, LimitError>
pub fn reserve( &self, resource: ResourceClass, amount: usize, ) -> Result<Reservation, LimitError>
Reserve before allocation. A zero-sized reservation is valid and owns no counters, which lets callers keep one unconditional cleanup path.
pub fn usage(&self, resource: ResourceClass) -> ResourceUsage
pub fn configured_limit(&self, resource: ResourceClass) -> Option<ResourceLimit>
Sourcepub fn capacity_available(&self, resource: ResourceClass, amount: usize) -> bool
pub fn capacity_available(&self, resource: ResourceClass, amount: usize) -> bool
Best-effort readiness probe that does not acquire and immediately drop
a reservation. Admission must still call Self::reserve; this method
exists for POLLOUT-style hints where a transient reservation would emit
a false capacity-change notification and churn blocked producers.
pub fn is_zero(&self) -> bool
pub fn integrity_ok(&self) -> bool
Sourcepub async fn capacity_changed(&self)
pub async fn capacity_changed(&self)
Wait without polling until any owner releases capacity. Callers must retry their full multi-resource admission after this notification.
Sourcepub async fn reserve_when_available(
&self,
resource: ResourceClass,
amount: usize,
) -> Result<Reservation, LimitError>
pub async fn reserve_when_available( &self, resource: ResourceClass, amount: usize, ) -> Result<Reservation, LimitError>
Pause an async source until the requested capacity is available. The notification is armed before each retry so a concurrent release cannot be missed between observing the limit and awaiting capacity.
Trait Implementations§
Source§impl Clone for ResourceLedger
impl Clone for ResourceLedger
Source§fn clone(&self) -> ResourceLedger
fn clone(&self) -> ResourceLedger
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more