discovery

package
v0.3.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package discovery provides a basic memberlist integration.

Index

Constants

This section is empty.

Variables

View Source
var ErrHostNotFound = errors.New("host not found")

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

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 (*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, error)

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

func (*Discovery) DecodeNodeMeta

func (d *Discovery) DecodeNodeMeta(buf []byte) (Member, error)

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
	ID        uint64
	Birthdate int64
}

Member represents a node in the cluster.

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