Documentation ¶
Index ¶
- Variables
- func ClusterInfoFilename(dataDir string) string
- func FetchNodeID(dataDir string) (id types.ID, err error)
- func FetchOrAssignNodeID(ctx context.Context, dataDir string) (id types.ID)
- func NewClusterProto() *kronospb.Cluster
- type Cluster
- func (c *Cluster) ActiveNodes() map[string]*kronospb.Node
- func (c *Cluster) AddNode(id string, addr *kronospb.NodeAddr) error
- func (c *Cluster) Close() error
- func (c *Cluster) Node(id string) (node *kronospb.Node, ok bool)
- func (c *Cluster) NodesIncludingRemoved() map[string]*kronospb.Node
- func (c *Cluster) Persist() error
- func (c *Cluster) PrettyPrint() (string, error)
- func (c *Cluster) RemoveNode(nodeID string)
- func (c *Cluster) UpdateAddrs(oldToNewAddr map[string]string, withPorts bool) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
ClusterInfoFilename returns the name of the file which stores cluster info.
func FetchNodeID ¶
FetchNodeID returns the nodeID if nodeInfoFile exists in data directory Otherwise it returns an error
func FetchOrAssignNodeID ¶
FetchOrAssignNodeID returns the nodeID if the nodeInfoFile exists in data directory. Otherwise it persists a new nodeID to nodeInfoFile and returns the same.
func NewClusterProto ¶
func NewClusterProto() *kronospb.Cluster
NewClusterProto returns an initialized cluster proto.
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 ¶
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 ¶
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 ¶
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 ¶
AddNode adds a new node with given ID/address. It returns an error if a node with this ID already exists.
func (*Cluster) Node ¶
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 ¶
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 ¶
Persist persists c to file using checksumfile. It fails if cluster was loaded in readOnly mode.
func (*Cluster) PrettyPrint ¶
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 ¶
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 ¶
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.