Skip to main content

Module lease_loop

Module lease_loop 

Source
Expand description

Serverless writer-lease boot path (PLAN.md Phase 5 / W6).

Boot-time entrypoint that opts the runtime into lease-fenced writes when:

  • RED_LEASE_REQUIRED=true (or 1) is set, and
  • a remote backend is configured (S3, FS, HTTP, …).

All transitions (acquire / refresh / lost / release) are delegated to LeaseLifecycle; this module only owns env-var parsing, lifecycle construction, and the refresh thread.

The refresh thread uses LeaseTimerWheel instead of a fixed thread::sleep(ttl_ms / 3) polling loop. The wheel wakes the thread exactly when the next refresh is due and reschedules after each successful refresh, so idle leases cost zero CPU.

Env knobs:

  • RED_LEASE_REQUIREDtrue / 1 to enable. Default off.
  • RED_LEASE_TTL_SECS — lease TTL in seconds. Default 60.
  • RED_LEASE_HOLDER_ID — explicit holder id. Default <hostname>-<pid>.
  • RED_LEASE_PREFIX — backend prefix for the lease object key. Default leases/.

Functions§

start_lease_loop_if_required
Try to start the writer-lease lifecycle if the operator opted in. Returns Ok(()) when: