Documentation ¶
Index ¶
- Constants
- Variables
- type Candidate
- func (c *Candidate) Elected() bool
- func (c *Candidate) ForeignLeaderIP(dc string) (net.IP, error)
- func (c *Candidate) ForeignLeaderService(dc string) (*api.SessionEntry, error)
- func (c *Candidate) ID() string
- func (c *Candidate) LeaderIP() (net.IP, error)
- func (c *Candidate) LeaderService() (*api.SessionEntry, error)
- func (c *Candidate) RemoveWatchers()
- func (c *Candidate) Resign()
- func (c *Candidate) Run() error
- func (c *Candidate) Running() bool
- func (c *Candidate) SessionID() string
- func (c *Candidate) SessionTTL() time.Duration
- func (c *Candidate) State() State
- func (c *Candidate) Unwatch(id string)
- func (c *Candidate) UpdateWatchers()
- func (c *Candidate) Wait() error
- func (c *Candidate) WaitFor(td time.Duration) error
- func (c *Candidate) WaitUntil(t time.Time) error
- func (c *Candidate) Watch(id string, fn WatchFunc) string
- type Config
- type ElectionUpdate
- type LeaderKVValue
- type SessionNameParts
- type State
- type WatchFunc
Constants ¶
const ( IDRegex = `^[a-zA-Z0-9:.-]+$` // only allow certain characters in an ID SessionKeyPrefix = "candidate-" )
Variables ¶
var (
InvalidCandidateID = fmt.Errorf("candidate ID must obey \"%s\"", IDRegex)
)
Functions ¶
This section is empty.
Types ¶
type Candidate ¶
type Candidate struct {
// contains filtered or unexported fields
}
func (*Candidate) Elected ¶
Elected will return true if this candidate's session is "locking" the kv
func (*Candidate) ForeignLeaderIP ¶
ForeignLeaderIP will attempt to parse the body of the locked kv key to locate the current leader
func (*Candidate) ForeignLeaderService ¶
func (c *Candidate) ForeignLeaderService(dc string) (*api.SessionEntry, error)
ForeignLeaderService will attempt to locate the leader's session entry in a datacenter of your choosing
func (*Candidate) LeaderService ¶
func (c *Candidate) LeaderService() (*api.SessionEntry, error)
LeaderService will attempt to locate the leader's session entry in your local agent's datacenter
func (*Candidate) RemoveWatchers ¶
func (c *Candidate) RemoveWatchers()
RemoveWatchers will clear all watchers
func (*Candidate) Resign ¶
func (c *Candidate) Resign()
Resign will remove this candidate from the election pool
func (*Candidate) SessionTTL ¶
SessionTTL returns the parsed TTL
func (*Candidate) UpdateWatchers ¶
func (c *Candidate) UpdateWatchers()
UpdateWatchers will immediately push the current state of this Candidate to all currently registered Watchers
func (*Candidate) WaitFor ¶
WaitFor will wait for a candidate to be elected or until duration has passed
type Config ¶
type Config struct { // KVKey [required] // // Must be the key to attempt to acquire a session lock on. This key must be considered ephemeral, and not contain // anything you don't want overwritten / destroyed. KVKey string // ID [suggested] // // Should be a unique identifier that makes sense within the scope of your implementation. // If left blank it will attempt to use the local IP address, otherwise a random string will be generated. ID string // SessionTTL [optional] // // The duration of time a given candidate can be elected without re-trying. A "good" value for this depends // entirely upon your implementation. Keep in mind that once the KVKey lock is acquired with the session, it will // remain locked until either the specified session TTL is up or Resign() is explicitly called. // // If not defined, will default to value of session.DefaultTTL SessionTTL string // Client [optional] // // Consul API client. If not specified, one will be created using api.DefaultConfig() Client *api.Client // AutoRun [optional] // // If set to true, the Candidate will immediately enter its election pool after successful construction AutoRun bool }
type ElectionUpdate ¶
type ElectionUpdate struct { // Elected tracks whether this specific candidate has been elected Elected bool // State tracks the current state of this candidate State State }
ElectionUpdate is sent to watchers on election state change
type LeaderKVValue ¶
type LeaderKVValue struct {
LeaderAddress string
}
LeaderKVValue is the body of the acquired KV
type SessionNameParts ¶
func ParseSessionName ¶
func ParseSessionName(name string) (*SessionNameParts, error)
type WatchFunc ¶
type WatchFunc func(update ElectionUpdate)