Documentation
¶
Index ¶
- Constants
- func DPrintf(format string, a ...interface{}) (n int, err error)
- type AppendEntryArgs
- type AppendEntryReply
- type ApplyMsg
- type LogEntry
- type Persister
- type Raft
- func (rf *Raft) AppendEntries(args AppendEntryArgs, reply *AppendEntryReply)
- func (rf *Raft) GetState() (int, bool)
- func (rf *Raft) Kill()
- func (rf *Raft) RequestVote(args RequestVoteArgs, reply *RequestVoteReply)
- func (rf *Raft) SendAppendEntriesToAllFollwer()
- func (rf *Raft) SendAppendEntryToFollower(server int, args AppendEntryArgs, reply *AppendEntryReply) bool
- func (rf *Raft) Start(command interface{}) (int, int, bool)
- type RequestVoteArgs
- type RequestVoteReply
Constants ¶
const ( STOPPED = "stopped" INITIALIZED = "initialized" FOLLOWER = "follower" CANDIDATE = "candidate" LEADER = "leader" SNAPSHOTTING = "snapshotting" )
const ( HeartbeatCycle = time.Millisecond * 50 ElectionMinTime = 150 ElectionMaxTime = 300 )
const Debug = 0
Debugging
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppendEntryArgs ¶
type AppendEntryArgs struct {
Term int
Leader_id int
PrevLogIndex int
PrevLogTerm int
Entries []LogEntry
LeaderCommit int
}
example AppendEntry RPC arguments structure.
type AppendEntryReply ¶
example AppendEntry RPC reply structure.
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
}
as each Raft peer becomes aware that successive log entries are committed, the peer should send an ApplyMsg to the service (or tester) on the same server, via the applyCh passed to Make().
type LogEntry ¶
type LogEntry struct {
Command interface{}
Term int
}
log entry contains command for state machine, and term when entry was received by leader
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 Raft ¶
type Raft struct {
// contains filtered or unexported fields
}
A Go object implementing a single Raft peer.
func Make ¶
the service or tester wants to create a Raft server. the ports of all the Raft servers (including this one) are in peers[]. this server's port is peers[me]. all the servers' peers[] arrays have the same order. persister is a place for this server to save its persistent state, and also initially holds the most recent saved state, if any. applyCh is a channel on which the tester or service expects Raft to send ApplyMsg messages. Make() must return quickly, so it should start goroutines for any long-running work.
func (*Raft) AppendEntries ¶
func (rf *Raft) AppendEntries(args AppendEntryArgs, reply *AppendEntryReply)
append entries
func (*Raft) Kill ¶
func (rf *Raft) Kill()
the tester calls Kill() when a Raft instance won't be needed again. you are not required to do anything in Kill(), but it might be convenient to (for example) turn off debug output from this instance.
func (*Raft) RequestVote ¶
func (rf *Raft) RequestVote(args RequestVoteArgs, reply *RequestVoteReply)
example RequestVote RPC handler.
func (*Raft) SendAppendEntriesToAllFollwer ¶
func (rf *Raft) SendAppendEntriesToAllFollwer()
send appendetries to all follwer
func (*Raft) SendAppendEntryToFollower ¶
func (rf *Raft) SendAppendEntryToFollower(server int, args AppendEntryArgs, reply *AppendEntryReply) bool
send appendetries to a follower
func (*Raft) Start ¶
the service using Raft (e.g. a k/v server) wants to start agreement on the next command to be appended to Raft's log. if this server isn't the leader, returns false. otherwise start the agreement and return immediately. there is no guarantee that this command will ever be committed to the Raft log, since the leader may fail or lose an election.
the first return value is the index that the command will appear at if it's ever committed. the second return value is the current term. the third return value is true if this server believes it is the leader.
type RequestVoteArgs ¶
type RequestVoteArgs struct {
// Your data here.
Term int // candidate's term
CandidateId int // candidate requesting vote
LastLogIndex int // index of candidate's last log entry
LastLogTerm int // term of candidate's last log entry
}
example RequestVote RPC arguments structure.
type RequestVoteReply ¶
type RequestVoteReply struct {
// Your data here.
Term int // currentTerm, for candidate to update itself
VoteGranted bool // true means candidate received vote
}
example RequestVote RPC reply structure.