gossip

package
v0.0.0-...-59b76e6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var Workers = []Worker{PlDb, UaDb, RoDb, KzDb, PtDb, BgDb, UzDb}

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) Finished

func (b *Broadcast) Finished()

func (*Broadcast) Invalidates

func (b *Broadcast) Invalidates(other memberlist.Broadcast) bool

func (*Broadcast) Message

func (b *Broadcast) Message() []byte

func (*Broadcast) Name

func (b *Broadcast) Name() string

type Cluster

type Cluster struct {
	Config     *Config
	Memberlist *memberlist.Memberlist
	State      *StateManager
	Messenger  *Messenger
	// contains filtered or unexported fields
}

func NewCluster

func NewCluster(logger *zap.Logger, cfg *Config, stopCh <-chan struct{}) (*Cluster, error)

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

func (d *Delegate) GetBroadcasts(overhead, limit int) [][]byte

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

func (d *Delegate) LocalState(join bool) []byte

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

func (d *Delegate) MergeRemoteState(buf []byte, join bool)

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

func (d *Delegate) NodeMeta(limit int) []byte

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

func (d *Delegate) NotifyMsg(b []byte)

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 EventName

type EventName = string

type FinishFunc

type FinishFunc func()

type Messenger

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

func (*Messenger) Broadcast

func (m *Messenger) Broadcast(topic string, data []byte)

func (*Messenger) SelectLeader

func (m *Messenger) SelectLeader(leaderID uint16) error

type NodeMeta

type NodeMeta struct {
	NodeID uint16 `json:"node_id"`
}

type NodeState

type NodeState struct {
	Name      string    `json:"name"`
	State     StateName `json:"state"`
	Leader    uint16    `json:"leader"`
	Workers   []Worker  `json:"workers"`
	Working   bool      `json:"working"`
	Timestamp time.Time `json:"timestamp"`
}

type SelectLeaderMessage

type SelectLeaderMessage struct {
	Method string `json:"method"`
	Args   struct {
		Leader uint16 `json:"leader"`
	} `json:"args"`
}

type State

type State struct {
	Indexes []uint16
	Nodes   map[uint16]NodeState `json:"nodes"`
	Working map[string]bool
}

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

type StateName

type StateName = string

type Update

type Update struct {
	Action string
	Data   map[string]string
}

type Worker

type Worker = string

Jump to

Keyboard shortcuts

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