Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewElection ¶
NewElection creates a new leader election for a member name.
Leader election is done using a KV Bucket where each key is an election, the key therefore should be a unique identifier for the election. Bucket is a loaded bucket using either NATS libraries of the helper in the choria package.
Buckets can be created using the NATS libraries or the "choria kv add ELECTION --ttl 30s --replicas 3" command, here we set a 30s TTL on the bucket which would be used to influence campaign frequency and the failover time after an outage of the leader. The smallest allowed TTL is 5 seconds though we suggest picking the biggest number in the range of 30 to 60 seconds that works for your use case.
A standard bucket CHORIA_LEADER_ELECTION gets made for Choria Streams and it's replicas and ttl is configurable in the config file.
Types ¶
type Backoff ¶
type Backoff interface { // Duration returns the time to sleep for the nth invocation Duration(n int) time.Duration }
Backoff controls the interval of campaigns
type Option ¶
type Option func(o *options)
Option configures the election system
func OnCampaign ¶
OnCampaign is called each time a campaign is done by the leader or a candidate
func WithBackoff ¶
WithBackoff will use the provided Backoff timer source to decrease campaign intervals over time