Skip to main content

nodedb_mem/
error.rs

1use crate::engine::EngineId;
2
3/// Errors produced by the memory governor.
4#[derive(Debug, thiserror::Error)]
5pub enum MemError {
6    /// Allocation request exceeds the engine's remaining budget.
7    #[error(
8        "memory budget exhausted for {engine:?}: requested {requested} bytes, \
9         available {available} bytes (limit: {limit} bytes)"
10    )]
11    BudgetExhausted {
12        engine: EngineId,
13        requested: usize,
14        available: usize,
15        limit: usize,
16    },
17
18    /// The global memory ceiling would be exceeded.
19    #[error(
20        "global memory ceiling exceeded: total allocated {allocated} bytes, \
21         ceiling {ceiling} bytes, requested {requested} bytes"
22    )]
23    GlobalCeilingExceeded {
24        allocated: usize,
25        ceiling: usize,
26        requested: usize,
27    },
28
29    /// Engine is not registered with the governor.
30    #[error("unknown engine: {0:?}")]
31    UnknownEngine(EngineId),
32
33    /// jemalloc introspection error.
34    #[error("jemalloc error: {0}")]
35    Jemalloc(String),
36
37    /// Overflow region error (mmap, I/O, or capacity).
38    #[error("overflow region error: {0}")]
39    Overflow(String),
40}
41
42pub type Result<T> = std::result::Result<T, MemError>;