Search in sources :

Example 1 with PreVoteRequest

use of com.hazelcast.cp.internal.raft.impl.dto.PreVoteRequest in project hazelcast by hazelcast.

the class PreVoteTask method innerRun.

@Override
protected void innerRun() {
    RaftState state = raftNode.state();
    if (state.leader() != null) {
        logger.fine("No new pre-vote phase, we already have a LEADER: " + state.leader());
        return;
    } else if (state.term() != term) {
        logger.fine("No new pre-vote phase for term= " + term + " because of new term: " + state.term());
        return;
    }
    Collection<RaftEndpoint> remoteMembers = state.remoteMembers();
    if (remoteMembers.isEmpty()) {
        logger.fine("Remote members is empty. No need for pre-voting.");
        return;
    }
    state.initPreCandidateState();
    int nextTerm = state.term() + 1;
    RaftLog log = state.log();
    PreVoteRequest request = new PreVoteRequest(localMember(), nextTerm, log.lastLogOrSnapshotTerm(), log.lastLogOrSnapshotIndex());
    logger.info("Pre-vote started for next term: " + request.nextTerm() + ", last log index: " + request.lastLogIndex() + ", last log term: " + request.lastLogTerm());
    raftNode.printMemberState();
    for (RaftEndpoint endpoint : remoteMembers) {
        raftNode.send(request, endpoint);
    }
    schedulePreVoteTimeout();
}
Also used : RaftState(com.hazelcast.cp.internal.raft.impl.state.RaftState) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) PreVoteRequest(com.hazelcast.cp.internal.raft.impl.dto.PreVoteRequest) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftLog(com.hazelcast.cp.internal.raft.impl.log.RaftLog)

Aggregations

RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)1 PreVoteRequest (com.hazelcast.cp.internal.raft.impl.dto.PreVoteRequest)1 RaftLog (com.hazelcast.cp.internal.raft.impl.log.RaftLog)1 RaftState (com.hazelcast.cp.internal.raft.impl.state.RaftState)1