raft

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2018 License: GPL-3.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

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

	// MsgRaftHeartbeat type.
	MsgRaftHeartbeat

	// MsgRaftRequestVote type.
	MsgRaftRequestVote
)

Variables

This section is empty.

Functions

func MockGetClient

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

MockGetClient mock.

func MockSetReplHandler

func MockSetReplHandler(raft *Raft, h mysql.ReplHandler)

MockSetReplHandler 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 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

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) 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 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 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.

type Raft

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

Raft tuple.

func MockRafts

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

MockRafts mock.

func MockRaftsWithConfig

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

MockRaftsWithConfig mock.

func MockRaftsWithLong

func MockRaftsWithLong(log *xlog.Log, port int, count 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) 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) GetEpochID

func (r *Raft) GetEpochID() uint64

GetEpochID returns epoch id.

func (*Raft) GetHARPC

func (s *Raft) GetHARPC() *HARPC

GetHARPC returns HARPC.

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) 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) 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
	Peers   []string
}

RaftMeta tuple.

type RaftRPC

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

RaftRPC tuple.

func (*RaftRPC) DisablePurgeBinlog

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

DisablePurgeBinlog 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) 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

	// 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