Documentation ¶
Index ¶
Constants ¶
const NoLease = etcd.LeaseID(-1)
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
NewClient creates a new etcd.Client with the specified config where blanks are filled from environment variables by NewConfig.
If the provided config is nil and no environment variables are set, it will return a client connecting without TLS via localhost:2379.
func NewConfig ¶
NewConfig creates a new etcd.Config using environment variables. If an existing config is passed, it will fill in missing configuration using environment variables or defaults if they exists on the local system.
If no environment variables are set, it will return a config set to connect without TLS via localhost:2379.
Types ¶
type AlwaysLeaderMock ¶
type AlwaysLeaderMock struct{}
func (*AlwaysLeaderMock) Close ¶
func (s *AlwaysLeaderMock) Close()
func (*AlwaysLeaderMock) Concede ¶
func (s *AlwaysLeaderMock) Concede() (bool, error)
func (*AlwaysLeaderMock) IsLeader ¶
func (s *AlwaysLeaderMock) IsLeader() bool
type Election ¶
type Election struct {
// contains filtered or unexported fields
}
func NewElection ¶
NewElection creates a new leader election and submits our candidate for leader.
client, _ := etcdutil.NewClient(nil) // Start a leader election and attempt to become leader, only returns after // determining the current leader. election := etcdutil.NewElection(client, etcdutil.ElectionConfig{ Election: "presidental", Candidate: "donald", EventObserver: func(e etcdutil.Event) { fmt.Printf("Leader Data: %t\n", e.LeaderData) if e.IsLeader { // Do thing as leader } }, TTL: 5, }) // Returns true if we are leader (thread safe) if election.IsLeader() { // Do periodic thing } // Concede the election if leader and cancel our candidacy // for the election. election.Close()
func (*Election) Close ¶
func (e *Election) Close()
Close cancels the election and concedes the election if we are leader
type ElectionConfig ¶
type ElectionConfig struct { // Optional function when provided is called every time leadership changes or an error occurs EventObserver EventObserver // The name of the election (IE: scout, blackbird, etc...) Election string // The name of this instance (IE: worker-n01, worker-n02, etc...) Candidate string // Seconds to wait before giving up the election if leader disconnected TTL int64 }
type Event ¶
type Event struct { // True if our candidate is leader IsLeader bool // True if the election is shutdown and // no further events will follow. IsDone bool // Holds the current leader key LeaderKey string // Hold the current leaders data LeaderData string // If not nil, contains an error encountered // while participating in the election. Err error }
type EventObserver ¶
type EventObserver func(Event)
type LeaderElector ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func NewSession(c *etcd.Client, conf SessionConfig) (*Session, error)
NewSession creates a lease and monitors lease keep alive's for connectivity. Once a lease ID is granted SessionConfig.Observer is called with the granted lease. If connectivity is lost with etcd SessionConfig.Observer is called again with -1 (NoLease) as the lease ID. The Session will continue to try to gain another lease, once a new lease is gained SessionConfig.Observer is called again with the new lease id.
type SessionConfig ¶
type SessionConfig struct { TTL int64 Observer SessionObserver }