election

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLeader

func GetLeader(c *clientv3.Client, leaderPath string) (*pdpb.Member, int64, error)

GetLeader gets the corresponding leader from etcd by given leaderPath (as the key).

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

func (ls *Leadership) Campaign(leaseTimeout int64, leaderData string, cmps ...clientv3.Cmp) error

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.

func (*Leadership) Watch

func (ls *Leadership) Watch(serverCtx context.Context, revision int64)

Watch is used to watch the changes of the leadership, usually is used to detect the leadership stepping down and restart an election as soon as possible.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL