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 strCaller tag (used as metric label). Pass the stable
gap-shorthand, e.g. "gap-04-resolve-or-create".
start: InstantMonotonic clock anchor set at construction.
budget_ms: u32Soft budget in milliseconds. Exceeding it yields
Decision::ShouldDefer.
hard_wall_ms: u32Hard wall in milliseconds. Exceeding it yields
HardWallExceeded and aborts the commit.
commit_cid: CidCID 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: boolSticky flag: true once any charge() returns ShouldDefer.
The envelope carries this so replay can short-circuit.
hard_wall_hit: boolSticky flag: true once any charge() returns HardWallExceeded.
Implementations§
Source§impl CommitBudgetGuard
impl CommitBudgetGuard
Sourcepub fn start(
tag: &'static str,
budget_ms: u32,
hard_wall_ms: u32,
commit_cid: Cid,
) -> Self
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.
Sourcepub fn elapsed_ms(&self) -> u32
pub fn elapsed_ms(&self) -> u32
Elapsed milliseconds since construction, saturated to u32::MAX.
Sourcepub fn charge(
&mut self,
stage: &'static str,
) -> Result<Decision, HardWallExceeded>
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.
Sourcepub fn defer(&mut self, stage: &'static str)
pub fn defer(&mut self, stage: &'static str)
Push a stage onto the deferred queue for the next commit.
Sourcepub fn into_report(self) -> CommitBudgetReport
pub fn into_report(self) -> CommitBudgetReport
Freeze the guard into a report for the commit envelope.