nextIndex for each follower (initialized to leader's log length)
If AppendEntries fails, reduce nextIndex for that follower and retry.
If follower receives conflicting entries but consistency check passes, removes all conflicting entries
Safety
Must ensure that the leader for the new term always holds all of the log entries committed in previous terms (Leader Completeness Property).
Step 1: restriction on elections: don't vote for a candidate unless the candidate's log is at least as up-to-date as yours.
Compare indexes and terms from last log entries.
Step 2: be very careful about when an entry is considered committed
As soon as it is replicated in the majority? Unsafe!
Committed => entry in current term replicated on majority
All preceding entries also committed because of Log Matching Property
Persistent Storage
Each server stores the following in persistent storage (e.g. disk or flash):
Current term
Most recent vote granted
Log
These must be recovered from persistent storage after a crash
If a server loses its persistent storage, it cannot participate in the cluster anymore
Implementing Raft
Every tiny detail matters.
Client Interactions
Clients interact only with the leader
Initially, a client can send a request to any server
If not leader, it rejects request, returns info about most recent leader
Client retries until it reaches leader
If leader crashes while executing a client request, the client retries (with a new randomly-chosen server) until the request succeeds
This can result in multiple executions of a command: not consistent!
Goal: linearizability: System behaves as if each operation is executed exactly once, atomically, sometime between sending of the request and receipt of the response.
Solution:
Client generates unique serial number for each request (client id, request number)
When retrying, client reuses the original serial number
Servers track latest serial number processed for each client, plus associated response (must be stored persistently)
When leader detects duplicate, it sends old response without re-executing request
Other Issues
Cluster membership
Log compaction
Get started with Spydra
Spydra is a next-generation API driven Decentralization-as-a-Service platform to enable business and developers to leverage the full potential of Blockchain and the Decentralized Web Infrastructure.