raft

package module
v0.0.0-...-a027528 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 15 Imported by: 0

README

raft

Raft consensus algorithm implementation

Documentation

Index

Constants

View Source
const (
	Follower  = "Follower"
	Candidate = "Candidate"
	Leader    = "Leader"
)

Variables

View Source
var (
	CurrentNode  *Node
	NodeDetail   = fmt.Sprintf("%s/.config/node-detail.json", os.Getenv("HOME"))
	EntryLogFile = fmt.Sprintf("%s/.config/entry_logs.json", os.Getenv("HOME"))
)
View Source
var (
	FileDir  = ".data"
	FilePath = ""
)

Functions

func GetBufferSize

func GetBufferSize() int

func GetFileSize

func GetFileSize(fileName string) (int64, error)

func ReadEntryLog

func ReadEntryLog(entries []Entry) error

func WriteEntryLog

func WriteEntryLog(entry Entry) error

Types

type AppendLog

type AppendLog struct {
	SrvNode   *Node
	LastEntry *Entry
}

func NewAppendLog

func NewAppendLog(node *Node) *AppendLog

func (*AppendLog) AddEntryToNode

func (a *AppendLog) AddEntryToNode(req *pb.AppendEntryRequestDetail)

func (*AppendLog) AppendEntryLog

func (a *AppendLog) AppendEntryLog(req *pb.AppendEntryRequestDetail) (*pb.AppendEntryResponse, error)

func (*AppendLog) SendAppendEntryLog

func (a *AppendLog) SendAppendEntryLog()

func (*AppendLog) SendHeartBeat

func (a *AppendLog) SendHeartBeat()

type AppendRequestMsg

type AppendRequestMsg struct{}

func (*AppendRequestMsg) Send

type DiskStore

type DiskStore struct {
	StoreDir string
	FileName string
}

func NewDiskStore

func NewDiskStore(fileName string) *DiskStore

func (*DiskStore) CreateFile

func (d *DiskStore) CreateFile(perm fs.FileMode, flag int) (*os.File, error)

func (*DiskStore) ReadFile

func (d *DiskStore) ReadFile(buf []byte, file *os.File) (int, error)

func (*DiskStore) WriteFile

func (d *DiskStore) WriteFile(buf []byte, file *os.File) error

type Entry

type Entry struct {
	Id      int    /* Entry index. Increases monotonically */
	Term    int64  /*  Term when entry was received */
	Command []byte /* Command value from client */
}

func NewEntry

func NewEntry(id int, term int64, command []byte) *Entry

type Exponential

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

func NewExponentialInterval

func NewExponentialInterval(optMin, optMax, mult float64) *Exponential

func (*Exponential) Next

func (e *Exponential) Next() time.Duration

type Message

type Message interface {
	Send()
}

type Node

type Node struct {
	CurrentTerm int64    `json:"current_term,omitempty"` /* Store the term we're in atm */
	VotedFor    string   `json:"voted_for,omitempty"`    /* CandidateId that received vote */
	State       string   `json:"state,omitempty"`        /* Current state of the node */
	Name        string   `json:"name,omitempty"`         /* Node name */
	CommitIndex int      `json:"commit_index,omitempty"` /* Index of highest log entry known to be committed */
	LastApplied int      `json:"last_applied,omitempty"` /* Index of highest log entry applied to state machine */
	Nodes       []string `json:"nodes,omitempty"`        /* Nodes in cluster */
	LogEntry    []Entry  `json:"log_entry,omitempty"`    /* Command Entries */
	// contains filtered or unexported fields
}

func NewNode

func NewNode(serverName string, clusterNodes []string) *Node

func NodeFromDisk

func NodeFromDisk() *Node

func (*Node) PersistToDisk

func (n *Node) PersistToDisk(perm fs.FileMode, flag int) error

func (*Node) ReadNodeFromFile

func (n *Node) ReadNodeFromFile(buf []byte, flag int) *Node

func (*Node) RefreshFromDisk

func (n *Node) RefreshFromDisk() *Node

func (*Node) SendRequestVote

func (n *Node) SendRequestVote()

func (*Node) String

func (n *Node) String() string

func (*Node) TruncNodeFile

func (n *Node) TruncNodeFile(size int64)

func (*Node) VoteForClient

func (n *Node) VoteForClient(client_name string, term int64, lastLogIdx int64, lastLogTerm int64) (int64, bool)

type RequestVoteMsg

type RequestVoteMsg struct{}

func (*RequestVoteMsg) Send

func (r *RequestVoteMsg) Send(server_name string, term int64, cId string, lastLogIdx int64, lastLogTerm int64) *pb.RequestVoteResponse

type Store

type Store interface {
	CreateFile(perm fs.FileMode, flag int)
	ReadFile(buf []byte, file *os.File)
	WriteFile()
}

Directories

Path Synopsis
grpc
protos

Jump to

Keyboard shortcuts

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