peer

package
v0.0.0-...-e79e798 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var States = map[string]PeerState{
	"LEADER":    LEADER,
	"CANDIDATE": CANDIDATE,
	"FOLLOWER":  FOLLOWER,
	"DEAD":      DEAD,
}

Functions

func ElectionTimeout

func ElectionTimeout() time.Duration

func GetClientConnection

func GetClientConnection(address string) (protocol.ClusterClient, error)

Types

type Event

type Event struct{}
var (
	PeerAdded         Event
	PeerRemoved       Event
	PeerStatusChanged Event
	PeerDead          Event
	PeerAlive         Event
	ElectionIntiated  Event
)

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewMap

func NewMap[K comparable, V any]() Map[K, V]

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) V

func (*Map[K, V]) GetEntries

func (m *Map[K, V]) GetEntries() map[K]V

func (*Map[K, V]) Put

func (m *Map[K, V]) Put(key K, value V)

type Peer

type Peer struct {
	Address string
	Name    string
	State   protocol.PeerState `protobuf:"enum=State" json:"State"`
}

func (*Peer) CheckIsAlive

func (p *Peer) CheckIsAlive() bool

func (*Peer) SendMesagge

func (p *Peer) SendMesagge(event *protocol.Event) error

type PeerState

type PeerState string
const (
	LEADER    PeerState = "LEADER"
	CANDIDATE PeerState = "CANDIDATE"
	FOLLOWER  PeerState = "FOLLOWER"
	DEAD      PeerState = "DEAD"
)

type RaftHub

type RaftHub struct {
	Self   *Peer
	Leader *Peer

	EventCh chan string
	// contains filtered or unexported fields
}

func NewRaft

func NewRaft(self *Peer) *RaftHub

func (*RaftHub) AddPeer

func (r *RaftHub) AddPeer(name, address string)

func (*RaftHub) ChangeLeader

func (r *RaftHub) ChangeLeader(name string) error

func (*RaftHub) CheckFollowersHealth

func (r *RaftHub) CheckFollowersHealth(d time.Duration)

func (*RaftHub) CheckLeaderHealth

func (r *RaftHub) CheckLeaderHealth()

func (*RaftHub) DeRegister

func (r *RaftHub) DeRegister(ctx context.Context, request *protocol.AddPeerRequest) error

func (*RaftHub) GetLogFilename

func (r *RaftHub) GetLogFilename(ctx context.Context) (*protocol.RPCResponse, error)

func (RaftHub) GetPeer

func (r RaftHub) GetPeer(name string) *Peer

func (RaftHub) GetPeerList

func (r RaftHub) GetPeerList() Map[string, *Peer]

func (*RaftHub) GetPeers

func (r *RaftHub) GetPeers(ctx context.Context) (*protocol.PeerList, error)

func (*RaftHub) InitiateElection

func (r *RaftHub) InitiateElection()

func (*RaftHub) InvokePeerElection

func (r *RaftHub) InvokePeerElection(ctx context.Context, address string, message *protocol.InitiateElectionMessage, timeout time.Duration) (*protocol.InitiateElectionMessage, error)

func (*RaftHub) Register

func (r *RaftHub) Register(ctx context.Context, request *protocol.AddPeerRequest) error

func (*RaftHub) RemovePeer

func (r *RaftHub) RemovePeer(name string)

func (*RaftHub) Synchronize

func (r *RaftHub) Synchronize()

func (*RaftHub) UpdatePeerStatus

func (r *RaftHub) UpdatePeerStatus(name string, state protocol.PeerState)

type Vote

type Vote struct {
	Address string `json:"address"`
	Name    string `json:"name"`
	Term    uint   `json:"term"`
}

Jump to

Keyboard shortcuts

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