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

Method get_or_create

nodedb-mem/src/collection_arena.rs:72–84  ·  view source on GitHub ↗

Return (or create) a dedicated arena for `(tenant_id, collection)`. Idempotent: calling twice with the same key returns the same handle.

(&self, tenant_id: u64, collection: &str)

Source from the content-addressed store, hash-verified

70 ///
71 /// Idempotent: calling twice with the same key returns the same handle.
72 pub fn get_or_create(&self, tenant_id: u64, collection: &str) -> Result<CollectionArenaHandle> {
73 let key = (tenant_id, collection.to_string());
74 let mut guard = self
75 .inner
76 .lock()
77 .map_err(|_| MemError::Jemalloc("collection arena registry lock poisoned".into()))?;
78 if let Some(h) = guard.handles.get(&key) {
79 return Ok(h.clone());
80 }
81 let handle = allocate_handle(tenant_id, collection);
82 guard.handles.insert(key, handle.clone());
83 Ok(handle)
84 }
85
86 /// Look up an existing handle without creating one. Returns `None` when
87 /// the collection has no dedicated arena yet.

Calls 6

allocate_handleFunction · 0.85
to_stringMethod · 0.80
lockMethod · 0.80
getMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45