Documentation ¶
Index ¶
- Constants
- type CampaignerInfo
- type Election
- func (e *Election) CancelEvictLeader()
- func (e *Election) ClearSessionIfNeeded(ctx context.Context, id string) (bool, error)
- func (e *Election) Close()
- func (e *Election) ErrorNotify() <-chan error
- func (e *Election) EvictLeader()
- func (e *Election) ID() string
- func (e *Election) IsLeader() bool
- func (e *Election) LeaderInfo(ctx context.Context) (string, string, string, error)
- func (e *Election) LeaderNotify() <-chan *CampaignerInfo
- func (e *Election) Resign()
Constants ¶
const ( // IsLeader means current compaigner become leader. IsLeader = "isLeader" // RetireFromLeader means current compaigner is old leader, and retired. RetireFromLeader = "retireFromLeader" // IsNotLeader means current compaigner is not old leader and current leader. IsNotLeader = "isNotLeader" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CampaignerInfo ¶
type CampaignerInfo struct { ID string `json:"id"` // addr is the campaigner's advertise address Addr string `json:"addr"` }
CampaignerInfo is the campaigner's information.
func (*CampaignerInfo) String ¶
func (c *CampaignerInfo) String() string
type Election ¶
type Election struct {
// contains filtered or unexported fields
}
Election implements the leader election based on etcd.
func NewElection ¶
func NewElection(ctx context.Context, cli *clientv3.Client, sessionTTL int, key, id, addr string, notifyBlockTime time.Duration) (*Election, error)
NewElection creates a new etcd leader Election instance and starts the campaign loop.
func (*Election) CancelEvictLeader ¶
func (e *Election) CancelEvictLeader()
CancelEvictLeader set evictLeader to false, and this member can campaign leader again.
func (*Election) ClearSessionIfNeeded ¶
ClearSessionIfNeeded will clear session when deleted master quited abnormally returns (triggered deleting session, error).
func (*Election) Close ¶
func (e *Election) Close()
Close closes the election instance and release the resources.
func (*Election) ErrorNotify ¶
ErrorNotify returns a channel that can fetch errors occurred for campaign.
func (*Election) EvictLeader ¶
func (e *Election) EvictLeader()
EvictLeader set evictLeader to true, and this member can't be leader.
func (*Election) LeaderInfo ¶
LeaderInfo returns the current leader's key, ID and address. it's similar with https://github.com/etcd-io/etcd/blob/v3.4.3/clientv3/concurrency/election.go#L147.
func (*Election) LeaderNotify ¶
func (e *Election) LeaderNotify() <-chan *CampaignerInfo
LeaderNotify returns a channel that can fetch the leader's information when the member become the leader or retire from the leader, or get a new leader. leader's information can be nil which means this member is leader and retire.