Expand description
Shared mode: several active servers on one PostgreSQL database
(orbit server --cluster --cluster-mode shared). Every node serves every
route; executions, worker tasks and worker sessions are spread over them.
- Membership. Every node keeps a row in
orbit_nodesand refreshes its heartbeat (database clock) every second. A node whose heartbeat is older than the node timeout is dead. - Ownership. Each running execution has one owner node and an epoch in
orbit_owners. The node that starts an execution owns it (epoch 1); child workflows share their root’s ownership. Only the owner appends to an execution’s history, and every append checks the epoch withSELECT ... FOR SHAREin its own transaction, as the active/standby cluster checks its term. Live nodes take over a dead node’s executions withUPDATE ... SET epoch = epoch + 1 WHERE node_id = <dead>(one winner per row), spread by rendezvous hashing, and rebuild them from history. - Task queue. The owner writes a row to
orbit_tasksfor every worker task it schedules, in the same transaction as theStepScheduledevent. Any node claims rows for the workers polling it (FOR UPDATE SKIP LOCKED), returns the assignment at once, and tells the owner through the owner’s inbox, so the owner remains the only writer of the history. - Inbox. Commands for an execution owned elsewhere (dispatches made by
other nodes, results, signals, cancellations) go to
orbit_inbox. The owner applies them in order through the ordinary engine methods and deletes each entry in the same transaction as the events it caused. - Worker sessions are stored in
orbit_sessions, so a worker can poll and report through any node, and keep working when a node dies.
See docs/src/runtime/cluster.md (“Shared mode”) for the full picture.
Structs§
- Ctx
- Shared-mode state of one node, held by its engine and its threads.
- Shared
Config
Functions§
- attach
- Turn an engine opened on a
PgMode::Sharedstore into a shared-mode node: creates the shared tables and registers the node. Serve it withcrate::server::serve_node, which starts the node’s threads; the node then resumes or takes over executions. - layer
- Wrap the API router for shared mode:
/v1/ready, the shared fields of/v1/health, fresh definitions, and replies for signals and cancels that were forwarded to another node. - open
- Open a shared-mode engine: builds it (through
factory) on a new shared-mode store andattaches it. - start
- Start the node’s control and notification threads. Called by
crate::server::serve_nodefor a shared-mode engine. - take_
over_ root - Take over one execution tree from
old: every execution ofrootthatoldowns moves tomewith its epoch incremented. Concurrent callers each win a disjoint set of rows (the update re-checksnode_id = oldafter waiting for a competing update). Returns (execution, new epoch).
Type Aliases§
- Engine
Factory - Builds a node’s engine on its store (as for
crate::cluster).