This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.

Fleet

import std/fleet

Koru Standard Library: fleet — nodes that share one `world`.

fleet.kz · 9 tors

Koru Standard Library: fleet — nodes that share one `world`. · 37 more lines
Koru Standard Library: fleet — nodes that share one `world`. std/fleet:claim(world: "cells", id: "room-42", node: "node-a") | claimed e |> ... // e is the granted epoch | held-by o |> ... // o is the owning node's id | failed e |> ... A fleet is not a resource — it is a PROTOCOL over the world directory, the same role the object-store bucket plays in celld: the shared floor is the only coordinator, so there is no membership protocol to write. Layout under `<world>/.fleet/`: owners/<id> exists iff the cell is owned. `node=<nid>\nepoch=<n>\nuntil=<unix-ms>`. `until` is the lease deadline — a wall-clock time every process on the floor reads the same way; 0 means un-leased. Written by createNew (claim — the CAS) or tmp+rename (seize/expired claim — the atomic takeover commit). epochs/<id> persistent counter, survives `release`. Every claim and seize bumps it, so a stale epoch can never collide with a fresh one — that is what makes `guard` a fence. std/fleet:guard(world:, id:, node:, epoch:) // the write-time fence | owner |> ... // record still names this node+epoch | fenced e |> ... // e is the epoch now on record | free |> ... // no owner record at all celld-alignment, honest limits: `claim` is the conditional-write analog, `seize` is takeover-after-crash, `guard` is the epoch fence enforced where celld enforces it — at the write. Leases are spelled: `ttl-ms` on claim, seize and renew, and an expired record is claimable — the takeover runs the same serialized bump+commit seize does. `std/node` renews on activity (lease-ms): residency is the heartbeat, no thread. Routing is spelled as a mailbox: `send` posts to `.fleet/inbox/<id>` and `drain` delivers owner-side under the lock — `std/net` stays a refusal surface. The epoch counter is advisory under true races; the node-id half of guard is what carries correctness.

~part acquire koru_std/fleet.acquire.kz

Koru Standard Library: the `acquire` part of fleet — the claim path `std/node` and `std/cell` call from host code. Joined via `~part acquire`. Caller ends up holding the id, learns the foreign owner (`nb`), or fails.

~part fence koru_std/fleet.fence.kz

Koru Standard Library: the `fence` part of fleet — read-back helpers: foreign-owner probe, the write-time guard, owner-scoped release. Joined via `~part fence` in fleet.kz. The record's owner if foreign — the slice lives in `nb`.

~part lease koru_std/fleet.lease.kz

Koru Standard Library: the `lease` part of fleet — takeover and lease renewal. seize is operator-decided takeover; an expired-lease claim runs the same serialized bump+commit. Joined via `~part lease` in fleet.kz.

~part mail koru_std/fleet.mail.kz

Koru Standard Library: the `mail` part of fleet — routing over the floor. Joined via `~part mail` in fleet.kz; merged into the fleet module at load. `.fleet/inbox/<id>/` is a mailbox that belongs to the CELL, not the node: a caller refused `held-by` leaves a turn for the owner of record, and the message survives takeover and ownership gaps — whoever holds the id next drains what was posted to it. `send` is multi-producer: every message is a uniquely-named file committed tmp+rename, so a reader never sees half a message and no two senders collide. `drain` is owner-side delivery: under the lock (serialized against seize and a second drainer), guarded (a stale owner answers `held-by`), ordered by send-time filename, and at-least-once — each file deletes only after the `! mail` arm returns, so a crash inside the arm redelivers on the next drain.

~part renew koru_std/fleet.renew.kz

Koru Standard Library: the `renew` part of fleet — lease renewal. Joined via `~part renew` in fleet.kz; merged into the fleet module at load. Renewal is piggyback, celld's ttl/3 cadence without a heartbeat thread: every activity path (acquire-hit, durable write, the explicit verb) renews when the deadline is inside its last third, so a live owner stays held and a dead one's leases lapse. Renews when the deadline is inside its last TTL third; returns the deadline now in force so callers can cache it. The lock is required: an unlocked renew could overwrite a committed takeover with the stale epoch it read before the lock.