Skip to main content

Module cluster

Module cluster 

Source
Expand description

Runtime state shared across replicas through Redis (18.22.0). Runtime state shared across replicas (18.22.0, #76).

With [cluster] redis = "host:port" (else [acme] redis), changes made on one replica through the admin API, rws ctl or the MCP tools — the IP blocklist, maintenance mode, drained backends, feature flags and cache purges — reach every replica within about a second.

How: one JSON document per cluster (<prefix>state) holds the shared state and a version. A change is applied locally first, then sent to Redis as an operation that a Lua script applies to the document atomically (Redis’s cjson), so concurrent changes on different replicas never overwrite each other. Every replica reads the document once a second and, when its version moved, makes its own state match. With Redis down, local changes still apply and are sent once it’s back; a replica that starts adopts the document. Each replica also writes a heartbeat into <prefix>nodes, which GET /admin/api/v1/status lists.

The admin operations (crate::admin::ops) publish; code that changes crate::blocklist::global or the feature store directly stays local.

Structs§

ClusterSync
One replica’s view of the cluster: the store, what it applied last, and operations waiting for the store to come back.
MemoryStore
The document in memory: for tests (several replicas in one process) and as a reference for the Lua script’s rules.
ProcessState
The process-wide blocklist, maintenance switch, upstream drains, feature flags and named caches.
RedisStore
The document in Redis.
State
The shared document.

Enums§

Op
One change to the shared state.

Constants§

HEARTBEAT
How often a heartbeat is written; nodes silent for 60 s drop out.
POLL
How often the shared document is read.
PURGES_KEPT
Purges kept in the document (older ones have been applied by then).
RWS_CONFIG_CLUSTER_PREFIX
RWS_CONFIG_CLUSTER_REDIS
[cluster] settings.
RWS_CONFIG_CLUSTER_REDIS_PASSWORD

Traits§

Local
Makes this process’s runtime state match a State; the default applies to the process-wide stores.
Store
Where the shared document lives.

Functions§

publish
Send a change made on this replica to the others (no-op without [cluster]).
start_from_env
The binary’s entry point: with [cluster] redis (or [acme] redis), start syncing on a thread of its own.
status_json
The cluster status for the admin API, or None without [cluster].