Documentation ¶
Index ¶
- func GetLeader(c *clientv3.Client, leaderPath string) (*pdpb.Member, int64, error)
- type Leadership
- func (ls *Leadership) Campaign(leaseTimeout int64, leaderData string, cmps ...clientv3.Cmp) error
- func (ls *Leadership) Check() bool
- func (ls *Leadership) DeleteLeaderKey() error
- func (ls *Leadership) GetClient() *clientv3.Client
- func (ls *Leadership) GetLeaderKey() string
- func (ls *Leadership) Keep(ctx context.Context)
- func (ls *Leadership) LeaderTxn(cs ...clientv3.Cmp) clientv3.Txn
- func (ls *Leadership) Reset()
- func (ls *Leadership) Watch(serverCtx context.Context, revision int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Leadership ¶
type Leadership struct {
// contains filtered or unexported fields
}
Leadership is used to manage the leadership campaigning.
func NewLeadership ¶
func NewLeadership(client *clientv3.Client, leaderKey, purpose string) *Leadership
NewLeadership creates a new Leadership.
func (*Leadership) Campaign ¶
Campaign is used to campaign the leader with given lease and returns a leadership
func (*Leadership) Check ¶
func (ls *Leadership) Check() bool
Check returns whether the leadership is still available.
func (*Leadership) DeleteLeaderKey ¶
func (ls *Leadership) DeleteLeaderKey() error
DeleteLeaderKey deletes the corresponding leader from etcd by the leaderPath as the key.
func (*Leadership) GetClient ¶
func (ls *Leadership) GetClient() *clientv3.Client
GetClient is used to get the etcd client.
func (*Leadership) GetLeaderKey ¶
func (ls *Leadership) GetLeaderKey() string
GetLeaderKey is used to get the leader key of etcd.
func (*Leadership) Keep ¶
func (ls *Leadership) Keep(ctx context.Context)
Keep will keep the leadership available by update the lease's expired time continuously
func (*Leadership) LeaderTxn ¶
func (ls *Leadership) LeaderTxn(cs ...clientv3.Cmp) clientv3.Txn
LeaderTxn returns txn() with a leader comparison to guarantee that the transaction can be executed only if the server is leader.
func (*Leadership) Reset ¶
func (ls *Leadership) Reset()
Reset does some defer jobs such as closing lease, resetting lease etc.