protected bool checkVote(RequestVote voteRequest) { //Reply false if term < currentTerm if (voteRequest.term < this.currentTerm) { return(false); } //Reply false if already voted if (this.votedForCandidateId > 0) { return(false); } //Reply false if the term of this node's last log > the term of requester's last log if (this.logEntries.getLastLogTerm() > voteRequest.lastLogTerm) { return(false); } //Reply false if the terms equal, but the requester's last index is smaller if (this.logEntries.getLastLogTerm() == voteRequest.lastLogTerm && this.logEntries.getLastLogIndex() > voteRequest.lastLogIndex) { return(false); } return(true); }
public void respondVoteRequest(RequestVote voteRequest, IActorRef sender) { //Check whether this node can vote for the requester bool vote = this.checkVote(voteRequest); //If we can vote for this candidate, vote and record it if (vote) { this.votedForCandidateId = voteRequest.candidateID; this.resetElectionTimer(); } this.updatePersistentStorage(); //Reply to the candidate sender.Tell(new RequestVoteResponse(this.currentTerm, vote)); }
public void handleRequestVote(RequestVote voteRequest, IActorRef sender) { this.node.respondVoteRequest(voteRequest, sender); }
public void handleRequestVote(RequestVote requestVote, IActorRef sender) { //If it gets here, the sender's term is <= this node's term, vote no sender.Tell(new RequestVoteResponse(this.node.currentTerm, false)); }