simple_raft

package module
v0.0.0-...-432e5a8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 13 Imported by: 0

README

TinyRaftKV

A simple raft implement

Documentation

Index

Constants

View Source
const (
	AppendEntriesInterval = 50 * time.Millisecond
	HeartBeatInterval     = 50 * time.Millisecond
	ChanSize              = 1000
)
View Source
const Debug = 1

Debugging

Variables

This section is empty.

Functions

func DPrintf

func DPrintf(format string, a ...interface{}) (n int, err error)

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

Types

type AppendEntriesArgs

type AppendEntriesArgs struct {
	Term     int
	LeaderId int

	PrevLogIndex int
	PrevLogTerm  int

	Entries []LogEntry

	LeaderCommit int
}

AppendEntries RPC

type AppendEntriesReply

type AppendEntriesReply struct {
	Term      int
	Success   bool
	NextIndex int
}

type ApplyMsg

type ApplyMsg struct {
	Index       int
	Command     interface{}
	UseSnapshot bool
	Snapshot    []byte
}

func (*ApplyMsg) String

func (msg *ApplyMsg) String() string

type InstallSnapshotArgs

type InstallSnapshotArgs struct {
	Term             int
	LeaderId         int
	LastIncludeIndex int
	LastIncludeTerm  int
	Data             []byte
}

InstallSnapShot RPC

type InstallSnapshotReply

type InstallSnapshotReply struct {
	Term int
}

type LogEntry

type LogEntry struct {
	LogIndex   int
	LogTerm    int
	LogCommand interface{}
}

type Persister

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

func MakePersister

func MakePersister() *Persister

func (*Persister) Copy

func (ps *Persister) Copy() *Persister

func (*Persister) RaftStateSize

func (ps *Persister) RaftStateSize() int

func (*Persister) ReadRaftState

func (ps *Persister) ReadRaftState() []byte

func (*Persister) ReadSnapshot

func (ps *Persister) ReadSnapshot() []byte

func (*Persister) SaveRaftState

func (ps *Persister) SaveRaftState(state []byte)

func (*Persister) SaveSnapshot

func (ps *Persister) SaveSnapshot(snapshot []byte)

func (*Persister) SaveStateAndSnapshot

func (ps *Persister) SaveStateAndSnapshot(state []byte, snapshot []byte)

Save both Raft state and K/V snapshot as a single atomic action, to help avoid them getting out of sync.

func (*Persister) SnapshotSize

func (ps *Persister) SnapshotSize() int

type Raft

type Raft struct {

	// all
	CommitIndex int
	LastApplied int
	// contains filtered or unexported fields
}

func Make

func Make(peers []*labrpc.ClientEnd, me int,
	persister *Persister, applyCh chan ApplyMsg) *Raft

func (*Raft) AppendEntries

func (rf *Raft) AppendEntries(args AppendEntriesArgs, reply *AppendEntriesReply)

func (*Raft) Commit

func (rf *Raft) Commit()

func (*Raft) FSM

func (rf *Raft) FSM()

func (*Raft) GetPerisistSize

func (rf *Raft) GetPerisistSize() int

func (*Raft) GetState

func (rf *Raft) GetState() (int, bool)

func (*Raft) InstallSnapshot

func (rf *Raft) InstallSnapshot(args InstallSnapshotArgs, reply *InstallSnapshotReply)

func (*Raft) Kill

func (rf *Raft) Kill()

func (*Raft) RequestVote

func (rf *Raft) RequestVote(args RequestVoteArgs, reply *RequestVoteReply)

func (*Raft) Start

func (rf *Raft) Start(command interface{}) (int, int, bool)

func (*Raft) StartSnapshot

func (rf *Raft) StartSnapshot(snapshot []byte, index int)

type RequestVoteArgs

type RequestVoteArgs struct {
	Term         int
	CandidateId  int
	LastLogTerm  int
	LastLogIndex int
}

RequestVote RPC

type RequestVoteReply

type RequestVoteReply struct {
	Term        int
	VoteGranted bool
}

type State

type State uint32
const (
	Leader State = iota
	Candidate
	Follower
)

Jump to

Keyboard shortcuts

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