Skip to main content

CommitBudgetGuard

Struct CommitBudgetGuard 

Source
pub struct CommitBudgetGuard {
    pub tag: &'static str,
    pub start: Instant,
    pub budget_ms: u32,
    pub hard_wall_ms: u32,
    pub commit_cid: Cid,
    pub deferred: Vec<&'static str>,
    pub charged: Vec<(&'static str, u32)>,
    pub breached: bool,
    pub hard_wall_hit: bool,
}
Expand description

Shared wall-clock budget envelope for a commit’s variable-cost stages.

See the module docs for wiring semantics and determinism notes.

Fields§

§tag: &'static str

Caller tag (used as metric label). Pass the stable gap-shorthand, e.g. "gap-04-resolve-or-create".

§start: Instant

Monotonic clock anchor set at construction.

§budget_ms: u32

Soft budget in milliseconds. Exceeding it yields Decision::ShouldDefer.

§hard_wall_ms: u32

Hard wall in milliseconds. Exceeding it yields HardWallExceeded and aborts the commit.

§commit_cid: Cid

CID of the commit this guard is embedded in, stored in the envelope for replay determinism.

§deferred: Vec<&'static str>

Stages deferred to the next commit (pushed by Self::defer).

§charged: Vec<(&'static str, u32)>

Stages charged so far; order-preserving for the envelope.

§breached: bool

Sticky flag: true once any charge() returns ShouldDefer. The envelope carries this so replay can short-circuit.

§hard_wall_hit: bool

Sticky flag: true once any charge() returns HardWallExceeded.

Implementations§

Source§

impl CommitBudgetGuard

Source

pub fn start( tag: &'static str, budget_ms: u32, hard_wall_ms: u32, commit_cid: Cid, ) -> Self

Start a new guard. hard_wall_ms >= budget_ms is enforced by clamping hard_wall to at least budget; an explicit violation would be a caller-bug but we accept the floor silently.

Source

pub fn elapsed_ms(&self) -> u32

Elapsed milliseconds since construction, saturated to u32::MAX.

Source

pub fn charge( &mut self, stage: &'static str, ) -> Result<Decision, HardWallExceeded>

Charge the running elapsed after a completed stage.

Returns Err(HardWallExceeded) if the elapsed exceeds hard_wall_ms - caller aborts. Returns Ok(Decision::ShouldDefer) if it exceeds budget_ms but not the hard wall - caller should stop doing new work and defer the remaining stages. Returns Ok(Decision::Proceed) otherwise.

§Errors

Returns HardWallExceeded when the running elapsed would exceed hard_wall_ms.

Source

pub fn defer(&mut self, stage: &'static str)

Push a stage onto the deferred queue for the next commit.

Source

pub fn into_report(self) -> CommitBudgetReport

Freeze the guard into a report for the commit envelope.

Trait Implementations§

Source§

impl Debug for CommitBudgetGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> 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<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