MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / drain

Method drain

nodedb/src/engine/timeseries/memtable.rs:227–267  ·  view source on GitHub ↗

Drain the memtable, returning all buffered data organized by series.

(&mut self)

Source from the content-addressed store, hash-verified

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

Calls 5

lenMethod · 0.45
appendMethod · 0.45
finishMethod · 0.45
pushMethod · 0.45
clearMethod · 0.45