Browse Source

raft: reuse "last index" in "appendEntry"

No need to call "lastIndex" again.
"append" call already returns "lastIndex".

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
Gyuho Lee 7 years ago
parent
commit
2b7c12fb12
1 changed files with 3 additions and 2 deletions
  1. 3 2
      raft/raft.go

+ 3 - 2
raft/raft.go

@@ -604,8 +604,9 @@ func (r *raft) appendEntry(es ...pb.Entry) {
 		es[i].Term = r.Term
 		es[i].Index = li + 1 + uint64(i)
 	}
-	r.raftLog.append(es...)
-	r.getProgress(r.id).maybeUpdate(r.raftLog.lastIndex())
+	// use latest "last" index after truncate/append
+	li = r.raftLog.append(es...)
+	r.getProgress(r.id).maybeUpdate(li)
 	// Regardless of maybeCommit's return, our caller will call bcastAppend.
 	r.maybeCommit()
 }