Documentation ¶
Overview ¶
raft-impl: An implementation of the Raft consensus algorithm Copyright (C) 2020 Yicheng Huang. All rights reserved.
A course assignment for Distributed System, Fall 2020, CS@NJU.
raft.go The core Raft implementation
Index ¶
Constants ¶
const ( /*RaftElectionTimeoutMin is the minimum timeout of leader election*/ RaftElectionTimeoutMin = 400 * time.Millisecond /*RaftHeartBeatLoop is the time period of sending heart beat*/ RaftHeartBeatLoop = 100 * time.Millisecond )
const DEBUG = 0
DEBUG for debug/run mode switch.
const Debug = 0
Debugging
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppendEntriesArgs ¶
type AppendEntriesArgs struct { Term int LeaderID int PrevLogIndex int PrevLogTerm int Entries []LogEntry LeaderCommit int }
AppendEntriesArgs is the structure of AppendEntries RPC arguments
type AppendEntriesReply ¶
AppendEntriesReply is the structure of AppendEntries RPC reply
type ApplyMsg ¶
type ApplyMsg struct { Index int Command interface{} UseSnapshot bool // ignore for lab2; only used in lab3 Snapshot []byte // ignore for lab2; only used in lab3 }
ApplyMsg is the structure of apply message to state machine
type LogEntry ¶
type LogEntry struct { Term int Value interface{} }
LogEntry is the structure of each log entry, composed by its term and value
type Persister ¶
type Persister struct {
// contains filtered or unexported fields
}
func MakePersister ¶
func MakePersister() *Persister
func (*Persister) RaftStateSize ¶
func (*Persister) ReadRaftState ¶
func (*Persister) ReadSnapshot ¶
func (*Persister) SaveRaftState ¶
func (*Persister) SaveSnapshot ¶
type RLogger ¶
type RLogger struct {
// contains filtered or unexported fields
}
RLogger is the structure of logger used by Raft, for convenience of debugging
type RMutex ¶
type RMutex struct {
// contains filtered or unexported fields
}
RMutex is the structure of mutex lock used by Raft, for convenience of debugging
type Raft ¶
type Raft struct {
// contains filtered or unexported fields
}
Raft is the core structure of each server making consensus with RAFT
func (*Raft) AppendEntries ¶
func (rf *Raft) AppendEntries(args AppendEntriesArgs, reply *AppendEntriesReply)
AppendEntries is the handler of AppendEntries RPC
func (*Raft) GetState ¶
GetState returns currentTerm and whether this server believes it is the leader
func (*Raft) Kill ¶
func (rf *Raft) Kill()
Kill is used by tester to shutdown a Raft instance. Graceful shutdown is implemented.
func (*Raft) RequestVote ¶
func (rf *Raft) RequestVote(args RequestVoteArgs, reply *RequestVoteReply)
RequestVote is the handler of RequestVote RPC
type RequestVoteArgs ¶
RequestVoteArgs is the structure of RequestVote RPC arguments
type RequestVoteReply ¶
RequestVoteReply is the structure of RequestVote RPC reply