The leader should update the next index upon successful AppendEntries RPC, thus causing its next AppendEntries RPC to that follower to include the entries immediately following those in the successful request. When the follower acknowledges a successful AppendEntries RPC, that indicates it has appended all the entries in the request. Therefore, the leader’s nextIndex for that follower then becomes nextIndex + count(entries). That is, the leader should update the nextIndex to what it believes to be the followers last log index + 1, based on the successful AE RPC.
In practice, different implementations may want to track and update the nextIndex a bit differently due to optimizations like pipelining. There’s not really any risk to correctness in how the leader updates the nextIndex — since the log matching checks on the follower will always ensure consistency between the leader’s and followers’ logs anyways — so do what makes sense for your implementation.
You also mentioned information not being included in the AppendEntries response. A lot of implementations actually do add the follower’s last log index to the response, and you should not shy away from doing so. This allows the leader to converge on the follower’s log more quickly — as opposed to decrementing one entry at a time — and the leader can use the lastLogIndex in the follower’s response to update the nextIndex for that follower.
Jordan Halterman
Hi Rafters,