feat: implement strict raft consensus and convergence parity
This commit is contained in:
@@ -49,12 +49,24 @@ public sealed class RaftNode
|
||||
TryBecomeLeader(clusterSize);
|
||||
}
|
||||
|
||||
public VoteResponse GrantVote(int term)
|
||||
public VoteResponse GrantVote(int term, string candidateId = "")
|
||||
{
|
||||
if (term < TermState.CurrentTerm)
|
||||
return new VoteResponse { Granted = false };
|
||||
|
||||
TermState.CurrentTerm = term;
|
||||
if (term > TermState.CurrentTerm)
|
||||
{
|
||||
TermState.CurrentTerm = term;
|
||||
TermState.VotedFor = null;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(TermState.VotedFor)
|
||||
&& !string.Equals(TermState.VotedFor, candidateId, StringComparison.Ordinal))
|
||||
{
|
||||
return new VoteResponse { Granted = false };
|
||||
}
|
||||
|
||||
TermState.VotedFor = candidateId;
|
||||
return new VoteResponse { Granted = true };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user