cluster

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyMetadata

func CopyMetadata(s map[string]string) map[string]string

Types

type Cluster

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

Cluster represents the shared view of the nodes in the cluster.

func NewCluster

func NewCluster(localNode Node) *Cluster

NewCluster returns a cluster state containing only the given local node.

func (*Cluster) ApplyUpdate

func (s *Cluster) ApplyUpdate(update *NodeUpdate) error

ApplyUpdate applies the given node state update and sends it to the subscribers.

func (*Cluster) Node

func (s *Cluster) Node(id string) (Node, bool)

Node returns the state of the node in the cluster with the given ID.

func (*Cluster) Nodes

func (s *Cluster) Nodes() []Node

func (*Cluster) Subscribe

func (s *Cluster) Subscribe(rewind bool, cb func(update *NodeUpdate)) func()

Subscribe subscribes to RPC to updates.

The callback is called with the cluster state mutex held (to guarantee ordering) so it MUST NOT block and MUST NOT call back to the cluster state.

If rewind is true the callback is called with join updates for existing nodes. Used to get the current node state and subscribe in one atomic transaction.

Returns a function to unsubscribe.

type Metadata

type Metadata map[string]string

func (Metadata) MarshalLogObject

func (m Metadata) MarshalLogObject(e zapcore.ObjectEncoder) error

type Node

type Node struct {
	// ID is a unique identifier for the node in the cluster.
	ID string `json:"id,omitempty"`

	// Service is the type of service running on the node.
	Service string `json:"service,omitempty"`

	// Locality is the location of the node in the cluster.
	Locality string `json:"locality,omitempty"`

	// Created is the time the node was created in UNIX milliseconds.
	Created int64 `json:"created,omitempty"`

	// Revision identifies the version of the service running on the node.
	Revision string `json:"revision,omitempty"`

	// Metadata is application defined information about the node.
	Metadata map[string]string `json:"metadata,omitempty"`
}

Node represents the state of a node that is propagated to other nodes in the cluster.

func (*Node) Copy

func (s *Node) Copy() Node

type NodeAttributes

type NodeAttributes struct {
	// Service is the type of service running on the node.
	Service string `json:"service,omitempty"`

	// Locality is the location of the node in the cluster.
	Locality string `json:"locality,omitempty"`

	// Created is the time the node was created in UNIX milliseconds.
	Created int64 `json:"created,omitempty"`

	// Revision identifies the version of the service running on the node.
	Revision string `json:"revision,omitempty"`
}

func (*NodeAttributes) MarshalLogObject

func (a *NodeAttributes) MarshalLogObject(e zapcore.ObjectEncoder) error

type NodeUpdate

type NodeUpdate struct {
	// ID is the ID of the node in the update.
	ID string `json:"id,omitempty"`

	// UpdateType indicates the type of update, either register, unregister or
	// metadata.
	UpdateType UpdateType `json:"update_type,omitempty"`

	// Attributes contains the set of immutable attributes for the node. This
	// will only be included in register updates.
	Attributes *NodeAttributes `json:"attributes,omitempty"`

	// Metadata contains application defined metadata. If the update is type
	// metadata, the field only contains the fields that have been updated.
	Metadata Metadata `json:"metadata,omitempty"`
}

func (*NodeUpdate) MarshalLogObject

func (u *NodeUpdate) MarshalLogObject(e zapcore.ObjectEncoder) error

type UpdateType

type UpdateType string
const (
	UpdateTypeRegister   UpdateType = "register"
	UpdateTypeUnregister UpdateType = "unregister"
	UpdateTypeMetadata   UpdateType = "metadata"
)

Jump to

Keyboard shortcuts

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