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

Method get_or_create

nodedb/src/control/metrics/database.rs:65–78  ·  view source on GitHub ↗

Get or create the counter handle for `db_name`. The returned `Arc ` is stable for the process lifetime.

(&self, db_name: &str)

Source from the content-addressed store, hash-verified

63 ///
64 /// The returned `Arc<DatabaseCounters>` is stable for the process lifetime.
65 pub fn get_or_create(&self, db_name: &str) -> Arc<DatabaseCounters> {
66 // Fast path: read lock.
67 {
68 let r = self.counters.read().unwrap_or_else(|p| p.into_inner());
69 if let Some(c) = r.get(db_name) {
70 return Arc::clone(c);
71 }
72 }
73 // Slow path: write lock.
74 let mut w = self.counters.write().unwrap_or_else(|p| p.into_inner());
75 w.entry(db_name.to_string())
76 .or_insert_with(|| Arc::new(DatabaseCounters::default()))
77 .clone()
78 }
79
80 /// Increment the QPS counter for `db_name` by 1.
81 pub fn record_qps(&self, db_name: &str) {

Callers 15

record_qpsMethod · 0.45
set_memory_bytesMethod · 0.45
set_storage_bytesMethod · 0.45
set_connectionsMethod · 0.45
set_wal_latency_p99Method · 0.45
set_mirror_lag_msMethod · 0.45
record_qps_incrementsFunction · 0.45
applied_index_watcherMethod · 0.45

Calls 6

entryMethod · 0.80
to_stringMethod · 0.80
readMethod · 0.45
getMethod · 0.45
writeMethod · 0.45
cloneMethod · 0.45