vandermies
vandermies

Reputation: 183

RAFT: term condition to commit an entry

I've been reading several documentation on Raft and I've getting contradictory information about the commit. I get that an entry can only be committed if it's known to be stored in the majority of servers but, is there any other condition? I've read that it is also compulsory that an entry from the current term is stored in every server, but some other documentation say nothing about that. Any help?

Upvotes: 2

Views: 708

Answers (1)

kuujo
kuujo

Reputation: 8185

It's not technically true that an entry stored on a majority of servers is committed. It is true that the leader determines that an entry is committed once it has been stored on a majority of servers, but only within its current term. An entry from another term can be stored on a majority of servers but never be committed and indeed later be overwritten by another leader. This is shown in Figure 8 in the Raft paper.

This is why a leader has to ensure an entry from its current term is committed before it can consider any (additional) entries from prior terms to be committed. Once a leader is elected, its possible for that leader to replicate entries from a prior term to a majority of nodes without them being committed. If that leader then crashes, another leader that has entries from a later term can be elected and overwrite the entries that were stored on a majority of the cluster. This is what's shown in Figure 8, and it's the reason the technical definition of commitment is: An entry in the leader's current term is committed once it's stored on a majority of the the cluster, and once an entry from the leader's term is committed all entries from prior terms in the leader's log are implicitly committed.

What this means in practice is when a leader is elected, it typically commits a no-op entry to force a commit in its current term. The leader doesn't increase its commitIndex until the no-op entry is stored on a majority of servers.

Upvotes: 5

Related Questions