MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / init_governor

Function init_governor

nodedb/src/memory/startup.rs:23–46  ·  view source on GitHub ↗

Initialize the memory governor from engine byte budgets. Called once at startup. The returned governor is shared (via `Arc`) across the Control Plane and all Data Plane cores. `budgets` carries a byte limit for **every** [`EngineId`]; the governor reports any engine without a budget as being at Emergency pressure, which rejects that engine's writes with `resources exhausted`, so the full map is

(
    global_ceiling: usize,
    budgets: &EngineByteBudgets,
)

Source from the content-addressed store, hash-verified

21/// [`crate::config::EngineConfig::to_byte_budgets`], which derives one
22/// entry per `EngineId::ALL` member.
23pub fn init_governor(
24 global_ceiling: usize,
25 budgets: &EngineByteBudgets,
26) -> crate::Result<Arc<MemoryGovernor>> {
27 let engine_limits = budgets.as_engine_limits().clone();
28
29 let config = GovernorConfig {
30 global_ceiling,
31 engine_limits,
32 };
33
34 let governor = MemoryGovernor::new(config).map_err(|e| crate::Error::Config {
35 detail: format!("failed to initialize memory governor: {e}"),
36 })?;
37
38 info!(
39 global_ceiling,
40 engines = EngineId::ALL.len(),
41 total_engine_budget = budgets.total(),
42 "memory governor initialized"
43 );
44
45 Ok(Arc::new(governor))
46}
47
48#[cfg(test)]
49mod tests {

Callers 5

mainFunction · 0.85
init_from_default_configFunction · 0.85
fresh_boot_governorFunction · 0.85

Calls 2

as_engine_limitsMethod · 0.80
cloneMethod · 0.45

Tested by 2

init_from_default_configFunction · 0.68