Flush as many items from the WFQ into the physical ring as will fit. Updates per-DB pressure states and returns the number of items flushed. `try_push` consumes the request by value, so a failure on push would drop the request. The two failure modes are handled explicitly so nothing is lost silently: - `BridgeError::Full` is unreachable: the SPSC ring has a single producer (this dispatcher), and
(&mut self)
| 116 | /// logic can observe them, and the next dispatch attempt will see |
| 117 | /// the disconnected state. |
| 118 | fn flush_wfq(&mut self) -> usize { |
| 119 | let mut flushed = 0; |
| 120 | while self.request_tx.utilization() < 100 { |
| 121 | let Some(req) = self.wfq.pop_next() else { |
| 122 | break; |
| 123 | }; |
| 124 | let db_id = req.database_id.as_u64(); |
| 125 | let req_id = req.request_id.as_u64(); |
| 126 | match self.request_tx.try_push(BridgeRequest { inner: req }) { |
| 127 | Ok(()) => { |
| 128 | flushed += 1; |
| 129 | self.update_db_pressure(db_id); |
| 130 | } |
| 131 | Err(BridgeError::Full { capacity, pending }) => { |
| 132 | unreachable!( |
| 133 | "SPSC ring reported Full (capacity={capacity}, pending={pending}) \ |
| 134 | despite utilization < 100 immediately before push — \ |
| 135 | single-producer invariant violated" |
| 136 | ); |
| 137 | } |
| 138 | Err(e @ BridgeError::Disconnected { .. }) => { |
| 139 | error!( |
| 140 | request_id = req_id, |
| 141 | database_id = db_id, |
| 142 | "data plane core disconnected during WFQ flush — stopping; request was lost: {e}" |
| 143 | ); |
| 144 | break; |
| 145 | } |
| 146 | Err( |
| 147 | e @ (BridgeError::Empty |
| 148 | | BridgeError::Backpressure { .. } |
| 149 | | BridgeError::DeadlineExceeded { .. }), |
| 150 | ) => { |
| 151 | // `Producer::try_push` only ever produces `Full` or |
| 152 | // `Disconnected`; these other variants are returned by |
| 153 | // consumer/backpressure paths and cannot reach here. |
| 154 | unreachable!("Producer::try_push returned non-producer BridgeError: {e}"); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | flushed |
| 159 | } |
| 160 | |
| 161 | /// Recompute and store the pressure state for a single database. |
| 162 | fn update_db_pressure(&mut self, database_id: u64) { |
no test coverage detected