use of com.hazelcast.cp.internal.raft.impl.state.LeadershipTransferState 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();
}
Aggregations