raft

package
v0.0.0-...-dd8e2c6 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PrefixHeartbeat      = "[HEARTBEAT] "
	PrefixStateChanged   = "[STATE CHANGED] "
	PrefixTermChanged    = "[TERM CHANGED] "
	PrefixElection       = "[ELECTION] "
	PrefixElectionResult = "[ELECTION RESULT] "
	PrefixElectionStop   = "[ELECTION STOPPED] "
	PrefixInfo           = "[INFO] "
	PrefixError          = "[ERROR] "
	PrefixAppendEntries  = "[APPEND ENTRIES] "
	PrefixRequestVote    = "[REQUEST VOTE] "
)
View Source
const (
	Follower = S(iota)
	Candidate
	Leader
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexedEntry

type IndexedEntry struct {
	Index int32
	*schema.Entry
}

type Indexes

type Indexes struct {
	sync.Map
	sync.Mutex
}

func NewIndexesMap

func NewIndexesMap(clients []rpc.Client, log *Log) *Indexes

func (*Indexes) DecrementIndex

func (ni *Indexes) DecrementIndex(clientId int32) bool

func (*Indexes) Reset

func (ni *Indexes) Reset(clients []rpc.Client, log *Log)

func (*Indexes) SetIndex

func (ni *Indexes) SetIndex(clientId int32, i int32)

type Log

type Log struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewLog

func NewLog() *Log

func (*Log) AppendEntries

func (l *Log) AppendEntries(entries []*schema.Entry)

func (*Log) EntryByIndex

func (l *Log) EntryByIndex(i int32) *IndexedEntry

func (*Log) EntryByIndexDecomposed

func (l *Log) EntryByIndexDecomposed(i int32) (int32, int32)

func (*Log) GetCommitIndex

func (l *Log) GetCommitIndex() int32

func (*Log) GetEntriesFrom

func (l *Log) GetEntriesFrom(i int32) []*schema.Entry

func (*Log) GetLastApplied

func (l *Log) GetLastApplied() int32

func (*Log) IsCandidatesLogAtLeastAsUpToDateAsCurrent

func (l *Log) IsCandidatesLogAtLeastAsUpToDateAsCurrent(lastLogTerm, lastLogIndex int32) bool

func (*Log) IsEmpty

func (l *Log) IsEmpty() bool

func (*Log) LastEntry

func (l *Log) LastEntry() *IndexedEntry

func (*Log) LastEntryDecomposed

func (l *Log) LastEntryDecomposed() (int32, int32)

func (*Log) Len

func (l *Log) Len() int32

func (*Log) SaveNewEntries

func (l *Log) SaveNewEntries(in schema.AppendEntriesInput)

func (*Log) SetCommitIndex

func (l *Log) SetCommitIndex(i int32)

type Logger

type Logger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger() *Logger

func (*Logger) Log

func (logger *Logger) Log(prefix string, v ...interface{})

type Raft

type Raft interface {
	Start(ctx context.Context)
	Stop()
	Stats() map[string]string
	GetState() *State
}

func New

func New(config env.Node, nodesAddresses []env.Node, clusterSize int) Raft

type S

type S int32

func (S) String

func (s S) String() string

type State

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

func NewState

func NewState() *State

func (*State) GetState

func (s *State) GetState() S

func (*State) GetTerm

func (s *State) GetTerm() int32

func (*State) GetVote

func (s *State) GetVote() int32

func (*State) IncrementTerm

func (s *State) IncrementTerm()

func (*State) SetState

func (s *State) SetState(newState S)

func (*State) SetTerm

func (s *State) SetTerm(new int32)

func (*State) SetVote

func (s *State) SetVote(candidateId int32)

func (*State) VotedInThisTerm

func (s *State) VotedInThisTerm() bool

Jump to

Keyboard shortcuts

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