Documentation ¶
Index ¶
- Constants
- func DPrintf(format string, a ...interface{}) (n int, err error)
- func Drawing()
- func InitLogEvent()
- func LogConnect(id int)
- func LogDisconnect(id int)
- func LogEvent(name string, content string)
- func LogRPC(sender int, receiver int, kind string, args interface{}, reply interface{})
- func LogRoleChange(id int, before, after string)
- func LogRunnerStart(id int)
- func LogRunnerStop(id int)
- func LogSystemStart()
- func MapToString(m interface{}) string
- func RandomInt(min, max int) int
- func StructToString(originStruct interface{}) string
- func Writer()
- type AppendEntriesArgs
- type AppendEntriesReply
- type ApplyMsg
- type Call
- type CallingBody
- type Entry
- type Event
- type KeyValue
- 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 RPC
- type Raft
- func (rf *Raft) AppendEntries(args *AppendEntriesArgs, reply *AppendEntriesReply)
- func (rf *Raft) ConvertToCandidate()
- func (rf *Raft) ConvertToFollower()
- func (rf *Raft) ConvertToLeader()
- func (rf *Raft) GetState() (int, bool)
- func (rf *Raft) Kill()
- func (rf *Raft) LeaderAppendEntries()
- func (rf *Raft) Lock()
- func (rf *Raft) Loop()
- func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply)
- func (rf *Raft) SendHeartBeat()
- func (rf *Raft) Start(command interface{}) (int, int, bool)
- func (rf *Raft) StartElection()
- func (rf *Raft) String() string
- func (rf *Raft) Unlock()
- type RequestVoteArgs
- type RequestVoteReply
- type RoleChange
- type Runner
Constants ¶
const ( RoleLeader = "leader" RoleFollower = "follower" RoleCandidate = "candidate" OutFile = "event.log" RPCKindHeartbeat = "heart-beat" RPCKindRequestVote = "request-vote" )
const Debug = 0
Debugging
Variables ¶
This section is empty.
Functions ¶
func InitLogEvent ¶
func InitLogEvent()
func LogConnect ¶
func LogConnect(id int)
func LogDisconnect ¶
func LogDisconnect(id int)
func LogRoleChange ¶
func LogRunnerStart ¶
func LogRunnerStart(id int)
func LogRunnerStop ¶
func LogRunnerStop(id int)
func LogSystemStart ¶
func LogSystemStart()
func MapToString ¶
func MapToString(m interface{}) string
func StructToString ¶
func StructToString(originStruct interface{}) string
Types ¶
type AppendEntriesArgs ¶
type AppendEntriesArgs struct { Term int LeaderID int PrevLogIndex int PrevLogTerm int Entries []Entry LeaderCommit int }
func (*AppendEntriesArgs) String ¶
func (arg *AppendEntriesArgs) String() string
type AppendEntriesReply ¶
func (*AppendEntriesReply) String ¶
func (arg *AppendEntriesReply) String() string
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 CallingBody ¶
type CallingBody struct { }
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 { CurrentTerm int VotedFor int Log []Entry CommitIndex int LastApplied int NextIndex []int MatchIndex []int Role string // leader, follower, candidate ElectionTimeout time.Duration VoteCount int Voters []int ValidRpcReceived bool ApplyCH chan ApplyMsg // 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 *AppendEntriesArgs, reply *AppendEntriesReply)
func (*Raft) ConvertToCandidate ¶
func (rf *Raft) ConvertToCandidate()
func (*Raft) ConvertToFollower ¶
func (rf *Raft) ConvertToFollower()
func (*Raft) ConvertToLeader ¶
func (rf *Raft) ConvertToLeader()
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) LeaderAppendEntries ¶
func (rf *Raft) LeaderAppendEntries()
func (*Raft) RequestVote ¶
func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply)
example RequestVote RPC handler.
func (*Raft) SendHeartBeat ¶
func (rf *Raft) SendHeartBeat()
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 { // Your data here (2A, 2B). Term int CandidateID int LastLogIndex int LastLogTerm int }
example RequestVote RPC arguments structure. field names must start with capital letters!
func (*RequestVoteArgs) String ¶
func (arg *RequestVoteArgs) String() string
type RequestVoteReply ¶
example RequestVote RPC reply structure. field names must start with capital letters!
func (*RequestVoteReply) String ¶
func (arg *RequestVoteReply) String() string