Skip to main content

Module shared

Module shared 

Source
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_nodes and 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 with SELECT ... FOR SHARE in its own transaction, as the active/standby cluster checks its term. Live nodes take over a dead node’s executions with UPDATE ... 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_tasks for every worker task it schedules, in the same transaction as the StepScheduled event. 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.
SharedConfig

Functions§

attach
Turn an engine opened on a PgMode::Shared store into a shared-mode node: creates the shared tables and registers the node. Serve it with crate::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 and attaches it.
start
Start the node’s control and notification threads. Called by crate::server::serve_node for a shared-mode engine.
take_over_root
Take over one execution tree from old: every execution of root that old owns moves to me with its epoch incremented. Concurrent callers each win a disjoint set of rows (the update re-checks node_id = old after waiting for a competing update). Returns (execution, new epoch).

Type Aliases§

EngineFactory
Builds a node’s engine on its store (as for crate::cluster).