raft

package
v0.0.0-...-13d8ce4 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdvanceTicks

func AdvanceTicks(n etcdraft.Node, electionTicks int)

AdvanceTicks advances ticks of Raft node. This can be used for fast-forwarding election ticks in multi data-center deployments, thus speeding up election process.

func MustGetAppliedIndex

func MustGetAppliedIndex(s storage.Storage) uint64

MustGetAppliedIndex get the applied raft index, if occur error, fatal

Types

type ApplyEntry

type ApplyEntry struct {
	Entries  []raftpb.Entry
	Snapshot raftpb.Snapshot
	// Notifyc synchronizes etcd server applies with the raft node
	Notifyc chan struct{}
}

ApplyEntry contains entries, Snapshot to be applied. Once an ApplyEntry is consumed, the entries will be persisted to to raft storage concurrently; the application must read raftDone before assuming the raft messages are stable.

type Node

type Node struct {
	NodeConfig
	// contains filtered or unexported fields
}

Node represents a raft node

func NewNode

func NewNode(cfg NodeConfig) *Node

NewNode create a raft node

func (*Node) Apply

func (r *Node) Apply() chan ApplyEntry

Apply return the apply channel

func (*Node) DoneC

func (r *Node) DoneC() chan struct{}

DoneC return the done channel

func (*Node) GetAppliedIndex

func (r *Node) GetAppliedIndex() uint64

GetAppliedIndex get the applied raft index

func (*Node) GetCommittedIndex

func (r *Node) GetCommittedIndex() uint64

GetCommittedIndex get the committed raft index

func (*Node) GetTerm

func (r *Node) GetTerm() uint64

GetTerm get the raft term

func (*Node) MsgSnapC

func (r *Node) MsgSnapC() chan raftpb.Message

MsgSnapC return snapshot channel

func (*Node) NewPeerListener

func (r *Node) NewPeerListener(peerURLs types.URLs) (err error)

NewPeerListener create listener of peer

func (*Node) PeerHandlerServe

func (r *Node) PeerHandlerServe()

PeerHandlerServe serve

func (*Node) Run

func (r *Node) Run(rh *ReadyHandler)

Run must keep run as fast as possible If execution is too slow, ticker will suffer, then tickHeartbeat(tickElection) will be influenced

func (*Node) SetAppliedIndex

func (r *Node) SetAppliedIndex(v uint64)

SetAppliedIndex set the applied raft index, not used

func (*Node) SetCommittedIndex

func (r *Node) SetCommittedIndex(v uint64)

SetCommittedIndex set the committed raft index

func (*Node) SetPeerHandler

func (r *Node) SetPeerHandler()

SetPeerHandler set the handler of raft transport

func (*Node) SetTerm

func (r *Node) SetTerm(v uint64)

SetTerm set the raft term

func (*Node) Stop

func (r *Node) Stop()

Stop implements stop raft node

func (*Node) StopPeerListener

func (r *Node) StopPeerListener() error

StopPeerListener stop the listener of peer

type NodeConfig

type NodeConfig struct {
	// to check if msg receiver is removed from cluster
	IsIDRemoved func(id uint64) bool
	etcdraft.Node
	//raftStorage *raft.MemoryStorage
	//storage     Storage
	//store raft log
	Storage storage.Storage
	//MetadataStorage MetadataStorage
	Heartbeat time.Duration // for logging
	// Transport specifies the Transport to send and receive msgs to members.
	// Sending messages MUST NOT block. It is okay to drop messages, since
	// clients should timeout and reissue their messages.
	// If Transport is nil, server will panic.
	Transport rafthttp.Transporter

	PeerListener []*peerListener
}

NodeConfig is the config of raft node

type ReadyHandler

type ReadyHandler struct {
	GetLead              func() (lead uint64)
	UpdateLead           func(lead uint64)
	UpdateLeadership     func(leadChange bool)
	UpdateCommittedIndex func(uint64)
}

ReadyHandler contains a set of EtcdServer operations to be called by Node, and helps decouple state machine logic from Raft algorithms. TODO: add a state machine interface to ApplyEntry the commit entries and do Snapshot/recover

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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