disco

package
v8.23.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// GetLeader returns the current Leader stored in the KV store. If the Leader
	// is set, the returned ok flag will be true. If the Leader is not set, the
	// returned ok flag will be false.
	GetLeader() (id string, apiAddr string, addr string, ok bool, e error)

	// InitializeLeader sets the leader to the given details, but only if no leader
	// has already been set. This operation is a check-and-set type operation. If
	// initialization succeeds, ok is set to true, otherwise false.
	InitializeLeader(id, apiAddr, addr string) (bool, error)

	// SetLeader unconditionally sets the leader to the given details.
	SetLeader(id, apiAddr, addr string) error

	fmt.Stringer
}

Client is the interface discovery clients must implement.

type Service

type Service struct {
	RegisterInterval time.Duration
	ReportInterval   time.Duration
	// contains filtered or unexported fields
}

Service represents a Discovery Service instance.

func NewService

func NewService(c Client, s Store, suf Suffrage) *Service

NewService returns an instantiated Discovery Service.

func (*Service) Register

func (s *Service) Register(id, apiAddr, addr string) (bool, string, error)

Register registers this node with the discovery service. It will block until a) if the node is a voter, it registers itself, b) learns of another node it can use to join the cluster, or c) an unrecoverable error occurs.

func (*Service) StartReporting

func (s *Service) StartReporting(id, apiAddr, addr string) chan struct{}

StartReporting reports the details of this node to the discovery service, if, and only if, this node is the leader. The service will report anytime a leadership change is detected. It also does it periodically to deal with any intermittent issues that caused Leadership information to go stale.

func (*Service) Stats

func (s *Service) Stats() (map[string]interface{}, error)

Stats returns diagnostic information on the disco service.

type Store

type Store interface {
	// IsLeader returns whether this node is the Leader.
	IsLeader() bool

	// RegisterLeaderChange registers a channel that will be notified when
	// a leadership change occurs.
	RegisterLeaderChange(c chan<- struct{})
}

Store is the interface the consensus system must implement.

type Suffrage added in v8.14.0

type Suffrage int

Suffrage is the type of suffrage -- voting or non-voting -- a node has.

const (
	SuffrageUnknown Suffrage = iota
	Voter
	NonVoter
)

func VoterSuffrage added in v8.14.0

func VoterSuffrage(b bool) Suffrage

VoterSuffrage returns a Suffrage based on the given boolean.

func (Suffrage) IsVoter added in v8.14.0

func (s Suffrage) IsVoter() bool

IsVoter returns whether the Suffrage indicates a Voter.

Jump to

Keyboard shortcuts

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