Drain the memtable, returning all buffered data organized by series.
(&mut self)
| 225 | |
| 226 | /// Drain the memtable, returning all buffered data organized by series. |
| 227 | pub fn drain(&mut self) -> Vec<FlushedSeries> { |
| 228 | let mut result = Vec::with_capacity(self.series.len() + self.evicted.len()); |
| 229 | result.append(&mut self.evicted); |
| 230 | |
| 231 | for (series_id, buf) in self.series.drain() { |
| 232 | match buf { |
| 233 | SeriesBuffer::Metric(m) => { |
| 234 | let sample_count = m.sample_count; |
| 235 | let compressed = m.encoder.finish(); |
| 236 | result.push(FlushedSeries { |
| 237 | series_id, |
| 238 | kind: FlushedKind::Metric { |
| 239 | gorilla_block: compressed, |
| 240 | sample_count, |
| 241 | }, |
| 242 | min_ts: m.min_ts, |
| 243 | max_ts: m.max_ts, |
| 244 | }); |
| 245 | } |
| 246 | SeriesBuffer::Log(l) => { |
| 247 | result.push(FlushedSeries { |
| 248 | series_id, |
| 249 | kind: FlushedKind::Log { |
| 250 | entries: l.entries, |
| 251 | total_bytes: l.total_bytes, |
| 252 | }, |
| 253 | min_ts: l.min_ts, |
| 254 | max_ts: l.max_ts, |
| 255 | }); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | self.series_meta.clear(); |
| 261 | self.memory_bytes = 0; |
| 262 | self.metric_count = 0; |
| 263 | self.log_count = 0; |
| 264 | self.oldest_ts = None; |
| 265 | |
| 266 | result |
| 267 | } |
| 268 | |
| 269 | pub fn metric_count(&self) -> u64 { |
| 270 | self.metric_count |