elect

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewElection

func NewElection(lg *zap.Logger, etcdCli *clientv3.Client, cfg ElectionConfig, id, key string, member Member) *election

NewElection creates an Election.

Types

type Election

type Election interface {
	// Start starts compaining the owner.
	Start(context.Context)
	// ID returns the member ID.
	ID() string
	// GetOwnerID gets the owner ID.
	GetOwnerID(ctx context.Context) (string, error)
	// Close resigns and but doesn't retire.
	Close()
}

Election is used to campaign the owner and manage the owner information.

type ElectionConfig

type ElectionConfig struct {
	Timeout          time.Duration
	RetryIntvl       time.Duration
	QueryIntvl       time.Duration
	WaitBeforeRetire time.Duration
	RetryCnt         uint64
	SessionTTL       int
}

func DefaultElectionConfig

func DefaultElectionConfig(sessionTTL int) ElectionConfig

type Member

type Member interface {
	OnElected()
	OnRetired()
}

Jump to

Keyboard shortcuts

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