elect

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 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 When starting the campaign, ctx only controls the waiting time for the campaign. If elected, the status of becoming the leader will always be maintained, and it has nothing to do with ctx.

func (*Candidate) Close

func (c *Candidate) Close() error

Close After closing the session, the current election or election will be withdrawn, and this instance will no longer be available. Calling Campaign again will report an error.

func (*Candidate) GetCurLeaderInfo

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

GetCurLeaderInfo Get the information about the current leader in the cluster. If no one is elected as the leader in the current cluster, then return concurrency.ErrElectionNoLeader error.

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 If you are the leader, you can change the name of yourself and announce it to its members during this period; If you are not the current leader, report an error and return concurrency.ErrElectionNotLeader.

func (*Candidate) Resign

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

Resign If you are the leader, you can voluntarily give up being the leader during this period; If you are not the current leader, it will have no effect and will not return err. If you call Campaign() later, you can campaign again.

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