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

Method tick

nodedb/src/control/lease/renewal.rs:172–217  ·  view source on GitHub ↗

One iteration: snapshot the near-expiry lease set under a short read lock, then re-acquire each one. Errors are logged at warn — the next tick retries automatically. Why we use wall-clock nanoseconds, not `hlc_clock.peek()`**: `peek` returns the last HLC the clock observed, which may be frozen at the moment the lease was stamped if nothing else has advanced the clock since. We want "real time now

(&self)

Source from the content-addressed store, hash-verified

170 /// and avoids spuriously classifying leases as "not near
171 /// expiry" just because the HLC hasn't ticked.
172 fn tick(&self) {
173 let Some(shared) = self.shared.upgrade() else {
174 return;
175 };
176 let now_wall_ns = super::wall_now_ns();
177 let near_expiry = collect_near_expiry(&shared, now_wall_ns, &self.config);
178 if near_expiry.is_empty() {
179 return;
180 }
181 debug!(
182 count = near_expiry.len(),
183 "descriptor lease renewal: re-acquiring near-expiry leases"
184 );
185 for (id, held_version) in near_expiry {
186 let current_version = lookup_current_version(&shared, &id);
187 match current_version {
188 Some(v) => {
189 let version = v.max(held_version);
190 if let Err(e) = super::propose::force_refresh_lease(
191 &shared,
192 id.clone(),
193 version,
194 self.config.full_duration,
195 ) {
196 warn!(
197 descriptor = ?id,
198 version,
199 error = %e,
200 "descriptor lease renewal: re-acquire failed"
201 );
202 self.loop_metrics.record_error("renew");
203 }
204 }
205 None => {
206 if let Err(e) = super::release::release_leases(&shared, vec![id.clone()]) {
207 warn!(
208 descriptor = ?id,
209 error = %e,
210 "descriptor lease renewal: release after drop failed"
211 );
212 self.loop_metrics.record_error("release");
213 }
214 }
215 }
216 }
217 }
218}
219
220/// Look up the current persisted version for a descriptor.

Callers 7

spawn_expiry_taskFunction · 0.45
spawn_flush_taskFunction · 0.45
spawn_refresh_taskFunction · 0.45
spawn_drain_taskFunction · 0.45
runMethod · 0.45
start_sync_listenerFunction · 0.45

Calls 8

collect_near_expiryFunction · 0.85
lookup_current_versionFunction · 0.85
force_refresh_leaseFunction · 0.85
release_leasesFunction · 0.85
record_errorMethod · 0.80
wall_now_nsFunction · 0.70
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected