Documentation ¶
Index ¶
- Constants
- func DPrintf(format string, a ...interface{}) (n int, err error)
- type AppendEntriesArgs
- type AppendEntriesReply
- type ApplyMsg
- type Entry
- type InstallSnapshotArgs
- type InstallSnapshotReply
- type PersistentState
- 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 *AppendEntriesArgs, reply *AppendEntriesReply)
- func (rf *Raft) GetState() (int, bool)
- func (rf *Raft) InstallSnapshot(args *InstallSnapshotArgs, reply *InstallSnapshotReply)
- func (rf *Raft) Kill()
- func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply)
- func (rf *Raft) Start(command interface{}) (int, int, bool)
- type RequestVoteArgs
- type RequestVoteReply
Constants ¶
const ( FOLLOWER = "FOLLOWER" CANDIDATE = "CANDIDATE" LEADER = "LEADER" )
const Debug = 1
Debugging
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppendEntriesArgs ¶
type AppendEntriesArgs struct { Term int // Leader's Term LeaderId int // Needed so follower can redirect clients Entries []Entry // Log entries to store, empty if heartbeat PrevLogIndex int // Index of the log Entry immediately preceding new ones PrevLogTerm int // Term of the prevLogIndex Entry LeaderCommit int // Leader's CommitIndex }
type AppendEntriesReply ¶
type AppendEntriesReply struct { Success bool // True if follower contained entry matching log index and term Term int // The current term for the leader to update itself ConflictIndex int // The conflicting entry's index in the peer's log to send back to the leader. If no conflicting index is present, send back the len(log) ConflictTerm int // The term of the conflicting entry }
type Entry ¶
type Entry struct { Term int // The leader's term that requested this Entry to be replicated Command interface{} // The client command to apply to the peer's state machine }
type InstallSnapshotArgs ¶
type InstallSnapshotArgs struct { Term int // Leader's term LeaderId int // So the follower can redirect clients LastIncludedIndex int // The snapshot replaces all entries up through and including this index LastIncludedTerm int // Term of LastIncludedIndex Offset int64 // Byte offset where the chunk is positioned in the snapshot file Data []int64 // Raw bytes of the snapshot chunk, starting at offset Done bool // True if this is the last chunk }
Invoked by the leader to send chunks of a snapshot to a follower. Leaders always send chunks in order.
type InstallSnapshotReply ¶
type InstallSnapshotReply struct {
Term int // Current term for the leader to update itself
}
type PersistentState ¶
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 *AppendEntriesArgs, reply *AppendEntriesReply)
func (*Raft) InstallSnapshot ¶
func (rf *Raft) InstallSnapshot(args *InstallSnapshotArgs, reply *InstallSnapshotReply)
func (*Raft) RequestVote ¶
func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply)
*
- RequestVote is a candidate's attempt to request votes from peers
- For a peer to give a candidate their vote
- A candidate's term must be >= this peer's term and the peer cannot have voted on someone else already *
- @param args
- @param reply
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.