discovery

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package discovery provides a basic memberlist integration.

Index

Constants

This section is empty.

Variables

View Source
var ErrMemberNotFound = errors.New("member not found")

ErrMemberNotFound indicates that the requested member could not be found in the member list.

View Source
var UptimeSeconds = stats.NewInt64Counter()

UptimeSeconds is number of seconds since the server started.

Functions

This section is empty.

Types

type ClusterEvent

type ClusterEvent struct {
	Event    memberlist.NodeEventType
	NodeName string
	NodeAddr net.IP
	NodePort uint16
	NodeMeta []byte // Metadata from the delegate for this node.
}

ClusterEvent is a single event related to node activity in the memberlist. The Node member of this struct must not be directly modified.

func ToClusterEvent added in v0.4.0

func ToClusterEvent(e memberlist.NodeEvent) *ClusterEvent

func (*ClusterEvent) MemberAddr

func (c *ClusterEvent) MemberAddr() string

type Discovery

type Discovery struct {
	ClusterEvents chan *ClusterEvent
	// contains filtered or unexported fields
}

Discovery is a structure that encapsulates memberlist and provides useful functions to utilize it.

func New

func New(log *flog.Logger, c *config.Config) *Discovery

New creates a new memberlist with a proper configuration and returns a new Discovery instance along with it.

func (*Discovery) FindMemberByID

func (d *Discovery) FindMemberByID(id uint64) (Member, error)

FindMemberByID finds and returns an alive member.

func (*Discovery) FindMemberByName

func (d *Discovery) FindMemberByName(name string) (Member, error)

FindMemberByName finds and returns an alive member.

func (*Discovery) GetCoordinator

func (d *Discovery) GetCoordinator() Member

GetCoordinator returns the oldest node in the memberlist.

func (*Discovery) GetMembers

func (d *Discovery) GetMembers() []Member

GetMembers returns a full list of known alive nodes.

func (*Discovery) IsCoordinator

func (d *Discovery) IsCoordinator() bool

IsCoordinator returns true if the caller is the coordinator node.

func (*Discovery) Join

func (d *Discovery) Join() (int, error)

Join is used to take an existing Memberlist and attempt to Join a cluster by contacting all the given hosts and performing a state sync. Initially, the Memberlist only contains our own state, so doing this will cause remote nodes to become aware of the existence of this node, effectively joining the cluster.

func (*Discovery) LocalNode

func (d *Discovery) LocalNode() *memberlist.Node

LocalNode is used to return the local Node

func (*Discovery) NumMembers

func (d *Discovery) NumMembers() int

func (*Discovery) Rejoin

func (d *Discovery) Rejoin(peers []string) (int, error)

func (*Discovery) Shutdown

func (d *Discovery) Shutdown() error

Shutdown will stop any background maintenance of network activity for this memberlist, causing it to appear "dead". A leave message will not be broadcasted prior, so the cluster being left will have to detect this node's Shutdown using probing. If you wish to more gracefully exit the cluster, call Leave prior to shutting down.

This method is safe to call multiple times.

func (*Discovery) Start

func (d *Discovery) Start() error

func (*Discovery) SubscribeNodeEvents

func (d *Discovery) SubscribeNodeEvents() chan *ClusterEvent

type Member

type Member struct {
	Name      string
	NameHash  uint64
	ID        uint64
	Birthdate int64
}

Member represents a node in the cluster.

func NewMember added in v0.4.0

func NewMember(c *config.Config) Member

func NewMemberFromMetadata added in v0.4.0

func NewMemberFromMetadata(metadata []byte) (Member, error)

func (Member) CompareByID added in v0.4.0

func (m Member) CompareByID(other Member) bool

CompareByID returns true if two members denote the same member in the cluster.

func (Member) CompareByName added in v0.4.0

func (m Member) CompareByName(other Member) bool

CompareByName returns true if the two members has the same name in the cluster. This function is intended to redirect the requests to the partition owner.

func (Member) Encode added in v0.4.0

func (m Member) Encode() ([]byte, error)

func (Member) String

func (m Member) String() string

Jump to

Keyboard shortcuts

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