NicolasT / kontiki

An implementation of the Raft consensus protocol
BSD 3-Clause "New" or "Revised" License
122 stars 15 forks source link

Please confirm that my understanding of how to replicate state is correct. #21

Open barrucadu opened 8 years ago

barrucadu commented 8 years ago

I've been playing with this library today, and figuring out how to actually use it has been a bit tricky, so I just wanted to confirm my understanding is correct:

To replicate a new entry from the leader:

  1. Append that entity to the log.
  2. Call Raft.handle with an EHeartbeatTimeout event to generate the replication commands.
  3. Process those commands.

This seems to work, but the use of an EHeartbeatTimeout was very non-obvious, so I want to check I haven't missed anything. Also, this method doesn't work if multiple entries have been appended, as the default handleHeartbeatTimeout only sends the latest entry.

NicolasT commented 7 years ago

This is how the initial Raft description worked as well, sort of: distributing entries was piggybacked on heartbeats, and could be 'sped up' by injecting a fake intermediate heartbeat. So yes, that's the way it's supposed to be done, though I admit it's non-obvious.

Wrt your last comment, this is also the way Raft was defined. I agree this approach is not the most efficient, but it is correct, the system will converge. My goal for Kontiki was to be as close to the Raft spec (in its draft version back then) as possible (but using uni-directional messages instead of RPC), have it correct, and then maybe improve efficiency where possible.