Insert decompressed partition data into the cache.
(&mut self, tenant_id: u64, collection: &str, partition: CachedPartition)
| 73 | |
| 74 | /// Insert decompressed partition data into the cache. |
| 75 | pub fn insert(&mut self, tenant_id: u64, collection: &str, partition: CachedPartition) { |
| 76 | let key = (tenant_id, collection.to_string(), partition.min_ts); |
| 77 | let size = partition.memory_bytes; |
| 78 | |
| 79 | if size > self.max_bytes { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | // Remove existing entry for this key. |
| 84 | if let Some(old) = self.entries.remove(&key) { |
| 85 | self.current_bytes -= old.memory_bytes; |
| 86 | self.order.retain(|k| k != &key); |
| 87 | } |
| 88 | |
| 89 | // Evict until room. |
| 90 | while self.current_bytes + size > self.max_bytes { |
| 91 | if let Some(evict_key) = self.order.pop_front() { |
| 92 | if let Some(evicted) = self.entries.remove(&evict_key) { |
| 93 | self.current_bytes -= evicted.memory_bytes; |
| 94 | } |
| 95 | } else { |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | self.current_bytes += size; |
| 101 | self.order.push_back(key.clone()); |
| 102 | self.entries.insert(key, partition); |
| 103 | } |
| 104 | |
| 105 | /// Evict partitions that are no longer in the hot window. |
| 106 | pub fn evict_cold(&mut self, now_ms: i64) { |