Commit 154e51a8 authored by Sushant Mahajan's avatar Sushant Mahajan

added code for AppendRPCReply

parent 3a58d3dd
...@@ -308,8 +308,15 @@ func (rft *Raft) grantVote(reply bool, currentTerm int) { ...@@ -308,8 +308,15 @@ func (rft *Raft) grantVote(reply bool, currentTerm int) {
} }
} }
func (rft *Raft) replyAppendRPC(reply bool, currentTerm int) { func (rft *Raft) replyAppendRPC(reply bool, currentTerm int, id int) {
// defer rafts[id].Unlock()
rafts[id].Lock()
if reply {
rafts[id].nextIndex[id-1] = len(rft.LogArray) - 1
rafts[id].matchIndex[id-1] = len(rft.LogArray) - 1
} else {
rafts[id].nextIndex[id-1]--
}
} }
func (rft *Raft) updateTermAndVote(term int) { func (rft *Raft) updateTermAndVote(term int) {
...@@ -418,7 +425,7 @@ func (rft *Raft) follower() int { ...@@ -418,7 +425,7 @@ func (rft *Raft) follower() int {
} }
} }
rft.LogF("AppendRPC") rft.LogF("AppendRPC")
rafts[req.leaderId].replyAppendRPC(reply, rft.currentTerm) rafts[req.leaderId].replyAppendRPC(reply, rft.currentTerm, rft.id)
} }
} }
} }
...@@ -507,6 +514,8 @@ func (rft *Raft) leader() int { ...@@ -507,6 +514,8 @@ func (rft *Raft) leader() int {
rft.matchIndex[i] = 0 rft.matchIndex[i] = 0
} }
//go rft.enforceLog()
for { for {
select { select {
case <-heartbeat.C: case <-heartbeat.C:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment