Documentation ¶
Index ¶
- type Elector
- type ElectorOption
- type LeaderLease
- type Leadership
- func (ls *Leadership) ChangeLeaderTo(newLeader string) error
- func (ls *Leadership) Check() bool
- func (ls *Leadership) CurrentLeader() (string, int64, error)
- func (ls *Leadership) DoIfLeader(conditions []clientv3.Cmp, ops ...clientv3.Op) (bool, error)
- func (ls *Leadership) ElectionLoop()
- func (ls *Leadership) GetLease() *LeaderLease
- func (ls *Leadership) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Elector ¶
type Elector interface { // CreateLeadship create a leadership CreateLeadship(purpose string, nodeName, nodeValue string, allowCampaign bool, becomeLeader, becomeFollower func(string) bool) *Leadership // Client etcd clientv3 Client() *clientv3.Client }
Elector a leader elector
func NewElector ¶
func NewElector(client *clientv3.Client, options ...ElectorOption) (Elector, error)
NewElector create a elector
type ElectorOption ¶
type ElectorOption func(*electorOptions)
ElectorOption elector option
func WithEmbedEtcd ¶
func WithEmbedEtcd(etcd *embed.Etcd) ElectorOption
WithEmbedEtcd with embed etcd
func WithLeaderLeaseSeconds ¶
func WithLeaderLeaseSeconds(value int64) ElectorOption
WithLeaderLeaseSeconds set leader lease in seconds
func WithLockIfBecomeLeader ¶
func WithLockIfBecomeLeader(value bool) ElectorOption
WithLockIfBecomeLeader set lock enable flag if become leader, If true, will add a distributed lock, and will unlock on become follower, ensure that the other nodes can be changed to leaders after the previous leader has processed the role changes.
func WithLogger ¶ added in v0.2.0
func WithLogger(logger *zap.Logger) ElectorOption
WithLogger sets logger
func WithPrefix ¶
func WithPrefix(value string) ElectorOption
WithPrefix set data prefix in embed etcd server
type LeaderLease ¶
type LeaderLease struct {
// contains filtered or unexported fields
}
LeaderLease is used for renewing leadership.
func (*LeaderLease) Close ¶
func (l *LeaderLease) Close(pctx context.Context) error
Close releases the lease.
func (*LeaderLease) IsExpired ¶
func (l *LeaderLease) IsExpired() bool
IsExpired checks if the lease is expired. If it returns true, current node should step down and try to re-elect again.
type Leadership ¶
type Leadership struct {
// contains filtered or unexported fields
}
Leadership is used to manage the leadership campaigning.
func (*Leadership) ChangeLeaderTo ¶
func (ls *Leadership) ChangeLeaderTo(newLeader string) error
ChangeLeaderTo change leader to new leader
func (*Leadership) Check ¶
func (ls *Leadership) Check() bool
Check returns whether the leadership is still available
func (*Leadership) CurrentLeader ¶
func (ls *Leadership) CurrentLeader() (string, int64, error)
CurrentLeader returns the current leader
func (*Leadership) DoIfLeader ¶
DoIfLeader do if i'm leader
func (*Leadership) ElectionLoop ¶
func (ls *Leadership) ElectionLoop()
ElectionLoop start lead election
func (*Leadership) GetLease ¶
func (ls *Leadership) GetLease() *LeaderLease
GetLease gets the lease of leadership, only if leadership is valid, i.e the owner is a true leader, the lease is not nil.