discovery

package
v0.0.0-...-d2438c5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const Interval = 10

Interval represents the number of seconds to wait between each schedule iteration

View Source
const (
	// PeerTypeStore serves the store API
	PeerTypeStore members.PeerType = "store"
)

Variables

This section is empty.

Functions

func Intersection

func Intersection(nodes []db.NodeInfo, services []db.ServiceNodeInfo) (map[string]NodeData, map[string]NodeData)

Intersection checks to see if there are any nodes and services that need to be added or removed.

func ParsePeerType

func ParsePeerType(t string) (members.PeerType, error)

ParsePeerType parses a potential peer type and errors out if it's not a known valid type.

Types

type Cluster

type Cluster interface {
	database.DBAccessor
	db.ClusterOpener
	db.ClusterTransactioner
	db.ClusterExclusiveLocker

	// NodeID sets the the node NodeID associated with this cluster instance. It's used for
	// backward-compatibility of all db-related APIs that were written before
	// clustering and don't accept a node NodeID, so in those cases we automatically
	// use this value as implicit node NodeID.
	NodeID(int64)

	// SchemaVersion returns the underlying schema version for the cluster
	SchemaVersion() int

	// Close the database facade.
	Close() error
}

Cluster mediates access to data stored in the cluster dqlite database.

type Daemon

type Daemon interface {
	// Gateway returns the underlying Daemon Gateway
	Gateway() Gateway

	// Cluster returns the underlying Cluster
	Cluster() Cluster

	// Node returns the underlying Node associated with the daemon
	Node() Node

	// NodeConfigSchema returns the daemon schema for the local Node
	NodeConfigSchema() config.Schema

	// Endpoints returns the underlying endpoints that the daemon controls.
	Endpoints() Endpoints
}

Daemon can respond to requests from a shared client.

type Discovery

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

Discovery represents a task collection of things that want to be run

func New

func New(daemon Daemon, options ...Option) *Discovery

New creates a series of tasks to be worked on

func (*Discovery) Run

func (s *Discovery) Run() (task.Func, task.Schedule)

Run returns a task function that performs operational GC checks against the internal cache of operations.

type Endpoints

type Endpoints interface {

	// NetworkPrivateKey returns the private key of the TLS certificate used by the
	// network endpoint.
	NetworkPrivateKey() []byte

	// NetworkPublicKey returns the public key of the TLS certificate used by the
	// network endpoint.
	NetworkPublicKey() []byte
}

Endpoints are in charge of bringing up and down the HTTP endpoints for serving the RESTful API.

type EventBus

type EventBus interface {

	// AddHandler attaches a event listener to all the members events
	// and broadcasts the event to the handler.
	AddHandler(members.Handler)

	// RemoveHandler removes the event listener.
	RemoveHandler(members.Handler)

	// DispatchEvent dispatches an event to all the members in the cluster.
	DispatchEvent(members.Event) error
}

EventBus allows the distributing and receiving of events over the cluster

type Gateway

type Gateway interface {

	// IsDatabaseNode returns true if this gateway also run acts a raft database
	// node.
	IsDatabaseNode() bool

	// LeaderAddress returns the address of the current raft leader.
	LeaderAddress() (string, error)
}

Gateway mediates access to the dqlite cluster using a gRPC SQL client, and possibly runs a dqlite replica on this node (if we're configured to do so).

type Member

type Member interface {

	// Name returns the name of the member
	Name() string

	// Address returns the host:port of the member
	Address() string
}

Member represents a node in the cluster.

type MemberList

type MemberList interface {

	// NumMembers returns the number of alive nodes currently known. Between
	// the time of calling this and calling Members, the number of alive nodes
	// may have changed, so this shouldn't be used to determine how many
	// members will be returned by Members.
	NumMembers() int

	// LocalNode is used to return the local Member
	LocalNode() Member

	// Members returns a point-in-time snapshot of the members of this cluster.
	Members() []Member
}

MemberList represents a way to manage members with in a cluster

type Members

type Members interface {
	EventBus

	// Join joins an existing members cluster. Returns the number of nodes
	// successfully contacted. The returned error will be non-nil only in the
	// case that no nodes could be contacted.
	Join() (int, error)

	// Leave gracefully exits the cluster. It is safe to call this multiple
	// times.
	Leave() error

	// Memberlist is used to get access to the underlying Memberlist instance
	MemberList() MemberList

	// Walk over a set of alive members
	Walk(func(members.PeerInfo) error) error

	// Shutdown the current members cluster
	Shutdown() error
}

Members represents a way of joining a members cluster

type Node

type Node interface {
	database.DBAccessor
	db.NodeOpener
	db.NodeTransactioner

	// Dir returns the directory of the underlying database file.
	Dir() string

	// Close the database facade.
	Close() error
}

Node mediates access to the data stored locally

type NodeData

type NodeData struct {
	NodeInfo      db.NodeInfo
	DaemonAddress string
	DaemonNonce   string
}

NodeData is a tuple containing the NodeInfo and Daemon information.

type Option

type Option func(*options)

Option to be passed to Connect to customize the resulting instance.

func WithClock

func WithClock(clock clock.Clock) Option

WithClock sets the clock on the option

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger on the option

type Peer

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

Peer represents the node with in the cluster.

func NewPeer

func NewPeer(
	members Members,
	logger log.Logger,
) *Peer

NewPeer creates or joins a cluster with the existing peers. We will listen for cluster communications on the bind addr:port. We advertise a PeerType HTTP API, reachable on apiPort.

func (*Peer) AddHandler

func (p *Peer) AddHandler(handler members.Handler)

AddHandler attaches an event listener to all the members events and broadcasts the event to the handler.

func (*Peer) Address

func (p *Peer) Address() string

Address returns host:port of this peer in the cluster.

func (*Peer) Close

func (p *Peer) Close()

Close out the API

func (*Peer) ClusterSize

func (p *Peer) ClusterSize() int

ClusterSize returns the total size of the cluster from this node's perspective.

func (*Peer) Current

func (p *Peer) Current(peerType members.PeerType, includeLocal bool) (res []string, err error)

Current API host:ports for the given type of node. IncludeLocal doesn't add the local cluster node to the resulting set.

func (*Peer) DispatchEvent

func (p *Peer) DispatchEvent(e members.Event) error

DispatchEvent dispatches an event to all the members in the cluster.

func (*Peer) Join

func (p *Peer) Join() (int, error)

Join attempts to join the cluster

func (*Peer) Leave

func (p *Peer) Leave() error

Leave the cluster.

func (*Peer) Name

func (p *Peer) Name() string

Name returns unique ID of this peer in the cluster.

func (*Peer) RemoveHandler

func (p *Peer) RemoveHandler(handler members.Handler)

RemoveHandler removes the event listener.

func (*Peer) State

func (p *Peer) State() map[string]interface{}

State returns a JSON-serializable dump of cluster state. Useful for debug.

Directories

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

Jump to

Keyboard shortcuts

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