I am currently implementing the Raft consensus algorithm myself, and I meet with the following problem.
Consider there are 4 nodes(A, B, C and D), so a log entry can be committed with more than 2 votes. Now we start the cluster and have Leader A elected with term = 0
. Then the following things happen:
LogEntry
X.term = 1
.RequestVote
RPC.LogEntry
X. So there are no Leader in the cluster.LogEntry
X to B.Now node A/B/C have exactly the same LogEntry
X, which is (index = 0, term = 0)
. However, according to the Raft paper, Leader A can't commit X, though it's generated by itself and a majority agreed on X.
Raft never commits log entries from previous terms by counting replicas. Only log entries from the leader’s current term are committed by counting replicas;
LogEntry
s from client to replicate, so LogEntry
X remains uncommitted.My questions are:
No
Yes. In raft paper, on page 13., you have the following:
The Leader Completeness Property guarantees that a leader has all committed entries, but at the start of its term, it may not know which those are. To find out, it needs to commit an entry from its term. Raft handles this by having each leader commit a blank no-op entry into the log at the start of its term
In your case, after step 7., A
will create a NoOp
Log entry and it will succeed in replicating it, commit it and thus all previous entries will be committed.