class Clustering

Defined in:

clustering.cr

Constant Summary

Log = ::Log.for(self)

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(uri : String | URI, name : String = ULID.generate, discovery : HoundDog::Discovery | Nil = nil, etcd_host : String = ENV["ETCD_HOST"]? || "localhost", etcd_port : Int32 = ENV["ETCD_PORT"]?.try(&.to_i?) || 2379) #

[View source]

Class Method Detail

def self.election_key #

[View source]
def self.meta_namespace #

[View source]
def self.readiness_key #

[View source]
def self.service_namespace #

[View source]

Instance Method Detail

def cluster_change #

Leader publishes a new version upon nodes joining/leaving the cluster


[View source]
def cluster_consistent? #

When there's an event under the readiness namespace, node creates a hash from node to version. If all the nodes are at the same version, the cluster is consistent.


[View source]
def cluster_version : String #

The version the current node is stable against


[View source]
def consume_stabilization_events #

Consume stabilization events until fiber channel empty

Ensures that the node will have only the latest version


[View source]
def discovery : HoundDog::Discovery #

Provides cluster node discovery


[View source]
def etcd_client #

Generate a new Etcd client


[View source]
def handle_readiness_event #

The leader calls the on_stable callback if...

  • cluster's version state is consistent
  • consistent state has not already been confirmed to be consistent

[View source]
def handle_version_change(value) #

Leader has published a new version to etcd


[View source]
def leader? : Bool #

Whether node is the cluster leader


[View source]
def leader_node #

Attains the current leader node


[View source]
def name(*args, **options) #

[View source]
def name(*args, **options, &) #

[View source]
def node_versions : Hash(String, String) #

[View source]
def nodes(*args, **options) #

[View source]
def nodes(*args, **options, &) #

[View source]
def retry_on_missing_lease(&) #

Retry a query if a lease is missing for at most the maximum requested lease TTL


[View source]
def service(*args, **options) #

[View source]
def service(*args, **options, &) #

[View source]
def stabilize : Array(HoundDog::Service::Node) -> Bool | Nil #

Performed to align nodes in the cluster


[View source]
def start #

Starts the node's clustering processes.

  • discovery (via hound-dog)
  • election_watcher (election event consumer)
  • readiness_watcher (cluster node version event consumer)
  • version_watcher (version change event consumer)
  • consume_stabilization_events (created by version_watcher)

[View source]
def start(on_stable : String -> Nil | Nil = nil, &stabilize : Array(HoundDog::Service::Node) -> Bool) #

Like above. Accepts a block that will be called with cluster nodes during stabilization events

If stabilize callback is true, the node is marked as ready.


[View source]
def stop #

Unregisters node from the cluster and ceases event handling


[View source]
def uri(*args, **options) #

[View source]
def uri(*args, **options, &) #

[View source]