raft

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MsgNone type.
	MsgNone = iota + 1

	// MsgRaftHeartbeat type.
	MsgRaftHeartbeat

	// MsgRaftRequestVote type.
	MsgRaftRequestVote

	// MsgRaftPing type.
	MsgRaftPing
)

Variables

This section is empty.

Functions

func MockGetClient

func MockGetClient(t *testing.T, svrConn string) (*xrpc.Client, func())

MockGetClient mock.

func MockSetMysqlHandler added in v1.0.5

func MockSetMysqlHandler(raft *Raft, h mysql.MysqlHandler)

MockSetMysqlHandler used to set mysql repl hander for test.

func MockStateTransition

func MockStateTransition(raft *Raft, state State)

MockStateTransition use to transfer the raft.state to state.

func MockWaitHeartBeatTimeout added in v1.0.7

func MockWaitHeartBeatTimeout()

MockWaitHeartBeatTimeout used to wait mysql ping timeout.

func MockWaitLeaderEggs

func MockWaitLeaderEggs(rafts []*Raft, leadernums int) int

MockWaitLeaderEggs mock. wait the leader eggs when leadernums >0 if leadernums == 0, we just want to sleep for a heartbeat broadcast

func MockWaitMySQLPingTimeout

func MockWaitMySQLPingTimeout()

MockWaitMySQLPingTimeout used to wait mysql ping timeout.

Types

type Candidate

type Candidate struct {
	*Raft
	// contains filtered or unexported fields
}

Candidate tuple.

func NewCandidate

func NewCandidate(r *Raft) *Candidate

NewCandidate creates the new Candidate.

func (*Candidate) Loop

func (r *Candidate) Loop()

Loop used to start the loop of the state machine. -------------------------------------- State Machine --------------------------------------

get majority votes

State1. CANDIDATE ------------------------> LEADER

higher viewid/new leader

State2. CANDIDATE ------------------------> FOLLOWER

timeout

State3. CANDIDATE ------------------------> CANDIDATE

type Follower

type Follower struct {
	*Raft
	// Whether the 'change to master' is success or not when the new leader eggs.
	ChangeToMasterError bool
	// contains filtered or unexported fields
}

Follower tuple.

func NewFollower

func NewFollower(r *Raft) *Follower

NewFollower creates new Follower.

func (*Follower) Loop

func (r *Follower) Loop()

Loop used to start the loop of the state machine. -------------------------------------- State Machine --------------------------------------

timeout and ping ack greater or equal to n/2+1

State1. FOLLOWER ------------------> CANDIDATE

type HARPC

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

HARPC tuple.

func (*HARPC) HADisable

func (h *HARPC) HADisable(req *model.HARPCRequest, rsp *model.HARPCResponse) error

HADisable rpc.

func (*HARPC) HAEnable

func (h *HARPC) HAEnable(req *model.HARPCRequest, rsp *model.HARPCResponse) error

HAEnable rpc.

func (*HARPC) HASetLearner added in v1.0.8

func (h *HARPC) HASetLearner(req *model.HARPCRequest, rsp *model.HARPCResponse) error

HASetLearner rpc.

func (*HARPC) HATryToLeader

func (h *HARPC) HATryToLeader(req *model.HARPCRequest, rsp *model.HARPCResponse) error

HATryToLeader rpc.

type Idle

type Idle struct {
	*Raft
	// contains filtered or unexported fields
}

Idle tuple.

func NewIdle

func NewIdle(r *Raft) *Idle

NewIdle creates new Idle.

func (*Idle) Loop

func (r *Idle) Loop()

Loop used to start the loop of the state machine. -------------------------------------- State Machine -------------------------------------- in IDLE state, we never do leader election

type Invalid added in v1.0.7

type Invalid struct {
	*Raft
	// contains filtered or unexported fields
}

Invalid tuple.

func NewInvalid added in v1.0.7

func NewInvalid(r *Raft) *Invalid

NewInvalid creates new Invalid.

func (*Invalid) Loop added in v1.0.7

func (r *Invalid) Loop()

Loop used to start the loop of the state machine. -------------------------------------- State Machine -------------------------------------- in INVALID state, we never do leader election

type Leader

type Leader struct {
	*Raft
	// contains filtered or unexported fields
}

Leader tuple.

func NewLeader

func NewLeader(r *Raft) *Leader

NewLeader creates new Leader.

func (*Leader) Loop

func (r *Leader) Loop()

Loop used to start the loop of the state machine. -------------------------------------- State Machine --------------------------------------

higher viewid

State1. LEADER ------------------> FOLLOWER

type Learner added in v1.0.8

type Learner struct {
	*Raft
	// contains filtered or unexported fields
}

Learner tuple.

func NewLearner added in v1.0.8

func NewLearner(r *Raft) *Learner

NewLearner creates new learner.

func (*Learner) Loop added in v1.0.8

func (r *Learner) Loop()

Loop used to start the loop of the state machine. -------------------------------------- State Machine -------------------------------------- in LEARNER state, we never do leader election

type Peer

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

Peer tuple.

func NewPeer

func NewPeer(raft *Raft, connectionStr string, requestTimeout int, heartbeatTimeout int) *Peer

NewPeer creates new Peer.

func (*Peer) NewClient

func (p *Peer) NewClient() (*xrpc.Client, func(), error)

NewClient creates new client.

func (*Peer) SendPing added in v1.0.7

func (p *Peer) SendPing(c chan *model.RaftRPCResponse)

follower SendPing

type Raft

type Raft struct {
	L  *Leader
	C  *Candidate
	F  *Follower
	I  *Idle
	IV *Invalid
	LN *Learner
	// contains filtered or unexported fields
}

Raft tuple.

func MockRafts

func MockRafts(log *xlog.Log, port int, count int, idleStart int) ([]string, []*Raft, func())

MockRafts mock. If no idle nodes, set idleStart to -1

func MockRaftsWithConfig

func MockRaftsWithConfig(log *xlog.Log, conf *config.RaftConfig, port int, count int, idleStart int) ([]string, []*Raft, func())

MockRaftsWithConfig mock.

func MockRaftsWithLong

func MockRaftsWithLong(log *xlog.Log, port int, count int, idleStart int) ([]string, []*Raft, func())

MockRaftsWithLong mock.

func NewRaft

func NewRaft(id string, conf *config.RaftConfig, log *xlog.Log, mysql *mysql.Mysql) *Raft

NewRaft creates the new raft.

func (*Raft) AddIdlePeer added in v1.0.9

func (r *Raft) AddIdlePeer(connStr string) error

AddIdlePeer used to add a idle peer to peers.

func (*Raft) AddPeer

func (r *Raft) AddPeer(connStr string) error

AddPeer used to add a peer to peers.

func (*Raft) DEBUG

func (r *Raft) DEBUG(format string, v ...interface{})

DEBUG level log.

func (*Raft) ERROR

func (r *Raft) ERROR(format string, v ...interface{})

ERROR level log.

func (*Raft) GetAllPeers added in v1.0.9

func (r *Raft) GetAllPeers() []string

GetAllPeers returns all peers string.

func (*Raft) GetEpochID

func (r *Raft) GetEpochID() uint64

GetEpochID returns epoch id.

func (*Raft) GetHARPC

func (s *Raft) GetHARPC() *HARPC

GetHARPC returns HARPC.

func (*Raft) GetIdlePeers added in v1.0.9

func (r *Raft) GetIdlePeers() []string

GetIdlePeers returns idle peers string.

func (*Raft) GetLeader

func (r *Raft) GetLeader() string

GetLeader returns leader.

func (*Raft) GetMembers

func (r *Raft) GetMembers() int

GetMembers returns member number.

func (*Raft) GetPeers

func (r *Raft) GetPeers() []string

GetPeers returns peers string.

func (*Raft) GetQuorums

func (r *Raft) GetQuorums() int

GetQuorums returns quorums.

func (*Raft) GetRaftRPC

func (r *Raft) GetRaftRPC() *RaftRPC

GetRaftRPC returns RaftRPC.

func (*Raft) GetState

func (r *Raft) GetState() State

GetState returns the raft state.

func (*Raft) GetVewiID

func (r *Raft) GetVewiID() uint64

GetVewiID returns view ID.

func (*Raft) INFO

func (r *Raft) INFO(format string, v ...interface{})

INFO level log.

func (*Raft) IncCandidateDegrades

func (s *Raft) IncCandidateDegrades()

IncCandidateDegrades counter.

func (*Raft) IncCandidatePromotes

func (s *Raft) IncCandidatePromotes()

IncCandidatePromotes counter.

func (*Raft) IncLeaderDegrades

func (s *Raft) IncLeaderDegrades()

IncLeaderDegrades counter.

func (*Raft) IncLeaderGetHeartbeatRequests

func (s *Raft) IncLeaderGetHeartbeatRequests()

IncLeaderGetHeartbeatRequests counter.

func (*Raft) IncLeaderGetVoteRequests

func (s *Raft) IncLeaderGetVoteRequests()

IncLeaderGetVoteRequests counter.

func (*Raft) IncLeaderPromotes

func (s *Raft) IncLeaderPromotes()

IncLeaderPromotes counter.

func (*Raft) IncLeaderPurgeBinlogFails

func (s *Raft) IncLeaderPurgeBinlogFails()

IncLeaderPurgeBinlogFails counter.

func (*Raft) IncLeaderPurgeBinlogs

func (s *Raft) IncLeaderPurgeBinlogs()

IncLeaderPurgeBinlogs counter.

func (*Raft) IncLessHeartbeatAcks

func (s *Raft) IncLessHeartbeatAcks()

IncLessHeartbeatAcks counter.

func (*Raft) PANIC

func (r *Raft) PANIC(format string, v ...interface{})

PANIC level log.

func (*Raft) RemoveIdlePeer added in v1.0.9

func (r *Raft) RemoveIdlePeer(connStr string) error

RemoveIdlePeer used to remove a idle peer from peers.

func (*Raft) RemovePeer

func (r *Raft) RemovePeer(connStr string) error

RemovePeer used to remove a peer from peers.

func (*Raft) ResetRaftMysqlStatus

func (s *Raft) ResetRaftMysqlStatus()

ResetRaftMysqlStatus used to reset mysql status.

func (*Raft) SetRaftMysqlStatus

func (s *Raft) SetRaftMysqlStatus(rms model.RAFTMYSQL_STATUS)

SetRaftMysqlStatus used to set mysql status.

func (*Raft) SetSkipCheckSemiSync added in v1.0.9

func (r *Raft) SetSkipCheckSemiSync(v bool)

SetSkipCheckSemiSync used to set check semi-sync or not.

func (*Raft) SetSkipPurgeBinlog

func (r *Raft) SetSkipPurgeBinlog(v bool)

SetSkipPurgeBinlog used to set purge binlog or not.

func (*Raft) Start

func (r *Raft) Start() error

Start used to start the raft.

func (*Raft) Stop

func (r *Raft) Stop() error

Stop used to stop the raft.

func (*Raft) WARNING

func (r *Raft) WARNING(format string, v ...interface{})

WARNING level log.

type RaftMeta

type RaftMeta struct {
	ViewID  uint64
	EpochID uint64

	// The Peers(endpoint) expect SuperIDLE
	Peers []string

	// The SuperIDLE Peers(endpoint)
	IdlePeers []string
}

RaftMeta tuple.

type RaftRPC

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

RaftRPC tuple.

func (*RaftRPC) DisableCheckSemiSync added in v1.0.9

func (r *RaftRPC) DisableCheckSemiSync(req *model.RaftStatusRPCRequest, rsp *model.RaftStatusRPCResponse) error

DisableCheckSemiSync rpc.

func (*RaftRPC) DisablePurgeBinlog

func (r *RaftRPC) DisablePurgeBinlog(req *model.RaftStatusRPCRequest, rsp *model.RaftStatusRPCResponse) error

DisablePurgeBinlog rpc.

func (*RaftRPC) EnableCheckSemiSync added in v1.0.9

func (r *RaftRPC) EnableCheckSemiSync(req *model.RaftStatusRPCRequest, rsp *model.RaftStatusRPCResponse) error

EnableCheckSemiSync rpc.

func (*RaftRPC) EnablePurgeBinlog

func (r *RaftRPC) EnablePurgeBinlog(req *model.RaftStatusRPCRequest, rsp *model.RaftStatusRPCResponse) error

EnablePurgeBinlog rpc.

func (*RaftRPC) Heartbeat

func (r *RaftRPC) Heartbeat(req *model.RaftRPCRequest, rsp *model.RaftRPCResponse) error

Heartbeat rpc.

func (*RaftRPC) Ping added in v1.0.7

func (r *RaftRPC) Ping(req *model.RaftRPCRequest, rsp *model.RaftRPCResponse) error

Ping rpc. send MsgRaftPing

func (*RaftRPC) RequestVote

func (r *RaftRPC) RequestVote(req *model.RaftRPCRequest, rsp *model.RaftRPCResponse) error

RequestVote rpc.

func (*RaftRPC) Status

Status rpc.

type State

type State int

State enum.

const (
	// FOLLOWER state.
	FOLLOWER State = 1 << iota

	// CANDIDATE state.
	CANDIDATE

	// LEADER state.
	LEADER

	// IDLE state.
	// neither process heartbeat nor voterequest(return ErrorInvalidRequest)
	IDLE

	// INVALID state.
	// neither process heartbeat nor voterequest(return ErrorInvalidRequest)
	INVALID

	// LEARNER state.
	LEARNER

	// STOPPED state.
	STOPPED
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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