leader

package
v0.0.0-...-f584327 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ElectionInfo

type ElectionInfo struct {
	// LeaderAddress is the ip address of leader
	LeaderAddress string

	// IsLeader returns true if current node is leader
	IsLeader bool
}

ElectionInfo is the response for http election service

type LeaderElection

type LeaderElection interface {
	// Campaign run leader election loop
	Campaign()

	// GetLeaderInfo get leader info, return peer address
	GetLeaderInfo() string

	// IsLeader return true when this instance is leader
	IsLeader() bool

	// GetElectionInfo get info of election
	GetElectionInfo() (ElectionInfo, error)
}

LeaderElection is responsible for run leader election and handle state when leader status changed

func NewLeaderElection

func NewLeaderElection(backend b.Backend, metricCli metrics.Metrics, onStartedLeading func(context.Context), onStoppedLeading func()) LeaderElection

NewLeaderElection returns a LeaderElection based on resourcelock of backend.Backend

type Stub

type Stub struct {
	ElectionInfo
}

Stub is an implement of LeaderElection for test

func (*Stub) Campaign

func (s *Stub) Campaign()

Campaign implements LeaderElection interface

func (*Stub) GetElectionInfo

func (s *Stub) GetElectionInfo() (ElectionInfo, error)

GetElectionInfo implements LeaderElection interface

func (*Stub) GetLeaderInfo

func (s *Stub) GetLeaderInfo() string

GetLeaderInfo implements LeaderElection interface

func (*Stub) IsLeader

func (s *Stub) IsLeader() bool

IsLeader implements LeaderElection interface

Jump to

Keyboard shortcuts

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