elect

package
v0.0.0-...-2bcf145 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	// contains filtered or unexported fields
}

func NewCandidate

func NewCandidate(client *clientv3.Client, position string, name string, ttl int) *Candidate

func (*Candidate) Campaign

func (c *Candidate) Campaign(ctx context.Context) error

Campaign 开始进行竞选, ctx只是控制竞选等待时间,如果当选,成为leader的状态将一直保持,与ctx没有关系了.

func (*Candidate) Close

func (c *Candidate) Close() error

Close 关闭会话后,将退出当前选举或当选,此实例也将不可再用,再调用Campaign将报错.

func (*Candidate) GetCurLeaderInfo

func (c *Candidate) GetCurLeaderInfo(ctx context.Context) (string, string, int64, error)

GetCurLeaderInfo 获取集群中当前作为leader的信息,如果当前集群中没有人当选leader, 则返回concurrency.ErrElectionNoLeader错误.

func (*Candidate) Init

func (c *Candidate) Init() error

func (*Candidate) IsCurLeaderAtMe

func (c *Candidate) IsCurLeaderAtMe(ctx context.Context) (bool, error)

func (*Candidate) MyName

func (c *Candidate) MyName() string

func (*Candidate) MyTerm

func (c *Candidate) MyTerm() string

func (*Candidate) Proclaim

func (c *Candidate) Proclaim(ctx context.Context, newName string) error

Proclaim 如果自己是leader,则可以在此期间,给自己修改名称,宣告给其成员; 如果自己不是当前的leader,则报错,返回concurrency.ErrElectionNotLeader.

func (*Candidate) Resign

func (c *Candidate) Resign(ctx context.Context) error

Resign 如果自己是leader,则可以在此期间,自己主动放弃作为leader; 如果自己不是当前的leader,则无任何影响,也不会返回err。 后续如果调用Campaign()还可以再次进行竞选.

type Observer

type Observer struct {
	CurTerm string
	// contains filtered or unexported fields
}

func NewObserver

func NewObserver(c *clientv3.Client, p string, ttl int) *Observer

func (*Observer) Init

func (o *Observer) Init() error

func (*Observer) Start

func (o *Observer) Start(ctx context.Context)

func (*Observer) Stop

func (o *Observer) Stop()

Jump to

Keyboard shortcuts

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