cluster

package
v0.25.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cluster enables an agent-wide cluster mechanism which subsystems can use to determine ownership of some key.

Index

Constants

This section is empty.

Variables

View Source
var DefaultGossipConfig = GossipConfig{
	AdvertiseInterfaces: advertise.DefaultInterfaces,
}

DefaultGossipConfig holds default GossipConfig options.

Functions

This section is empty.

Types

type GossipConfig

type GossipConfig struct {
	// Name of the node within the cluster. Must be unique cluster-wide.
	NodeName string

	// host:port address to advertise to peers to connect to. When unset, the
	// first discovered IP from AdvertiseInterfaces will be used to find.
	AdvertiseAddr string

	// Slice of interface names to infer an advertise IP from. Must be set if
	// AdvertiseAddr is unset.
	AdvertiseInterfaces flagext.StringSlice

	// List of one or more host:port peer addresses to connect to. Mutually
	// exclusive with DiscoverPeers.
	//
	// If an agent connects to no peers, it will form a one-node cluster until a
	// peer connects to it explicitly.
	JoinPeers flagext.StringSlice

	// Discover peers to connect to using go-discover. Mutually exclusive with
	// JoinPeers.
	DiscoverPeers string

	// Client pool to use for connecting to peers.
	Pool *clientpool.Pool
}

GossipConfig controls clustering of Agents through gRPC-based gossip. GossipConfig cannot be changed at runtime.

func (*GossipConfig) ApplyDefaults

func (c *GossipConfig) ApplyDefaults(defaultPort int) error

ApplyDefaults mutates c with default settings applied. defaultPort is added as the default port for addresses that do not have port numbers assigned.

An error will be returned if the configuration is invalid or if an error occurred while applying defaults.

type GossipNode

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

GossipNode is a Node which uses gRPC and gossip to discover peers.

func NewGossipNode

func NewGossipNode(l log.Logger, srv *grpc.Server, c *GossipConfig) (*GossipNode, error)

NewGossipNode creates an unstarted GossipNode. The GossipNode will register itself as a gRPC service to srv. GossipConfig is expected to be valid and have already had ApplyDefaults called on it.

GossipNode operations are unavailable until the node is started.

func (*GossipNode) ChangeState

func (n *GossipNode) ChangeState(ctx context.Context, to peer.State) error

ChangeState changes the state of n. ChangeState will block until the state change has been receieved by another node; cancel the context to stop waiting. ChangeState will fail if the current state cannot move to the target state.

Nodes must be a StateParticipant to receive writes.

func (*GossipNode) CurrentState

func (n *GossipNode) CurrentState() peer.State

CurrentState returns the current state of the node. Note that other nodes may have an older view of the state while a state change propagates throughout the cluster.

func (*GossipNode) Lookup

func (n *GossipNode) Lookup(key shard.Key, numOwners int, op shard.Op) ([]peer.Peer, error)

Lookup implements Node and returns numOwners Peers that are responsible for key. Only peers in StateParticipant are considered during a lookup; if no peers are in StateParticipant, the Lookup will fail.

func (*GossipNode) Observe

func (n *GossipNode) Observe(o ckit.Observer)

Observe registers o to be informed when the cluster changes, including peers appearing, disapearing, or changing state.

Calls will have to filter events if they are only interested in a subset of changes.

func (*GossipNode) Peers

func (n *GossipNode) Peers() []peer.Peer

Peers returns the current set of Peers.

func (*GossipNode) Start

func (n *GossipNode) Start() (err error)

Start starts the node. Start will connect to peers if configured to do so.

Start must only be called after the gRPC server is running, otherwise Start will block forever.

func (*GossipNode) Stop

func (n *GossipNode) Stop() error

Stop leaves the cluster and terminates n. n cannot be re-used after stopping.

It is advisble to ChangeState to StateTerminating and StateGone before stopping so the local node has an opportunity to move work to other nodes.

type Node

type Node interface {
	// Lookup determines the set of replicationFactor owners for a given key.
	// peer.Peer.Self can be used to determine if the local node is the owner,
	// allowing for short-circuiting logic to connect directly to the local node
	// instead of using the network.
	//
	// Callers can use github.com/rfratto/ckit/shard.StringKey or
	// shard.NewKeyBuilder to create a key.
	Lookup(key shard.Key, replicationFactor int, op shard.Op) ([]peer.Peer, error)

	// Observe registers an Observer to receive notifications when the set of
	// Peers for a Node changes.
	Observe(ckit.Observer)

	// Peers returns the current set of peers for a Node.
	Peers() []peer.Peer
}

Node is a read-only view of a cluster node.

func NewLocalNode

func NewLocalNode(selfAddr string) Node

NewLocalNode returns a Node which forms a single-node cluster and never connects to other nodes.

selfAddr is the address for a Node to use to connect to itself over gRPC.

Jump to

Keyboard shortcuts

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