membership

package
v0.0.0-...-9c44629 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterMember

type ClusterMember struct {
	Address string
	// contains filtered or unexported fields
}

func NewClusterMember

func NewClusterMember(address string) *ClusterMember

func (*ClusterMember) Broadcast

func (n *ClusterMember) Broadcast(ctx context.Context, listener func([]byte))

func (*ClusterMember) Emit

func (n *ClusterMember) Emit(value []byte) error

func (*ClusterMember) EventLeader

func (n *ClusterMember) EventLeader(isMaster bool, master string)

func (*ClusterMember) GetBroadcasts

func (n *ClusterMember) GetBroadcasts(overhead, limit int) [][]byte

Membership Delegate

func (*ClusterMember) Leave

func (n *ClusterMember) Leave(node *memberlist.Node)

func (*ClusterMember) LocalState

func (n *ClusterMember) LocalState(join bool) []byte

Membership Delegate

func (*ClusterMember) MergeRemoteState

func (n *ClusterMember) MergeRemoteState(buf []byte, join bool)

Membership Delegate

func (*ClusterMember) NodeMeta

func (n *ClusterMember) NodeMeta(limit int) []byte

Membership Delegate

func (*ClusterMember) NotifyMsg

func (n *ClusterMember) NotifyMsg(msg []byte)

Membership Delegate

type Election

type Election struct {
	Client *api.Client // Consul client
	Checks []string    // Slice of associated health checks

	Kv string // Key in Consul kv

	CheckTimeout time.Duration
	LogPrefix    string // Prefix for a log

	Event  Notifier
	Node   string
	Master string
	sync.RWMutex

	Num int
	// contains filtered or unexported fields
}

Election implements to detect a leader in a cluster of services

func NewElection

func NewElection(c *ElectionConfig) *Election

Params: Consul client, slice of associated health checks, service name

func (*Election) Init

func (e *Election) Init()

Init starting election process

func (*Election) IsLeader

func (e *Election) IsLeader() bool

IsLeader check a leader

func (*Election) NotifyJoin

func (e *Election) NotifyJoin(node *memberlist.Node)

func (*Election) NotifyLeave

func (e *Election) NotifyLeave(node *memberlist.Node)

func (*Election) NotifyUpdate

func (e *Election) NotifyUpdate(node *memberlist.Node)

func (*Election) SetLogLevel

func (e *Election) SetLogLevel(level uint8)

SetLogLevel is setting level according constants LogDisable|LogError|LogInfo|LogDebug

func (*Election) Stop

func (e *Election) Stop()

Stop election process

type ElectionConfig

type ElectionConfig struct {
	Client       *api.Client // Consul client
	Checks       []string    // Slice of associated health checks
	Key          string      // Key in Consul KV
	LogLevel     uint8       // Log level LogDisable|LogError|LogInfo|LogDebug
	LogPrefix    string      // Prefix for a log
	Event        Notifier
	CheckTimeout time.Duration
	Node         string
}

ElectionConfig config for Election

type Notifier

type Notifier interface {
	EventLeader(e bool, master string) // The method will be called when the leader status is changed
	Leave(node *memberlist.Node)
}

Notifier can tell your code the event of the leader's status change

Jump to

Keyboard shortcuts

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