goraft/raft — pull request #239 by jrallison (2014-10-22 15:52:18+00:00)
Title: Command#Apply context is passed inconsistent information.

Hey all,

I'm using raft for a project, and using `context.CurrentIndex()` in my command's Apply function for some bookkeeping.

I noticed, in different circumstances, the `context.CurrentIndex()` is inconsistent. For instance, committing 3 entries, in succession against a new 1-node cluster, results in the following contexts passed to the `Apply` function:

Term: 0 CurrentIndex: 3 CommitIndex: 3
Term: 0 CurrentIndex: 4 CommitIndex: 4
Term: 0 CurrentIndex: 5 CommitIndex: 5

Killing and restarting the node will force it to recover from the log. While recovering, we receive the following contexts as the node replays the committed entries:

Term: 0 CurrentIndex: 5 CommitIndex: 3
Term: 0 CurrentIndex: 5 CommitIndex: 4
Term: 0 CurrentIndex: 5 CommitIndex: 5

This is due to how the `internalCurrentIndex` method is computed.

I've added a failing test, and adjusted the code to always return the index of the entry as the current index (the index we're currently applying to the state machine).

Let me know if anything here is unclear, or if I've misunderstood the meaning of `CurrentIndex`.