Evict one entry from the shard with the highest overshoot ratio. Among shards with equal overshoot ratios, `hint_db_id` (the inserting shard) is preferred so that a cold shard at its proportional share is never displaced in favour of the hot inserting shard. Returns `false` if all shards are empty.
(&mut self, hint_db_id: u64)
| 348 | /// |
| 349 | /// Returns `false` if all shards are empty. |
| 350 | fn evict_from_highest_overshoot(&mut self, hint_db_id: u64) -> bool { |
| 351 | let total_weight = self.total_weight(); |
| 352 | let db_id = self |
| 353 | .shards |
| 354 | .iter() |
| 355 | .filter(|(_, s)| !s.entries.is_empty()) |
| 356 | .max_by_key(|(id, s)| { |
| 357 | let score = s.overshoot_score(total_weight); |
| 358 | // Prefer the inserting shard on ties so equal-ratio cold shards |
| 359 | // are not evicted in its place. |
| 360 | let is_hint = u8::from(**id == hint_db_id); |
| 361 | (score, is_hint) |
| 362 | }) |
| 363 | .map(|(&id, _)| id); |
| 364 | match db_id { |
| 365 | Some(id) => { |
| 366 | let removed = self.shards.get_mut(&id).expect("just found").evict_one(); |
| 367 | if removed { |
| 368 | self.total = self.total.saturating_sub(1); |
| 369 | } |
| 370 | removed |
| 371 | } |
| 372 | None => false, |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | #[cfg(test)] |
no test coverage detected