tofu_worker_clock
ToFu · Shared monotonic worker-lease clock and server epoch for ToFu
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102270 | tofu_worker_clock | ToFu | 1.0 | FUNC | MIT | C |
PostgreSQL · 17, 18
Usage
Sources:
tofu_worker_clock 1.0 supplies ToFu SQL worker operations with a server-owned lease clock and epoch. It requires PostgreSQL 17 or newer and is a separate native module inside the ToFu application repository. The application release number is not the extension’s control version.
Core Workflow
The deployment operator installs matching extension files and creates the extension as a superuser in each participating database. Application startup does not install it. The fixed schema is public.
The function returns JSONB containing format, epoch, nowMs, utcMs and stateBytes. nowMs is the shared high-water lease time; utcMs is sampled wall-clock time. Keep absolute UTC scheduling separate from elapsed lease expiry. epoch identifies the server lifetime; ToFu additionally scopes that identity by database OID.
Lifetime and Failure Boundaries
The first call lazily creates bounded shared dynamic-memory state. Other sessions share it; closing clients or replacing a connection pool does not reset it. No preload, clock table, background worker or restart is needed to enable the function.
Restarting PostgreSQL creates a new epoch and revokes prior ToFu lease authority. This is not a persistent sequence, cross-server clock or guarantee that wall time cannot move backwards. The upstream SQL worker layer rejects missing or incompatible output rather than falling back to client time. Restrict installation privileges and preserve the exact result contract when integrating it with worker claims.