cluster

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClockDiffrent is a clock difference.
	ClockDiffrent = 1
	// ClockMax is a maximum clock value.
	ClockMax = math.MaxUint64
)
View Source
const (
	DefaultClusterName = "puzzledb"
)

Variables

This section is empty.

Functions

func CompareClocks

func CompareClocks(c1 Clock, c2 Clock) int

CompareClocks compares two clocks. If c1 and c2 are equal, returns 0. If c1 is greater than c2, returns 1. If c2 is greater than c1, returns -1. However, if the difference between c1 and c2 is greater than half of the maximum UNIT64 value, the clock is considered to be back to zero and the comparison results are reversed.

Types

type Clock

type Clock = uint64

Clock represents a logical clock.

func MaxClock

func MaxClock(c1 Clock, c2 Clock) Clock

MaxClock returns the maximum clock.

func NewClock

func NewClock() Clock

NewClock returns a new clock.

type Cluster

type Cluster interface {
	// Name returns a name of the cluster.
	Name() string
	// Nodes returns nodes in the cluster.
	Nodes() []Node
}

Cluster represents a cluster.

func NewCluster

func NewCluster() Cluster

NewCluster returns a new cluster.

func NewClusterWith

func NewClusterWith(name string, nodes []Node) Cluster

NewClusterWith returns a new cluster with the specified name and nodes.

type Node

type Node interface {
	// SetCluster sets a cluster name to the cluster node.
	SetCluster(cluster string)
	// Cluster returns a cluster name of the cluster node.
	Cluster() string
	// SetID sets a UUID to the cluster node.
	SetID(uuid uuid.UUID)
	// ID returns a UUID of the cluster node.
	ID() uuid.UUID
	// SetHost sets a host name to the cluster node.
	SetHost(host string)
	// Host returns a host name of the cluster node.
	Host() string
	// SetClock sets a logical clock to the cluster node.
	SetClock(clock Clock)
	// Clock returns a logical clock of the cluster node.
	Clock() Clock
	// SetReceivedClock sets a received logical clock to the cluster node.
	SetReceivedClock(clock Clock) Clock
	// IncrementClock increments a logical clock of the cluster node.
	IncrementClock() Clock
	// SetTimestamp sets a phisical timestamp to the cluster node.
	SetTimestamp(ts time.Time)
	// Timestamp returns a phisical timestamp of the cluster node.
	Timestamp() time.Time
	// SetStatus sets a status to the cluster node.
	SetStatus(state NodeStatus)
	// Status returns a status of the cluster node.
	Status() NodeStatus
	// Equals returns true if the specified cluster node is same as this node.
	Equals(node Node) bool
	// Lock locks the cluster node.
	Lock()
	// Unlock unlocks the cluster node.
	Unlock()
}

Node represents a cluster node.

func NewNode

func NewNode() Node

type NodeStatus

type NodeStatus int

NodeStatus represents a cluster node status.

const (
	// NodeUnknown represents an unknown node status.
	NodeUnknown NodeStatus = iota
	// NodeIdle represents an idle node status.
	NodeIdle
	// NodeJoining represents a joining node status.
	NodeJoining
	// NodeUp represents a running node status.
	NodeUp
	// NodeDown represents a down node status.
	NodeDown
	// NodeLeaving represents a leaving node status.
	NodeLeaving
	// NodeExiting represents an exiting node status.
	NodeExiting
	// NodeRemoved represents a removed node status.
	NodeRemoved
	// NodeAborted represents an aborted node status.
	NodeAborted
	// NodeUnreachable represents an unreachable node status.
	NodeUnreachable
)

func NewNodeStatusWith

func NewNodeStatusWith(s string) NodeStatus

NewNodeStatusWith returns a new node status with the specified string.

func (NodeStatus) String

func (t NodeStatus) String() string

String represents a string of the node status.

Jump to

Keyboard shortcuts

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