Skip to content

Commit

Permalink
Update raft.go
Browse files Browse the repository at this point in the history
  • Loading branch information
UndefinedSy committed Dec 2, 2020
1 parent 4ca1956 commit 89f09d6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,29 @@ func timeoutThread(rf *Raft) {
lastLogTerm: localLastLogTerm
}

requestVoteResultChan := make(chan RequestVoteReply, len(rf.peers) - 1)

for peerIndex, _ := range rf.peers {
go rf.sendRequestVote(peerIndex, requestVoteArgs, &replys[peerIndex])
go func(peerIndex int) {
if rf.me == peerIndex {
return
}

ok := rf.sendRequestVote(peerIndex, requestVoteArgs, &replys[peerIndex])

if ok {
requestVoteResultChan<- &replys[peerIndex]
}
else {
requestVoteResultChan<- nil
}

}(peerIndex)
}

for i := 0; i < len(rf.peers) - 1; i++ {
requestVoteResult := <-requestVoteResultChan

}
}
}
Expand Down

0 comments on commit 89f09d6

Please sign in to comment.