metadata

package
v0.0.0-...-2c42c2a Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoClusterFile = errors.New("cluster file does not exist")

ErrNoClusterFile is returned when the cluster file does not exist when trying to load an existing cluster.

Functions

func ClusterInfoFilename

func ClusterInfoFilename(dataDir string) string

ClusterInfoFilename returns the name of the file which stores cluster info.

func FetchNodeID

func FetchNodeID(dataDir string) (id types.ID, err error)

FetchNodeID returns the nodeID if nodeInfoFile exists in data directory Otherwise it returns an error

func FetchOrAssignNodeID

func FetchOrAssignNodeID(ctx context.Context, dataDir string) (id types.ID)

FetchOrAssignNodeID returns the nodeID if the nodeInfoFile exists in data directory. Otherwise it persists a new nodeID to nodeInfoFile and returns the same.

func GenerateNewNodeID

func GenerateNewNodeID() types.ID

func NewClusterProto

func NewClusterProto() *kronospb.Cluster

NewClusterProto returns an initialized cluster proto.

func PersistNewNodeID

func PersistNewNodeID(ctx context.Context, id string, dataDir string)

Types

type Cluster

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

Cluster is a wrapper around *kronospb.Cluster so that methods can be defined on it. It is thread-safe and it creates a lock file in dataDir when readOnly is false, so that at max one instance of Cluster with write access can exist at a time for a dataDir across all processes/threads.

func LoadCluster

func LoadCluster(dataDir string, readOnly bool) (*Cluster, error)

LoadCluster loads the persisted Cluster from dataDir if the cluster info file exists inside it. If no cluster info file exists in dataDir, it returns ErrNoClusterFile. If readOnly is true, then the returned Cluster is only good for reading, and trying to persist it will return an error.

func NewCluster

func NewCluster(dataDir string, cluster *kronospb.Cluster) (*Cluster, error)

NewCluster creates a new Cluster initialized from cluster. If cluster is nil, an empty cluster is created. The returned cluster is persistable, but not persisted yet. It needs to be explicitly persisted if required.

func (*Cluster) ActiveNodes

func (c *Cluster) ActiveNodes() map[string]*kronospb.Node

ActiveNodes returns the nodes which are an active part of the cluster. This excludes the nodes which have been removed from the cluster.

func (*Cluster) AddNode

func (c *Cluster) AddNode(id string, addr *kronospb.NodeAddr) error

AddNode adds a new node with given ID/address. It returns an error if a node with this ID already exists.

func (*Cluster) Close

func (c *Cluster) Close() error

Close closes the cluster.

func (*Cluster) Node

func (c *Cluster) Node(id string) (node *kronospb.Node, ok bool)

Node returns the node with the given ID from the cluster metadata. If the node does not exist, ok will be false.

func (*Cluster) NodesIncludingRemoved

func (c *Cluster) NodesIncludingRemoved() map[string]*kronospb.Node

NodesIncludingRemoved returns all the nodes which have been a part of this cluster. This includes the nodes which have been removed from the cluster.

func (*Cluster) Persist

func (c *Cluster) Persist() error

Persist persists c to file using checksumfile. It fails if cluster was loaded in readOnly mode.

func (*Cluster) PrettyPrint

func (c *Cluster) PrettyPrint() (string, error)

PrettyPrint returns a string which is a table having node ids, addresses and whether the node has been removed for nodes stored in c.

func (*Cluster) RemoveNode

func (c *Cluster) RemoveNode(nodeID string)

RemoveNode sets nodeID as removed. It creates the node and marks it as removed if it doesn't already exist in metadata. This function is idempotent and it is OK to remove an already removed node.

func (*Cluster) UpdateAddrs

func (c *Cluster) UpdateAddrs(oldToNewAddr map[string]string, withPorts bool) error

UpdateAddrs updates raft addresses of nodes in c. oldToNewAddr should contain mapping of old to new addresses. If withPorts is true, kronos raft ports are also updated, otherwise only hosts are updated. Both old and new addresses must be present in 'host:port' format in oldToNewAddr if this is set to true. If withPorts is false, oldToNewAddr should contain only hosts and no ports.

Jump to

Keyboard shortcuts

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