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

Method alloc_one

nodedb/src/control/surrogate/registry.rs:91–105  ·  view source on GitHub ↗

Allocate a single surrogate. Returns `Exhausted` if the u32 space is full.

(&self)

Source from the content-addressed store, hash-verified

89 /// Allocate a single surrogate. Returns `Exhausted` if the u32 space
90 /// is full.
91 pub fn alloc_one(&self) -> Result<Surrogate, SurrogateAllocError> {
92 let prev = self.counter.fetch_add(1, Ordering::AcqRel);
93 if prev > u64::from(u32::MAX) {
94 // Restore the counter so future callers also see Exhausted
95 // rather than racing past us into a wrapped value. We don't
96 // need atomicity with the racing increments — once any caller
97 // observes `prev > u32::MAX`, the space is effectively dead.
98 self.counter
99 .store(u64::from(u32::MAX) + 1, Ordering::Release);
100 return Err(SurrogateAllocError::Exhausted);
101 }
102 self.allocs_since_flush.fetch_add(1, Ordering::AcqRel);
103 // Safe: prev <= u32::MAX is guaranteed by the check above.
104 Ok(Surrogate::new(prev as u32))
105 }
106
107 /// Allocate `n` contiguous surrogates as an inclusive range.
108 /// Returns `EmptyBatch` for `n == 0`, `Exhausted` if the batch

Callers 13

assignMethod · 0.45
assign_anonymousMethod · 0.45
monotonic_10kFunction · 0.45
restart_survives_hwmFunction · 0.45
flush_threshold_opsFunction · 0.45
flush_threshold_elapsedFunction · 0.45
handle_create_databaseFunction · 0.45
handle_clone_databaseFunction · 0.45

Calls 1

storeMethod · 0.45

Tested by 8

monotonic_10kFunction · 0.36
restart_survives_hwmFunction · 0.36
flush_threshold_opsFunction · 0.36
flush_threshold_elapsedFunction · 0.36