Documentation ¶
Index ¶
- Constants
- Variables
- type Broadcast
- type Cluster
- type Config
- type Delegate
- type EventDelegate
- type EventName
- type FinishFunc
- type Messenger
- type NodeMeta
- type NodeState
- type SelectLeaderMessage
- type State
- type StateManager
- func (s *StateManager) AssignWorkers()
- func (s *StateManager) CurrentState() string
- func (s *StateManager) ElectLeader() bool
- func (s *StateManager) HasNode(key uint16) bool
- func (s *StateManager) ImportState(state map[uint16]NodeState)
- func (s *StateManager) IsLeader() bool
- func (s *StateManager) IsLocalNode(key uint16) bool
- func (s *StateManager) LocalNodeID() uint16
- func (s *StateManager) LocalNodeState() NodeState
- func (s *StateManager) LocalState() map[uint16]NodeState
- func (s *StateManager) ReleaseWorkers()
- func (s *StateManager) RemoveNode(id uint16) bool
- func (s *StateManager) SetState(name StateName)
- func (s *StateManager) Size() int
- func (s *StateManager) StartWorkers()
- func (s *StateManager) StopWorkers()
- func (s *StateManager) Trigger(name EventName, args ...interface{}) error
- type StateName
- type Update
- type Worker
Constants ¶
const ( Idle StateName = "idle" Configuring StateName = "configuring" Joining StateName = "joining" Assembling StateName = "assembling" Electing StateName = "electing" Assigning StateName = "balancing" Working StateName = "working" Starting StateName = "starting" Stopping StateName = "stopping" Join EventName = "join" Joined EventName = "joined" Assemble EventName = "assemble" Assembled EventName = "assembled" Elect EventName = "elect" Elected EventName = "elected" Assign EventName = "assign" Assigned EventName = "assigned" Start EventName = "start" Started EventName = "started" Stop EventName = "stop" Stopped EventName = "stopped" Finish EventName = "finish" PlDb Worker = "pl_db" UaDb Worker = "ua_db" RoDb Worker = "ro_db" KzDb Worker = "kz_db" PtDb Worker = "pt_db" BgDb Worker = "bg_db" UzDb Worker = "uz_db" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Broadcast ¶
type Broadcast struct {
// contains filtered or unexported fields
}
func NewBroadcast ¶
func NewBroadcast(logger *zap.Logger, ml *memberlist.Memberlist, name string, msg []byte, notifyCh chan<- struct{}) *Broadcast
func (*Broadcast) Invalidates ¶
func (b *Broadcast) Invalidates(other memberlist.Broadcast) bool
type Cluster ¶
type Cluster struct { Config *Config Memberlist *memberlist.Memberlist State *StateManager Messenger *Messenger // contains filtered or unexported fields }
type Config ¶
type Config struct { NodeID uint16 `yaml:"node_id"` BindAddr string `yaml:"bind_addr"` BindPort int `yaml:"bind_port"` AdvertiseAddr string `yaml:"advertise_addr"` AdvertisePort int `yaml:"advertise_port"` PushPullIntervalMS int `yaml:"push_pull_interval_ms"` First bool `yaml:"first"` JoinNodes []string `yaml:"join_nodes"` JoinNodesNum int `yaml:"join_nodes_num"` JoinTimeoutS int `yaml:"join_timeout_s"` AssembleTimeoutS int `yaml:"assemble_timeout_s"` ElectLeaderS int `yaml:"elect_leader_s"` Debug bool `yaml:"debug"` }
type Delegate ¶
type Delegate struct { State *StateManager // contains filtered or unexported fields }
func (*Delegate) GetBroadcasts ¶
GetBroadcasts is called when user data messages can be broadcast. It can return a list of buffers to send. Each buffer should assume an overhead as provided with a limit on the total byte size allowed. The total byte size of the resulting data to send must not exceed the limit. Care should be taken that this method does not block, since doing so would block the entire UDP packet receive loop.
func (*Delegate) LocalState ¶
LocalState is used for a TCP Push/Pull. This is sent to the remote side in addition to the membership information. Any data can be sent here. See MergeRemoteState as well. The `join` boolean indicates this is for a join instead of a push/pull.
func (*Delegate) MergeRemoteState ¶
MergeRemoteState is invoked after a TCP Push/Pull. This is the state received from the remote side and is the result of the remote side's LocalState call. The 'join' boolean indicates this is for a join instead of a push/pull.
func (*Delegate) NodeMeta ¶
NodeMeta is used to retrieve meta-data about the current node when broadcasting an alive message. Its length is limited to the given byte size. This metadata is available in the Node structure.
func (*Delegate) NotifyMsg ¶
NotifyMsg is called when a user-data message is received. Care should be taken that this method does not block, since doing so would block the entire UDP packet receive loop. Additionally, the byte slice may be modified after the call returns, so it should be copied if needed
type EventDelegate ¶
type EventDelegate struct {
// contains filtered or unexported fields
}
EventDelegate is a simpler delegate that is used only to receive notifications about members joining and leaving. The methods in this delegate may be called by multiple goroutines, but never concurrently. This allows you to reason about ordering.
func (*EventDelegate) NotifyJoin ¶
func (d *EventDelegate) NotifyJoin(node *memberlist.Node)
NotifyJoin is invoked when a node is detected to have joined. The Node argument must not be modified. - stop workers - assemble - elect leader - distribute load - start workers
func (*EventDelegate) NotifyLeave ¶
func (d *EventDelegate) NotifyLeave(node *memberlist.Node)
NotifyLeave is invoked when a node is detected to have left. The Node argument must not be modified.
func (*EventDelegate) NotifyUpdate ¶
func (d *EventDelegate) NotifyUpdate(node *memberlist.Node)
NotifyUpdate is invoked when a node is detected to have updated, usually involving the metadata. The Node argument must not be modified.
type FinishFunc ¶
type FinishFunc func()
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
func (*Messenger) SelectLeader ¶
type SelectLeaderMessage ¶
type StateManager ¶
type StateManager struct {
// contains filtered or unexported fields
}
func (*StateManager) AssignWorkers ¶
func (s *StateManager) AssignWorkers()
func (*StateManager) CurrentState ¶
func (s *StateManager) CurrentState() string
func (*StateManager) ElectLeader ¶
func (s *StateManager) ElectLeader() bool
ElectLeader sets leader for LocalNode & returns true when 100% quorum is achieved
func (*StateManager) HasNode ¶
func (s *StateManager) HasNode(key uint16) bool
func (*StateManager) ImportState ¶
func (s *StateManager) ImportState(state map[uint16]NodeState)
func (*StateManager) IsLeader ¶
func (s *StateManager) IsLeader() bool
func (*StateManager) IsLocalNode ¶
func (s *StateManager) IsLocalNode(key uint16) bool
func (*StateManager) LocalNodeID ¶
func (s *StateManager) LocalNodeID() uint16
func (*StateManager) LocalNodeState ¶
func (s *StateManager) LocalNodeState() NodeState
func (*StateManager) LocalState ¶
func (s *StateManager) LocalState() map[uint16]NodeState
func (*StateManager) ReleaseWorkers ¶
func (s *StateManager) ReleaseWorkers()
func (*StateManager) RemoveNode ¶
func (s *StateManager) RemoveNode(id uint16) bool
func (*StateManager) SetState ¶
func (s *StateManager) SetState(name StateName)
func (*StateManager) Size ¶
func (s *StateManager) Size() int
func (*StateManager) StartWorkers ¶
func (s *StateManager) StartWorkers()
func (*StateManager) StopWorkers ¶
func (s *StateManager) StopWorkers()
func (*StateManager) Trigger ¶
func (s *StateManager) Trigger(name EventName, args ...interface{}) error