raft

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

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotALeader = errors.New("not a leader")

ErrorNotALeader error returned where no server leader

Functions

This section is empty.

Types

type Args

type Args struct {
	IsTestMode   bool
	Logger       *logrus.Logger
	PstLog       wal.Wal
	RPCServer    rpc.Server
	Server       *pb.Peer
	EventHandler *events.Events
	StorageMgr   store.Manager
}

Args argument structure for Raft Instance

type CommitEntry

type CommitEntry struct {
	// Command is the client command being committed.
	Command interface{}
	// Index is the log index at which the client command is committed.
	Index int64
	// Term is the Raft term at which the client command is committed.
	Term int64
}

CommitEntry is the data reported by Raft to the commit channel. Each commit entry notifies the client that consensus was reached on a command and it can be applied to the client's state machine.

type Raft

type Raft interface {
	Peers() map[string]*pb.Peer
	AddPeer(peer *pb.Peer)
	State() State
	RequestVotes(ctx context.Context, request *pb.VoteRequest) (*pb.VoteReply, error)
	RemovePeer(*pb.RemovePeerRequest) error
	Start()
	Stop()
	AppendEntries(ctx context.Context, request *pb.AppendEntryRequest) (*pb.AppendEntryReply, error)
	Log() []*pb.WalEntry
	SubmitAndWait(interface{}, string, pb.CommandType) error
	AddCommandListener(string) error
	WaitForCommandCompletion(string) error

	Server() *pb.Peer
	StorageManager() store.Manager

	IsTestMode() bool
	EventHandler() *events.Events

	//IsRunning for tests
	IsRunning() bool
}

Raft raft interface

func NewRaft

func NewRaft(args *Args) (Raft, error)

NewRaft creates new instance of Raft

type State

type State int

State of the raft instance

const (
	//Follower indicate follower state
	Follower State = iota
	//Candidate indicate candidate state
	Candidate
	//Leader indicate leader state
	Leader
	//Dead indicate dead state
	Dead
)

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