Skip to main content

Module cluster

Module cluster 

Source
Expand description

Multi-server operation: one active leader, any number of standbys, all on the same PostgreSQL database (orbit server --cluster).

  • Election. Every node keeps a dedicated PostgreSQL session (separate from the store’s connection) and tries pg_try_advisory_lock on a fixed key once per check interval. The session that holds the lock is the leader. PostgreSQL releases the lock when that session ends, so a crashed leader is replaced within about one interval.
  • Fencing. On election the leader increments orbit_cluster.term and opens its store in PgMode::Fenced mode: every history append checks the term inside its own transaction. A deposed leader that has not yet noticed cannot write anything.
  • Liveness. The leader re-checks its session, its lock and the term every interval. It only serves while the last successful check is younger than the lease; when a check fails it steps down to standby in-process (drops its engine and its lock session) and rejoins the election.
  • Standby. A standby serves read-only routes from the database through an engine opened on a PgMode::ReadOnly store, and answers every write and worker route with 503 NOT_LEADER and the leader’s address.

Structs§

ClusterConfig
Node
One cluster member. Created by the CLI, driven by start.

Enums§

Role

Constants§

LEADER_LOCK_KEY
Advisory lock key for leader election (ASCII “orbitldr”).

Functions§

default_node_id
A default node id: $HOSTNAME, /etc/hostname, or a random id.
grpc_gate
gRPC interceptor: on a standby every worker call fails with UNAVAILABLE and orbit-error-code: NOT_LEADER (SDKs retry it like a connection error).
layer
Wrap the API router: adds /v1/ready, the cluster fields of /v1/health, and (in cluster mode) refuses writes on a standby. Runs before authentication, so load balancers can probe /v1/ready without credentials.
start
Start the election thread for node, swapping engines in state as the node gains and loses leadership. state must hold a standby engine (Node::standby_engine) to begin with.

Type Aliases§

EngineFactory
Builds an engine on a store. The CLI passes one that applies the server’s engine configuration and telemetry, so leader and standby engines are configured exactly like a single-node server’s.