Skip to content
Snippets Groups Projects
Commit 0b81ac78 authored by djq2's avatar djq2
Browse files

whatever

parent a7058ab1
No related branches found
No related tags found
No related merge requests found
......@@ -169,7 +169,9 @@ func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply) {
func (rf *Raft) AppendEntries(args *AppendEntriesArgs, reply *AppendEntriesReply) {
// Refresh timeout
// print("append entries")
rf.mu.Lock()
// print("grabed lock")
......@@ -236,7 +238,7 @@ func (rf *Raft) AppendEntries(args *AppendEntriesArgs, reply *AppendEntriesReply
//add else statment later to handle optimization
reply.Success = false
}
reply.Term = rf.currentTerm
rf.mu.Unlock()
return
......@@ -257,12 +259,13 @@ func (rf *Raft) printLog() {
func (rf *Raft) handleCommitChannel(){
for range rf.commitReadyChan {
<-rf.commitReadyChan
rf.mu.Lock()
lastApplied := rf.lastApplied
var entries []Entry
if rf.commitIndex > rf.lastApplied {
entries = rf.log[rf.lastApplied + 1: rf.commitIndex + 1]
rf.lastApplied = rf.commitIndex
entries = rf.log[rf.lastApplied + 1: rf.commitIndex + 1]
rf.lastApplied = rf.commitIndex
}
rf.mu.Unlock()
......@@ -359,7 +362,6 @@ func (rf *Raft) Follower() {
return
}
rf.mu.Unlock()
}
}
......@@ -626,7 +628,7 @@ func (rf *Raft) sendHeartbeat(){
count := 1
for j := 0; j < len(rf.peers); j++{
if j != rf.me{
if rf.matchIndex[j] >= i{
if rf.matchIndex[j] >= i {
count++
}
}
......@@ -700,7 +702,7 @@ func (rf *Raft) Start(command interface{}) (int, int, bool) {
go rf.sendHeartbeat()
}
index = len(rf.log)
// Your code here (2B).
rf.mu.Unlock()
return index, term, isLeader
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment