Hoverbear / old-raft-rs

[Incomplete] A Raft implementation in Rust
https://hoverbear.github.io/raft-rs/raft/
MIT License
266 stars 41 forks source link

Transactions #1

Closed Hoverbear closed 9 years ago

Hoverbear commented 9 years ago

In general, the sender of a RemoteProcedureCall must have some way of identifying it's corresponding RemoteProcedureResponse.

We could use uuid::Uuid (as suggested by @manishearth) to uniquely identify a RemoteProcedureCall and RemoteProcedureResponse pair... But it's possibly unnecessary in some cases, see below.

General Implementation Details

A RemoteProcedureResponse::{Accepted, Rejected} is required:

The paper states that the entries in a RaftNode should back their replicated log onto a persistent storage. The storage will be interfaced with via u64 indexes, and the items in the log are known to be RustcEncodable and RustcDecodable.

The protocol keeps the state of the last_applied and commit_index indices into the log. All indices before the commit_index are known to be committed to the backing storage.

Leader Implementation Details

  • We don't necessarily care at the RemoteProcedureCall level, we care about the index level, as an AppendEntries call make have several entries (or none!) and some of them may be repeated indices we have already sent.
  • The AppendEntries log items will always be contiguous and start from what the Leader thinks is the index of the next log entry the Follower does not yet have.
  • The Leader tracks the index of the highest entry known to be replicated on each Follower.
  • If a Follower issues an Accept of an AppendEntries it means that all entries up to that point have been successfully replicated (and thus confirmed).
  • If a RemoteProcedureResponse is sent to the Leader and it's not received we will be sending another AppendEntries with the logs anyways, and the Follower will (hopefully) be able to respond to that.

    Follower Implementation Details

  • Accepting the latest AppendEntries means that all entries before it are confirmed as well.
  • Any RemoteProcedureResponses that fail to reach the Leader will have the corresponding logs resent, the storage backing needs to account for this.
  • (Not in paper) If passing on an AppendEntries request to the Leader, we need some way to wait for (and identify) the appropriate response.

    RequestVote: Use a disposable data store.

This should be tracked by the Candidate state and disposed of afterwards, it's not persistent information and is only O(n) in storage, where n is the number of nodes. HashMaps has good performance in this setting and being able to lookup by u64 will be convenient.

Candidate Implementation Details

Hoverbear commented 9 years ago

Woo!