Example #1
0
        private async Task CountVote(RequestVoteResponse requestVoteResponse)
        {
            if (ResponseContainsTermGreaterThanCurrentTerm(requestVoteResponse))
            {
                BecomeFollowerAfterElectionFinishes(requestVoteResponse);
            }

            if (requestVoteResponse.VoteGranted)
            {
                lock (_lock)
                {
                    _votesThisElection++;

                    if (HasMajority())
                    {
                        ShouldBecomeLeader();
                    }
                }
            }
        }
Example #2
0
 private bool ResponseContainsTermGreaterThanCurrentTerm(RequestVoteResponse requestVoteResponse)
 {
     return(requestVoteResponse.Term > CurrentState.CurrentTerm);
 }