use of com.hazelcast.cp.internal.raft.impl.state.CandidateState in project hazelcast by hazelcast.
the class VoteResponseHandlerTask method handleResponse.
@Override
protected void handleResponse() {
RaftState state = raftNode.state();
if (state.role() != CANDIDATE) {
logger.info("Ignored " + resp + ". We are not CANDIDATE anymore.");
return;
}
if (resp.term() > state.term()) {
logger.info("Demoting to FOLLOWER from current term: " + state.term() + " to new term: " + resp.term() + " after " + resp);
raftNode.toFollower(resp.term());
return;
}
if (resp.term() < state.term()) {
logger.warning("Stale " + resp + " is received, current term: " + state.term());
return;
}
CandidateState candidateState = state.candidateState();
if (resp.granted() && candidateState.grantVote(resp.voter())) {
logger.info("Vote granted from " + resp.voter() + " for term: " + state.term() + ", number of votes: " + candidateState.voteCount() + ", majority: " + candidateState.majority());
}
if (candidateState.isMajorityGranted()) {
logger.info("We are the LEADER!");
raftNode.toLeader();
}
}
use of com.hazelcast.cp.internal.raft.impl.state.CandidateState in project hazelcast by hazelcast.
the class PreVoteResponseHandlerTask method handleResponse.
@Override
protected void handleResponse() {
RaftState state = raftNode.state();
if (state.role() != FOLLOWER) {
logger.info("Ignored " + resp + ". We are not FOLLOWER anymore.");
return;
}
if (resp.term() < state.term()) {
logger.warning("Stale " + resp + " is received, current term: " + state.term());
return;
}
CandidateState preCandidateState = state.preCandidateState();
if (preCandidateState == null) {
if (logger.isFineEnabled()) {
logger.fine("Ignoring " + resp + ". We are not interested in pre-votes anymore.");
}
return;
}
if (resp.granted() && preCandidateState.grantVote(resp.voter())) {
logger.info("Pre-vote granted from " + resp.voter() + " for term: " + resp.term() + ", number of votes: " + preCandidateState.voteCount() + ", majority: " + preCandidateState.majority());
}
if (preCandidateState.isMajorityGranted()) {
logger.info("We have the majority during pre-vote phase. Let's start real election!");
new LeaderElectionTask(raftNode, false).run();
}
}
Aggregations