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

Method record

nodedb-bridge/src/telemetry.rs:100–116  ·  view source on GitHub ↗

Record a metric sample (called from Data Plane core). Lock-free, allocation-free. If the ring is full, the oldest sample is overwritten and the drop counter incremented.

(&mut self, sample: MetricSample)

Source from the content-addressed store, hash-verified

98 /// Lock-free, allocation-free. If the ring is full, the oldest sample
99 /// is overwritten and the drop counter incremented.
100 pub fn record(&mut self, sample: MetricSample) {
101 let pos = self.write_pos.load(Ordering::Relaxed);
102 let read = self.read_pos.load(Ordering::Relaxed);
103
104 // If we've lapped the reader, advance the reader (drop oldest).
105 if pos.wrapping_sub(read) >= self.capacity as u64 {
106 self.read_pos.store(
107 pos.wrapping_sub(self.capacity as u64 - 1),
108 Ordering::Relaxed,
109 );
110 self.dropped.fetch_add(1, Ordering::Relaxed);
111 }
112
113 let idx = (pos as usize) & self.mask;
114 self.slots[idx] = sample;
115 self.write_pos.store(pos.wrapping_add(1), Ordering::Release);
116 }
117
118 /// Drain all available samples into the provided buffer (called from Control Plane).
119 ///

Callers 2

basic_record_and_drainFunction · 0.45
overflow_drops_oldestFunction · 0.45

Calls 2

loadMethod · 0.45
storeMethod · 0.45

Tested by 2

basic_record_and_drainFunction · 0.36
overflow_drops_oldestFunction · 0.36