goraft/raft — pull request #142 by benbjohnson (2013-12-23 14:23:49+00:00)
Title: Command Context

I spent the weekend trying to figure out some etcd issues after upgrading to the current Raft revision. One of the biggest issues was trying to access things like `CommitIndex()` from within a `Command.Apply()` function. The commands are executed within a server lock so it causes the app to hang when trying to retrieve the commit index from within the `Apply()` function.

The Raft version hasn't been sync'd up on etcd for a while so we should probably try to stay more in sync and hopefully these issues will pop up sooner and be easier to debug.

The change included in this PR is to pass a `Context` object to the `Apply()` function instead of the `Server` reference. I kept the old `Apply(Server)` for backwards compatibility but it's not advertised in the API anymore and it's marked as "deprecated" in the code.

The new `Context` object has `CurrentIndex()` and `CurrentTerm()` methods attached to it so the command can use that information without requiring a lock.

/cc: @philips @xiangli-cmu