use of com.hazelcast.cp.internal.raft.impl.dto.PreVoteResponse in project hazelcast by hazelcast.
the class PreVoteRequestHandlerTask method innerRun.
@Override
protected void innerRun() {
RaftState state = raftNode.state();
RaftEndpoint localEndpoint = localMember();
// Reply false if term < currentTerm (ยง5.1)
if (state.term() > req.nextTerm()) {
logger.info("Rejecting " + req + " since current term: " + state.term() + " is bigger");
raftNode.send(new PreVoteResponse(localEndpoint, state.term(), false), req.candidate());
return;
}
// Reply false if last AppendEntries call was received less than election timeout ago (leader stickiness)
if (raftNode.lastAppendEntriesTimestamp() > Clock.currentTimeMillis() - raftNode.getLeaderElectionTimeoutInMillis()) {
logger.info("Rejecting " + req + " since received append entries recently.");
raftNode.send(new PreVoteResponse(localEndpoint, state.term(), false), req.candidate());
return;
}
RaftLog raftLog = state.log();
if (raftLog.lastLogOrSnapshotTerm() > req.lastLogTerm()) {
logger.info("Rejecting " + req + " since our last log term: " + raftLog.lastLogOrSnapshotTerm() + " is greater");
raftNode.send(new PreVoteResponse(localEndpoint, req.nextTerm(), false), req.candidate());
return;
}
if (raftLog.lastLogOrSnapshotTerm() == req.lastLogTerm() && raftLog.lastLogOrSnapshotIndex() > req.lastLogIndex()) {
logger.info("Rejecting " + req + " since our last log index: " + raftLog.lastLogOrSnapshotIndex() + " is greater");
raftNode.send(new PreVoteResponse(localEndpoint, req.nextTerm(), false), req.candidate());
return;
}
logger.info("Granted pre-vote for " + req);
raftNode.send(new PreVoteResponse(localEndpoint, req.nextTerm(), true), req.candidate());
}
Aggregations