Public API for distributed state sharing.
This namespace provides the public interface for cluster functionality:
Configuration example: {:cluster {:enabled true :node-id "auto" :bind-address "0.0.0.0" :bind-port 7946 :seeds ["192.168.1.10:7946" "192.168.1.11:7946"] :gossip-interval-ms 200 :gossip-fanout 2 :push-pull-interval-ms 10000 :sync-health true :sync-circuit-breaker true :sync-drain true :sync-conntrack true}}
Public API for distributed state sharing.
This namespace provides the public interface for cluster functionality:
- Cluster lifecycle (start!/stop!)
- State broadcasting
- Membership queries
- Event subscription
Configuration example:
{:cluster
{:enabled true
:node-id "auto"
:bind-address "0.0.0.0"
:bind-port 7946
:seeds ["192.168.1.10:7946" "192.168.1.11:7946"]
:gossip-interval-ms 200
:gossip-fanout 2
:push-pull-interval-ms 10000
:sync-health true
:sync-circuit-breaker true
:sync-drain true
:sync-conntrack true}}(alive-nodes)Get set of alive node IDs (including self).
Get set of alive node IDs (including self).
(all-nodes)Get map of all known nodes: node-id -> NodeInfo.
Get map of all known nodes: node-id -> NodeInfo.
(broadcast! state-type key value)Broadcast a state change to the cluster.
Args:
Returns the SyncableState record that was broadcast, or nil if cluster not running.
Broadcast a state change to the cluster. Args: - state-type: Keyword identifying state type (e.g., :health, :circuit-breaker) - key: Unique identifier within state type (e.g., target-id) - value: State value (must be serializable as EDN) Returns the SyncableState record that was broadcast, or nil if cluster not running.
(broadcast-many! states)Broadcast multiple state changes to the cluster.
Args:
Use this for batch updates to reduce network overhead.
Broadcast multiple state changes to the cluster. Args: - states: Vector of SyncableState records Use this for batch updates to reduce network overhead.
(cluster-size)Get number of alive nodes in the cluster.
Get number of alive nodes in the cluster.
(get-all-nodes)Get map of all known nodes: node-id -> NodeInfo.
Get map of all known nodes: node-id -> NodeInfo.
(get-config)Get current cluster configuration.
Get current cluster configuration.
(get-node-id)Get this node's unique identifier.
Get this node's unique identifier.
Protocol for state providers. Import from lb.cluster.protocol for implementation.
Protocol for state providers. Import from lb.cluster.protocol for implementation.
(local-node)Get this node's NodeInfo record.
Get this node's NodeInfo record.
Create a SyncableState record. (make-syncable-state state-type key value version source-node)
Create a SyncableState record. (make-syncable-state state-type key value version source-node)
Get next Lamport timestamp for versioning.
Get next Lamport timestamp for versioning.
(node-alive? node-id)Check if a specific node is considered alive.
Check if a specific node is considered alive.
(node-dead? node-id)Check if a specific node is confirmed dead.
Check if a specific node is confirmed dead.
(node-id)Get this node's unique identifier.
Get this node's unique identifier.
(node-suspected? node-id)Check if a specific node is suspected of failure.
Check if a specific node is suspected of failure.
(register-provider! provider)Register a state provider for synchronization.
A state provider must implement lb.cluster.protocol/IStateProvider:
Register a state provider for synchronization. A state provider must implement lb.cluster.protocol/IStateProvider: - provider-type: Return keyword identifying provider (e.g., :health) - get-sync-state: Return vector of SyncableState records - get-state-digest: Return map of [type key] -> version - apply-remote-state: Apply received remote states - on-node-failure: Handle node failure (for failover)
(running?)Check if cluster mode is running.
Check if cluster mode is running.
(start! config)Start cluster mode with the given configuration.
Config options: :enabled - Enable/disable cluster mode (default false) :node-id - Node identifier, "auto" generates UUID (default "auto") :bind-address - Address to bind gossip transport (default "0.0.0.0") :bind-port - Port for gossip communication (default 7946) :seeds - List of seed node addresses ["ip:port", ...]
Gossip tuning: :gossip-interval-ms - Gossip tick interval (default 200) :gossip-fanout - Peers to gossip to per tick (default 2) :push-pull-interval-ms - Full state sync interval (default 10000)
Failure detection: :ping-interval-ms - Probe interval (default 1000) :ping-timeout-ms - Probe timeout (default 500) :suspicion-mult - Suspicion multiplier (default 3)
State sync: :sync-health - Sync health status (default true) :sync-circuit-breaker - Sync circuit breaker state (default true) :sync-drain - Sync drain coordination (default true) :sync-conntrack - Sync connection tracking (default true)
Returns {:node-id <id> :address <addr>} on success, nil if disabled/already running.
Start cluster mode with the given configuration.
Config options:
:enabled - Enable/disable cluster mode (default false)
:node-id - Node identifier, "auto" generates UUID (default "auto")
:bind-address - Address to bind gossip transport (default "0.0.0.0")
:bind-port - Port for gossip communication (default 7946)
:seeds - List of seed node addresses ["ip:port", ...]
Gossip tuning:
:gossip-interval-ms - Gossip tick interval (default 200)
:gossip-fanout - Peers to gossip to per tick (default 2)
:push-pull-interval-ms - Full state sync interval (default 10000)
Failure detection:
:ping-interval-ms - Probe interval (default 1000)
:ping-timeout-ms - Probe timeout (default 500)
:suspicion-mult - Suspicion multiplier (default 3)
State sync:
:sync-health - Sync health status (default true)
:sync-circuit-breaker - Sync circuit breaker state (default true)
:sync-drain - Sync drain coordination (default true)
:sync-conntrack - Sync connection tracking (default true)
Returns {:node-id <id> :address <addr>} on success, nil if disabled/already running.(stats)Get cluster statistics.
Returns map with:
Get cluster statistics.
Returns map with:
- :status - :stopped, :starting, :running, :stopping
- :membership - {:node-id, :alive-count, :suspected-count, :dead-count}
- :gossip - {:running?, :provider-count, :config}
- :config - Current cluster configuration(stop!)Stop cluster mode, gracefully leaving the cluster.
Stop cluster mode, gracefully leaving the cluster.
(subscribe! callback)Subscribe to cluster events.
Callback receives ClusterEvent records with:
Returns an unsubscribe function.
Subscribe to cluster events.
Callback receives ClusterEvent records with:
- :event-type - One of: :node-join, :node-leave, :node-suspect, :node-alive,
:node-dead, :cluster-started, :cluster-stopped
- :node-id - Node related to event (if applicable)
- :timestamp - When event occurred
- :data - Event-specific data
Returns an unsubscribe function.(unregister-provider! type)Unregister a state provider by type.
Unregister a state provider by type.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |