Search in sources :

Example 1 with TriggerLeaderElection

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

the class LeadershipTransferTask method run.

@Override
public void run() {
    ILogger logger = raftNode.getLogger(getClass());
    RaftState state = raftNode.state();
    LeaderState leaderState = state.leaderState();
    if (leaderState == null) {
        logger.fine("Not retrying leadership transfer since not leader...");
        return;
    }
    LeadershipTransferState leadershipTransferState = state.leadershipTransferState();
    checkTrue(leadershipTransferState != null, "No leadership transfer state!");
    if (retryCount == maxRetryCount) {
        String msg = "Leadership transfer to " + leadershipTransferState.endpoint() + " timed out!";
        logger.warning(msg);
        state.completeLeadershipTransfer(new IllegalStateException(msg));
        return;
    }
    RaftEndpoint targetEndpoint = leadershipTransferState.endpoint();
    if (state.commitIndex() < state.log().lastLogOrSnapshotIndex()) {
        logger.warning("Waiting until all appended entries to be committed before transferring leadership to " + targetEndpoint);
        reschedule();
        return;
    }
    if (retryCount > 0) {
        logger.fine("Retrying leadership transfer to " + leadershipTransferState.endpoint());
    } else {
        logger.info("Transferring leadership to " + leadershipTransferState.endpoint());
    }
    leaderState.getFollowerState(targetEndpoint).appendRequestAckReceived();
    raftNode.sendAppendRequest(targetEndpoint);
    LogEntry entry = state.log().lastLogOrSnapshotEntry();
    raftNode.send(new TriggerLeaderElection(raftNode.getLocalMember(), state.term(), entry.term(), entry.index()), targetEndpoint);
    reschedule();
}
Also used : RaftState(com.hazelcast.cp.internal.raft.impl.state.RaftState) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ILogger(com.hazelcast.logging.ILogger) LeadershipTransferState(com.hazelcast.cp.internal.raft.impl.state.LeadershipTransferState) TriggerLeaderElection(com.hazelcast.cp.internal.raft.impl.dto.TriggerLeaderElection) LogEntry(com.hazelcast.cp.internal.raft.impl.log.LogEntry) LeaderState(com.hazelcast.cp.internal.raft.impl.state.LeaderState)

Aggregations

RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)1 TriggerLeaderElection (com.hazelcast.cp.internal.raft.impl.dto.TriggerLeaderElection)1 LogEntry (com.hazelcast.cp.internal.raft.impl.log.LogEntry)1 LeaderState (com.hazelcast.cp.internal.raft.impl.state.LeaderState)1 LeadershipTransferState (com.hazelcast.cp.internal.raft.impl.state.LeadershipTransferState)1 RaftState (com.hazelcast.cp.internal.raft.impl.state.RaftState)1 ILogger (com.hazelcast.logging.ILogger)1