public RequestVoteResponse Handle(RequestVote requestVote) { var response = RequestVoteTermIsGreaterThanCurrentTerm(requestVote); if (response.shouldReturn) { return(response.requestVoteResponse); } response = _rules.RequestVoteTermIsLessThanCurrentTerm(requestVote, CurrentState); if (response.shouldReturn) { return(response.requestVoteResponse); } response = _rules.VotedForIsNotThisOrNobody(requestVote, CurrentState); if (response.shouldReturn) { return(response.requestVoteResponse); } response = LastLogIndexAndLastLogTermMatchesThis(requestVote); if (response.shouldReturn) { return(response.requestVoteResponse); } return(new RequestVoteResponse(false, CurrentState.CurrentTerm)); }
public async Task <RequestVoteResponse> Handle(RequestVote requestVote) { var response = RequestVoteTermIsGreaterThanCurrentTerm(requestVote); if (response.shouldReturn) { return(response.requestVoteResponse); } response = _rules.RequestVoteTermIsLessThanCurrentTerm(requestVote, CurrentState); if (response.shouldReturn) { return(response.requestVoteResponse); } response = _rules.VotedForIsNotThisOrNobody(requestVote, CurrentState); if (response.shouldReturn) { return(response.requestVoteResponse); } response = await LastLogIndexAndLastLogTermMatchesThis(requestVote); _messagesSinceLastElectionExpiry++; if (response.shouldReturn) { return(response.requestVoteResponse); } return(new RequestVoteResponse(false, CurrentState.CurrentTerm)); }
public async Task <RequestVoteResponse> Handle(RequestVote requestVote) { var response = RequestVoteTermIsGreaterThanCurrentTerm(requestVote); if (response.shouldReturn) { return(response.requestVoteResponse); } return(new RequestVoteResponse(false, CurrentState.CurrentTerm)); }
public RequestVoteResponse Handle(RequestVote requestVote) { return(State.Handle(requestVote)); }
private (RequestVoteResponse requestVoteResponse, bool shouldReturn) LastLogIndexAndLastLogTermMatchesThis(RequestVote requestVote) { if (requestVote.LastLogIndex == _log.LastLogIndex && requestVote.LastLogTerm == _log.LastLogTerm) { CurrentState = new CurrentState(CurrentState.Id, CurrentState.CurrentTerm, requestVote.CandidateId, CurrentState.CommitIndex, CurrentState.LastApplied, CurrentState.LeaderId); BecomeFollower(); return(new RequestVoteResponse(true, CurrentState.CurrentTerm), true); } return(null, false); }
private (RequestVoteResponse requestVoteResponse, bool shouldReturn) RequestVoteTermIsGreaterThanCurrentTerm(RequestVote requestVote) { if (requestVote.Term > CurrentState.CurrentTerm) { CurrentState = new CurrentState(CurrentState.Id, requestVote.Term, requestVote.CandidateId, CurrentState.CommitIndex, CurrentState.LastApplied, CurrentState.LeaderId); BecomeFollower(); return(new RequestVoteResponse(true, CurrentState.CurrentTerm), true); } return(null, false); }
public async Task <RequestVoteResponse> Handle(RequestVote requestVote) { return(await State.Handle(requestVote)); }
public RequestVoteResponse Request(RequestVote requestVote) { throw new NotImplementedException(); }
private async Task <(RequestVoteResponse requestVoteResponse, bool shouldReturn)> LastLogIndexAndLastLogTermMatchesThis(RequestVote requestVote) { if (requestVote.LastLogIndex == await _log.LastLogIndex() && requestVote.LastLogTerm == await _log.LastLogTerm()) { CurrentState = new CurrentState(CurrentState.Id, CurrentState.CurrentTerm, requestVote.CandidateId, CurrentState.CommitIndex, CurrentState.LastApplied, CurrentState.LeaderId); return(new RequestVoteResponse(true, CurrentState.CurrentTerm), true); } return(null, false); }