Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Candidate ¶
Candidate is an interface representing both a candidate campaigning to become a leader, and the observer that watches state changes in leadership to be notified about changes
func NewCandidate ¶
func NewCandidate( cfg ElectionConfig, parent tally.Scope, role string, nomination Nomination) (Candidate, error)
NewCandidate creates new election object to control participation in leader election.
type Discovery ¶
type Discovery interface {
// Returns the app URL for a given Peloton role such as
// peloton-jobmgr, peloton-resmgr or peloton-hostmgr etc.
GetAppURL(role string) (*url.URL, error)
}
Discovery is the service discovery interface for Peloton clients
type ElectionConfig ¶
type ElectionConfig struct {
// A comma separated list of ZK servers to use for leader election.
ZKServers []string `yaml:"zk_servers"`
// The root path in ZK to use for role leader election.
// This will be something like /peloton/YOURCLUSTERHERE.
Root string `yaml:"root"`
}
ElectionConfig is config related to leader election of this service.
type ID ¶
type ID struct {
Hostname string `json:"hostname"`
IP string `json:"ip"`
HTTPPort int `json:"http"`
GRPCPort int `json:"grpc"`
Version string `json:"version"`
}
ID defines the json struct to be encoded in leader node TODO(rcharles) add Instance representing the instance number
type Nomination ¶
type Nomination interface {
// GainedLeadershipCallback is the callback when the current node
// becomes the leader
GainedLeadershipCallback() error
// HasGainedLeadership returns true iff once GainedLeadershipCallback
// completes
HasGainedLeadership() bool
// ShutDownCallback is the callback to shut down gracefully if
// possible
ShutDownCallback() error
// LostLeadershipCallback is the callback when the leader lost
// leadership
LostLeadershipCallback() error
// GetID returns the host:master_port of the node running for
// leadership (i.e. the ID)
GetID() string
}
Nomination represents the set of callbacks to handle leadership election
type Observer ¶
Observer is an interface that describes something that can observe an election for a given role, and can Start() observing, query the CurrentLeader(), and Stop() observing.
func NewObserver ¶
func NewObserver(cfg ElectionConfig, scope tally.Scope, role string, newLeaderCallback func(string) error) (Observer, error)
NewObserver creates a new Observer that will watch and react to new leadership events for leaders in a given `role`, and will call newLeaderCallback whenever leadership changes