distributed-computingconsensusraftleader

Raft leaders commit a no-op entry at the beginning of their term


Recently I have read a paper on the Raft consensus algorithm. The new leader does not know what is the current commit index.

How does a no-op solves this problem?


Solution

  • In Raft a new elected leader (implies that he received a majority of votes in the cluster. That means his log was at least up-to-date as the log of the nodes that granted him his votes) is not allowed to directly commit (I) entries from previous terms - previous leaders.

    However he can do that implicitly. If he appends a new command to the log and replicates that command on other nodes, he can consider, as soon as the majority responds with an ok, that command as committed. This means implicit that all the previous commands are committed as well and can be passed to the state machine if not already done so.

    Now if you add an no-op entry to the log, you are able to implicit commit previous commands and thus figure out which is the current commitIndex.


    (I): mark a command to be safe to pass to the state machine. This is as soon as the command is replicated on the majority of nodes in the cluster.