membership

package
v0.0.0-...-b0c7fd6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ToProtoStatusMap = map[Status]proto.Status{
	StatusHealthy:   proto.Status_HEALTHY,
	StatusUnhealthy: proto.Status_UNHEALTHY,
	StatusLeft:      proto.Status_LEFT,
}

Functions

func ToProtoNode

func ToProtoNode(node *Node) *proto.Node

func ToProtoNodeList

func ToProtoNodeList(nodes []Node) []*proto.Node

Types

type Cluster

type Cluster interface {
	Node(id NodeID) (Node, bool)
	Nodes() []Node
	SelfID() NodeID
	Self() Node

	ConnContext(ctx context.Context, id NodeID) (*nodeapi.Client, error)
	Conn(id NodeID) (*nodeapi.Client, error)
	LocalConn() *nodeapi.Client

	ApplyState(nodes []Node, sourceID NodeID) []Node
	StateHash() uint64
}

type Config

type Config struct {
	NodeID        NodeID
	NodeName      string
	PublicAddr    string
	LocalAddr     string
	Dialer        nodeapi.Dialer
	Logger        kitlog.Logger
	DialTimeout   time.Duration
	ProbeTimeout  time.Duration
	ProbeInterval time.Duration
	ProbeJitter   float64
	GCInterval    time.Duration
	IndirectNodes int
}

func DefaultConfig

func DefaultConfig() Config

type Node

type Node struct {
	ID          NodeID
	RunID       int64
	Name        string
	PublicAddr  string
	LocalAddr   string
	Error       string
	Status      Status
	LocalStatus Status
	Gen         uint32
}

Node represents a single cluster member.

func FromProtoNode

func FromProtoNode(node *proto.Node) Node

func FromProtoNodeList

func FromProtoNodeList(nodes []*proto.Node) []Node

func (*Node) Hash64

func (n *Node) Hash64() uint64

Hash64 returns a 64-bit hash of the node.

func (*Node) IsReachable

func (n *Node) IsReachable() bool

IsReachable returns true if the node is reachable.

type NodeID

type NodeID uint32

type SWIMCluster

type SWIMCluster struct {
	// contains filtered or unexported fields
}

func NewCluster

func NewCluster(conf Config) *SWIMCluster

func (*SWIMCluster) AddConn

func (cl *SWIMCluster) AddConn(id NodeID, conn *nodeapi.Client)

AddConn adds a connection to the cluster. If a connection to the same member already exists, the old connection is closed. This method is intended to be used during tests or during the cluster bootstrap.

func (*SWIMCluster) ApplyState

func (cl *SWIMCluster) ApplyState(nodes []Node, sourceID NodeID) []Node

ApplyState merges the given nodes with the current cluster state and returns the list of all nodes in the cluster after the merge.

func (*SWIMCluster) Conn

func (cl *SWIMCluster) Conn(id NodeID) (*nodeapi.Client, error)

Conn returns a connection to the member with the given ID. If the connection is not present, it attempts to dial the member and create a new connection.

func (*SWIMCluster) ConnContext

func (cl *SWIMCluster) ConnContext(ctx context.Context, id NodeID) (*nodeapi.Client, error)

ConnContext returns a connection to the member with the given ID. If the connection is not present, it attempts to dial the member and create a new connection. The context is used to cancel the dialing process.

func (*SWIMCluster) Join

func (cl *SWIMCluster) Join(ctx context.Context, addr string) error

Join adds the current node to the cluster with the given address. All nodes from the remote cluster are added to the local cluster and vice versa.

func (*SWIMCluster) Leave

func (cl *SWIMCluster) Leave(ctx context.Context) error

Leave removes the current node from the cluster. The leave call blocks until at least one other node acknowledges the leave request.

func (*SWIMCluster) LocalConn

func (cl *SWIMCluster) LocalConn() *nodeapi.Client

LocalConn returns a connection to the local member. It assumes that the local connection is always stable, so it panics if it is not present.

func (*SWIMCluster) Node

func (cl *SWIMCluster) Node(id NodeID) (Node, bool)

Node returns the node with the given ID, if it exists.

func (*SWIMCluster) Nodes

func (cl *SWIMCluster) Nodes() []Node

Nodes returns a list of all nodes in the cluster, including the current node, and nodes that have recently left the cluster but have not been garbage collected yet.

func (*SWIMCluster) Self

func (cl *SWIMCluster) Self() Node

Self returns the current node.

func (*SWIMCluster) SelfID

func (cl *SWIMCluster) SelfID() NodeID

SelfID returns the ID of the current node.

func (*SWIMCluster) Start

func (cl *SWIMCluster) Start()

Start schedules background tasks for managing the cluster state, such as probing nodes and garbage collecting nodes that have left the cluster.

func (*SWIMCluster) StateHash

func (cl *SWIMCluster) StateHash() uint64

type Status

type Status uint8
const (
	// StatusHealthy is the status of a healthy node.
	StatusHealthy Status = iota + 1
	// StatusUnhealthy is the status of a node that has failed a health check.
	StatusUnhealthy
	// StatusLeft is the status of a node that has left the cluster.
	StatusLeft
)

func (Status) String

func (s Status) String() string

String returns the string representation of the status.

func (Status) WorseThan

func (s Status) WorseThan(other Status) bool

WorseThan returns true if the status is worse than the other status.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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