election

package
v0.0.0-...-7b93ac1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotLeader is returned when a node attempts to execute a leader-only
	// operation.
	ErrNotLeader = errors.New("not leader")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Bind    string `json:"bind"`
	DataDir string `json:"data_dir"`
	Peers   string `json:"peers"`
}

Config ?

type Election

type Election struct {
	NodeStatCh  chan NodeState
	OperationCh chan OperationType
	// contains filtered or unexported fields
}

Election leader election with raft

func New

func New(raftBindAddr utils.NetAddr, raftDataDir string, raftPeers utils.NetAddrList, enableSingle bool) *Election

New return an Election instance

func (*Election) Join

func (p *Election) Join(id, addr string) error

Join let peers join into cluster

func (*Election) RecvOperation

func (p *Election) RecvOperation(op OperationType) error

func (*Election) RemovePeer

func (p *Election) RemovePeer(id string) error

func (*Election) RemoveSvr

func (p *Election) RemoveSvr(id string) error

func (*Election) Start

func (p *Election) Start() error

Start start and maintain leader election and monitor

func (*Election) TransferLeaderShip

func (p *Election) TransferLeaderShip(id, address string) error

type NodeState

type NodeState int

NodeState follower, candidate, leader

const (
	//Follower value zero
	Follower NodeState = iota
	//Candidate value 1
	Candidate
	//Leader value 2
	Leader
)

func (NodeState) String

func (e NodeState) String() string

type Operation

type Operation interface {
	TransferLeaderShip(id, address string) error
	Join(id, address string) error
	RemoveSvr(id string) error
}

type OperationType

type OperationType int

OperationType for raft peers

const (
	// Remove remove raft peer
	Remove OperationType = iota
)

Jump to

Keyboard shortcuts

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