Check engine-level memory pressure at the start of a write handler. - `Normal` / `Warning`: returns `None` — proceed normally. - `Critical`: increments the critical metric counter, returns `None` (handler proceeds; engine-specific flush is the handler's own responsibility — see timeseries ingest for the pattern). - `Emergency`: increments the emergency metric counter, returns `Some(Response)` wit
(
&self,
task: &ExecutionTask,
engine: EngineId,
)
| 41 | /// `Some(Response)` with `ErrorCode::ResourcesExhausted`. The caller |
| 42 | /// must return this response immediately without executing the write. |
| 43 | pub fn check_engine_pressure( |
| 44 | &self, |
| 45 | task: &ExecutionTask, |
| 46 | engine: EngineId, |
| 47 | ) -> Option<Response> { |
| 48 | let governor = self.governor.as_ref()?; |
| 49 | let pressure = governor.engine_pressure(engine); |
| 50 | match pressure { |
| 51 | PressureLevel::Normal | PressureLevel::Warning => None, |
| 52 | PressureLevel::Critical => { |
| 53 | if let Some(ref m) = self.metrics { |
| 54 | m.record_backpressure_critical(&engine.to_string()); |
| 55 | } |
| 56 | warn!( |
| 57 | core = self.core_id, |
| 58 | engine = %engine, |
| 59 | "Critical memory pressure — proceeding with engine-specific flush" |
| 60 | ); |
| 61 | None |
| 62 | } |
| 63 | PressureLevel::Emergency => { |
| 64 | if let Some(ref m) = self.metrics { |
| 65 | m.record_backpressure_emergency(&engine.to_string()); |
| 66 | } |
| 67 | warn!( |
| 68 | core = self.core_id, |
| 69 | engine = %engine, |
| 70 | "Emergency memory pressure — rejecting write with backpressure" |
| 71 | ); |
| 72 | Some(self.response_error(task, ErrorCode::ResourcesExhausted)) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /// Adjust SPSC read depth based on worst-case pressure across all engines. |
| 78 | /// |