leader

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 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 Actor

type Actor struct {
	gen.Process
	// contains filtered or unexported fields
}

func (*Actor) Bootstrap

func (l *Actor) Bootstrap() []gen.ProcessID

Bootstrap returns the bootstrap peer list

func (*Actor) Broadcast

func (l *Actor) Broadcast(message any)

Broadcast sends a message to all known peers

func (*Actor) BroadcastBootstrap

func (l *Actor) BroadcastBootstrap(message any)

BroadcastBootstrap sends a message to all bootstrap peers (excluding self)

func (*Actor) ClusterID

func (l *Actor) ClusterID() string

ClusterID returns the cluster identifier

func (*Actor) HandleCall

func (l *Actor) HandleCall(from gen.PID, ref gen.Ref, request any) (any, error)

func (*Actor) HandleInspect

func (l *Actor) HandleInspect(from gen.PID, item ...string) map[string]string

func (*Actor) HandleMessage

func (l *Actor) HandleMessage(from gen.PID, message any) error

func (*Actor) HandlePeerJoined

func (l *Actor) HandlePeerJoined(peer gen.PID) error

func (*Actor) HandlePeerLeft

func (l *Actor) HandlePeerLeft(peer gen.PID) error

func (*Actor) HandleTermChanged

func (l *Actor) HandleTermChanged(oldTerm, newTerm uint64) error

func (*Actor) HasPeer

func (l *Actor) HasPeer(pid gen.PID) bool

HasPeer checks if a PID is a known peer

func (*Actor) IsLeader

func (l *Actor) IsLeader() bool

IsLeader returns true if this node is the leader

func (*Actor) Join

func (l *Actor) Join(peer gen.ProcessID)

Join adds a peer to the cluster Use this to manually add known peers or for dynamic cluster growth

func (*Actor) Leader

func (l *Actor) Leader() gen.PID

Leader returns the current leader PID (empty if no leader)

func (*Actor) PeerCount

func (l *Actor) PeerCount() int

PeerCount returns the number of known peers

func (*Actor) Peers

func (l *Actor) Peers() []gen.PID

Peers returns a snapshot of current peer list

func (*Actor) ProcessInit

func (l *Actor) ProcessInit(process gen.Process, args ...any) (rr error)

func (*Actor) ProcessRun

func (l *Actor) ProcessRun() (rr error)

func (*Actor) ProcessTerminate

func (l *Actor) ProcessTerminate(reason error)

func (*Actor) Term

func (l *Actor) Term() uint64

Term returns the current election term

func (*Actor) Terminate

func (l *Actor) Terminate(reason error)

type ActorBehavior

type ActorBehavior interface {
	gen.ProcessBehavior

	Init(args ...any) (Options, error)
	HandleMessage(from gen.PID, message any) error
	HandleCall(from gen.PID, ref gen.Ref, request any) (any, error)
	Terminate(reason error)
	HandleInspect(from gen.PID, item ...string) map[string]string

	// Leadership callbacks
	HandleBecomeLeader() error
	HandleBecomeFollower(leader gen.PID) error

	// Peer management callbacks
	HandlePeerJoined(peer gen.PID) error
	HandlePeerLeft(peer gen.PID) error

	// Term management callback
	HandleTermChanged(oldTerm, newTerm uint64) error
}

type Options

type Options struct {
	ClusterID string
	Bootstrap []gen.ProcessID

	ElectionTimeoutMin int // Minimum election timeout (ms, default: 150)
	ElectionTimeoutMax int // Maximum election timeout (ms, default: 300)
	HeartbeatInterval  int // Heartbeat interval (ms, default: 50)
}

Options for leader election

Jump to

Keyboard shortcuts

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