election

package
v0.0.0-...-51fbea3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefStartupGracePeriod       = time.Second * 15
	DefMembershipSampleInterval = time.Second
	DefLeaderAliveThreshold     = time.Second * 10
	DefLeaderElectionDuration   = time.Second * 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ElectionConfig

type ElectionConfig struct {
	StartupGracePeriod       time.Duration
	MembershipSampleInterval time.Duration
	// LeaderAliveThreshold 定义了 leadership 消息的过期超时时间。
	LeaderAliveThreshold   time.Duration
	LeaderElectionDuration time.Duration
}

type LeaderElectionAdapter

type LeaderElectionAdapter interface {
	// Gossip gossips a message to other peers
	Gossip(*pgossip.GossipMessage)

	// Accept returns a channel that emits messages
	Accept() <-chan *pgossip.GossipMessage

	// CreateProposalMessage
	CreateMessage(isDeclaration bool) *pgossip.GossipMessage

	// Peers returns a list of peers considered alive
	Peers() []utils.NetworkMember

	// ReportMetrics sends a report to the metrics server about a leadership status
	ReportMetrics(isLeader bool)
}

LeaderElectionAdapter 在 leader 选举模块中被用来接收/发送消息。

func NewAdapter

func NewAdapter(gossip gossip, pkiid utils.PKIidType, channel utils.ChannelID,
	metrics *metrics.ElectionMetrics, logger mlog.Logger) LeaderElectionAdapter

NewAdapter creates new leader election adapter

type LeaderElectionService

type LeaderElectionService interface {
	// IsLeader returns whether this peer is a leader or not
	IsLeader() bool

	// Stop stops the LeaderElectionService
	Stop()

	// Yield relinquishes the leadership until a new leader is elected,
	// or a timeout expires
	Yield()
}

LeaderElectionService is the object that runs the leader election algorithm

func NewLeaderElectionService

func NewLeaderElectionService(adapter LeaderElectionAdapter, id utils.PKIidType, callback leadershipCallback, config ElectionConfig, logger mlog.Logger) LeaderElectionService

NewLeaderElectionService returns a new LeaderElectionService

Jump to

Keyboard shortcuts

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