Documentation ¶
Index ¶
- Variables
- func ToProtoNode(node *Node) *proto.Node
- func ToProtoNodeList(nodes []Node) []*proto.Node
- type Cluster
- type Config
- type Node
- type NodeID
- type SWIMCluster
- func (cl *SWIMCluster) AddConn(id NodeID, conn *nodeapi.Client)
- func (cl *SWIMCluster) ApplyState(nodes []Node, sourceID NodeID) []Node
- func (cl *SWIMCluster) Conn(id NodeID) (*nodeapi.Client, error)
- func (cl *SWIMCluster) ConnContext(ctx context.Context, id NodeID) (*nodeapi.Client, error)
- func (cl *SWIMCluster) Join(ctx context.Context, addr string) error
- func (cl *SWIMCluster) Leave(ctx context.Context) error
- func (cl *SWIMCluster) LocalConn() *nodeapi.Client
- func (cl *SWIMCluster) Node(id NodeID) (Node, bool)
- func (cl *SWIMCluster) Nodes() []Node
- func (cl *SWIMCluster) Self() Node
- func (cl *SWIMCluster) SelfID() NodeID
- func (cl *SWIMCluster) Start()
- func (cl *SWIMCluster) StateHash() uint64
- type Status
Constants ¶
This section is empty.
Variables ¶
var FromProtoStatusMap = map[proto.Status]Status{ proto.Status_HEALTHY: StatusHealthy, proto.Status_UNHEALTHY: StatusUnhealthy, proto.Status_LEFT: StatusLeft, }
var ToProtoStatusMap = map[Status]proto.Status{ StatusHealthy: proto.Status_HEALTHY, StatusUnhealthy: proto.Status_UNHEALTHY, StatusLeft: proto.Status_LEFT, }
Functions ¶
func ToProtoNode ¶
func ToProtoNodeList ¶
Types ¶
type Cluster ¶
type Cluster interface { Node(id NodeID) (Node, bool) Nodes() []Node SelfID() NodeID Self() Node ConnContext(ctx context.Context, id NodeID) (*nodeapi.Client, error) Conn(id NodeID) (*nodeapi.Client, error) LocalConn() *nodeapi.Client ApplyState(nodes []Node, sourceID NodeID) []Node StateHash() uint64 }
type Config ¶
type Config struct { NodeID NodeID NodeName string PublicAddr string LocalAddr string Dialer nodeapi.Dialer Logger kitlog.Logger DialTimeout time.Duration ProbeTimeout time.Duration ProbeInterval time.Duration ProbeJitter float64 GCInterval time.Duration IndirectNodes int }
func DefaultConfig ¶
func DefaultConfig() Config
type Node ¶
type Node struct { ID NodeID RunID int64 Name string PublicAddr string LocalAddr string Error string Status Status LocalStatus Status Gen uint32 }
Node represents a single cluster member.
func FromProtoNode ¶
func FromProtoNodeList ¶
func (*Node) IsReachable ¶
IsReachable returns true if the node is reachable.
type SWIMCluster ¶
type SWIMCluster struct {
// contains filtered or unexported fields
}
func NewCluster ¶
func NewCluster(conf Config) *SWIMCluster
func (*SWIMCluster) AddConn ¶
func (cl *SWIMCluster) AddConn(id NodeID, conn *nodeapi.Client)
AddConn adds a connection to the cluster. If a connection to the same member already exists, the old connection is closed. This method is intended to be used during tests or during the cluster bootstrap.
func (*SWIMCluster) ApplyState ¶
func (cl *SWIMCluster) ApplyState(nodes []Node, sourceID NodeID) []Node
ApplyState merges the given nodes with the current cluster state and returns the list of all nodes in the cluster after the merge.
func (*SWIMCluster) Conn ¶
func (cl *SWIMCluster) Conn(id NodeID) (*nodeapi.Client, error)
Conn returns a connection to the member with the given ID. If the connection is not present, it attempts to dial the member and create a new connection.
func (*SWIMCluster) ConnContext ¶
ConnContext returns a connection to the member with the given ID. If the connection is not present, it attempts to dial the member and create a new connection. The context is used to cancel the dialing process.
func (*SWIMCluster) Join ¶
func (cl *SWIMCluster) Join(ctx context.Context, addr string) error
Join adds the current node to the cluster with the given address. All nodes from the remote cluster are added to the local cluster and vice versa.
func (*SWIMCluster) Leave ¶
func (cl *SWIMCluster) Leave(ctx context.Context) error
Leave removes the current node from the cluster. The leave call blocks until at least one other node acknowledges the leave request.
func (*SWIMCluster) LocalConn ¶
func (cl *SWIMCluster) LocalConn() *nodeapi.Client
LocalConn returns a connection to the local member. It assumes that the local connection is always stable, so it panics if it is not present.
func (*SWIMCluster) Node ¶
func (cl *SWIMCluster) Node(id NodeID) (Node, bool)
Node returns the node with the given ID, if it exists.
func (*SWIMCluster) Nodes ¶
func (cl *SWIMCluster) Nodes() []Node
Nodes returns a list of all nodes in the cluster, including the current node, and nodes that have recently left the cluster but have not been garbage collected yet.
func (*SWIMCluster) SelfID ¶
func (cl *SWIMCluster) SelfID() NodeID
SelfID returns the ID of the current node.
func (*SWIMCluster) Start ¶
func (cl *SWIMCluster) Start()
Start schedules background tasks for managing the cluster state, such as probing nodes and garbage collecting nodes that have left the cluster.
func (*SWIMCluster) StateHash ¶
func (cl *SWIMCluster) StateHash() uint64