Liking cljdoc? Tell your friends :D

lb.cluster

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}}

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}}
raw docstring

alive-nodesclj

(alive-nodes)

Get set of alive node IDs (including self).

Get set of alive node IDs (including self).
sourceraw docstring

all-nodesclj

(all-nodes)

Get map of all known nodes: node-id -> NodeInfo.

Get map of all known nodes: node-id -> NodeInfo.
sourceraw docstring

broadcast!clj

(broadcast! state-type key value)

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 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.
sourceraw docstring

broadcast-many!clj

(broadcast-many! states)

Broadcast multiple state changes to the cluster.

Args:

  • states: Vector of SyncableState records

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.
sourceraw docstring

cluster-sizeclj

(cluster-size)

Get number of alive nodes in the cluster.

Get number of alive nodes in the cluster.
sourceraw docstring

get-all-nodesclj

(get-all-nodes)

Get map of all known nodes: node-id -> NodeInfo.

Get map of all known nodes: node-id -> NodeInfo.
sourceraw docstring

get-configclj

(get-config)

Get current cluster configuration.

Get current cluster configuration.
sourceraw docstring

get-node-idclj

(get-node-id)

Get this node's unique identifier.

Get this node's unique identifier.
sourceraw docstring

IStateProvidercljprotocol

Protocol for state providers. Import from lb.cluster.protocol for implementation.

Protocol for state providers. Import from lb.cluster.protocol for implementation.
sourceraw docstring

local-nodeclj

(local-node)

Get this node's NodeInfo record.

Get this node's NodeInfo record.
sourceraw docstring

make-syncable-stateclj

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)
sourceraw docstring

next-versionclj

Get next Lamport timestamp for versioning.

Get next Lamport timestamp for versioning.
sourceraw docstring

node-alive?clj

(node-alive? node-id)

Check if a specific node is considered alive.

Check if a specific node is considered alive.
sourceraw docstring

node-dead?clj

(node-dead? node-id)

Check if a specific node is confirmed dead.

Check if a specific node is confirmed dead.
sourceraw docstring

node-idclj

(node-id)

Get this node's unique identifier.

Get this node's unique identifier.
sourceraw docstring

node-suspected?clj

(node-suspected? node-id)

Check if a specific node is suspected of failure.

Check if a specific node is suspected of failure.
sourceraw docstring

register-provider!clj

(register-provider! provider)

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)
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)
sourceraw docstring

running?clj

(running?)

Check if cluster mode is running.

Check if cluster mode is running.
sourceraw docstring

start!clj

(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.
sourceraw docstring

statsclj

(stats)

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
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
sourceraw docstring

stop!clj

(stop!)

Stop cluster mode, gracefully leaving the cluster.

Stop cluster mode, gracefully leaving the cluster.
sourceraw docstring

subscribe!clj

(subscribe! callback)

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.

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.
sourceraw docstring

unregister-provider!clj

(unregister-provider! type)

Unregister a state provider by type.

Unregister a state provider by type.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close