Documentation
¶
Index ¶
- Constants
- func DPrintf(format string, a ...interface{}) (n int, err error)
- func GetRandomElectionTimeout() time.Duration
- type AppendEntriesReply
- type AppendEntriesRequest
- type ApplyMsg
- type LogEntry
- type Persister
- func (ps *Persister) Copy() *Persister
- func (ps *Persister) RaftStateSize() int
- func (ps *Persister) ReadRaftState() []byte
- func (ps *Persister) ReadSnapshot() []byte
- func (ps *Persister) SaveRaftState(state []byte)
- func (ps *Persister) SaveStateAndSnapshot(state []byte, snapshot []byte)
- func (ps *Persister) SnapshotSize() int
- type Raft
- func (rf *Raft) AppendEntries(args *AppendEntriesRequest, reply *AppendEntriesReply)
- func (rf *Raft) GetState() (int, bool)
- func (rf *Raft) Kill()
- func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply)
- func (rf *Raft) Start(command interface{}) (int, int, bool)
- func (rf *Raft) StartElection()
- type RequestVoteArgs
- type RequestVoteReply
- type State
Constants ¶
const ( None = -1 ElectionTimeout = 100 )
const Debug = 0
Debugging
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppendEntriesReply ¶
type AppendEntriesReply struct {
// contains filtered or unexported fields
}
type AppendEntriesRequest ¶
type AppendEntriesRequest struct {
// contains filtered or unexported fields
}
type ApplyMsg ¶
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(). set CommandValid to true to indicate that the ApplyMsg contains a newly committed log entry.
in Lab 3 you'll want to send other kinds of messages (e.g., snapshots) on the applyCh; at that point you can add fields to ApplyMsg, but set CommandValid to false for these other uses.
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) SaveStateAndSnapshot ¶
Save both Raft state and K/V snapshot as a single atomic action, to help avoid them getting out of sync.
func (*Persister) SnapshotSize ¶
type Raft ¶
type Raft struct {
// contains filtered or unexported fields
}
func (*Raft) AppendEntries ¶
func (rf *Raft) AppendEntries(args *AppendEntriesRequest, reply *AppendEntriesReply)
func (*Raft) Kill ¶
func (rf *Raft) Kill()
the tester doesn't halt goroutines created by Raft after each test, but it does call the Kill() method. your code can use killed() to check whether Kill() has been called. the use of atomic avoids the need for a lock.
the issue is that long-running goroutines use memory and may chew up CPU time, perhaps causing later tests to fail and generating confusing debug output. any goroutine with a long-running loop should call killed() to check whether it should stop.
func (*Raft) RequestVote ¶
func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply)
example RequestVote RPC handler.
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. even if the Raft instance has been killed, this function should return gracefully.
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.
func (*Raft) StartElection ¶
func (rf *Raft) StartElection()
type RequestVoteArgs ¶
type RequestVoteArgs struct {
// contains filtered or unexported fields
}
example RequestVote RPC arguments structure. field names must start with capital letters!
type RequestVoteReply ¶
type RequestVoteReply struct {
// contains filtered or unexported fields
}
example RequestVote RPC reply structure. field names must start with capital letters!