Search in sources :

Example 1 with PreVoteTask

use of com.hazelcast.cp.internal.raft.impl.task.PreVoteTask in project hazelcast by hazelcast.

the class RaftNodeImpl method start.

/**
 * Starts the periodic tasks, such as voting, leader failure-detection, snapshot handling.
 */
public void start() {
    if (status == TERMINATED) {
        logger.warning("Not starting since already terminated...");
        return;
    }
    if (status != INITIAL) {
        throw new IllegalStateException("Cannot start RaftNode when " + status);
    }
    if (!raftIntegration.isReady()) {
        raftIntegration.schedule(this::start, RAFT_NODE_INIT_DELAY_MILLIS, MILLISECONDS);
        return;
    }
    logger.fine("Starting Raft node: " + state.localEndpoint() + " for " + groupId + " with " + state.memberCount() + " members: " + state.members());
    execute(() -> {
        if (status == TERMINATED) {
            logger.warning("Not starting since already terminated...");
            return;
        }
        if (status != INITIAL) {
            throw new IllegalStateException("Cannot start RaftNode when " + status);
        }
        initRestoredState();
        try {
            state.init();
        } catch (IOException e) {
            logger.severe("Raft node start failed!", e);
            setStatus(TERMINATED);
            return;
        }
        new PreVoteTask(RaftNodeImpl.this, 0).run();
        scheduleLeaderFailureDetection();
        // so we only switch to ACTIVE only if status is INITIAL
        if (status == INITIAL) {
            setStatus(ACTIVE);
        }
    });
}
Also used : IOException(java.io.IOException) PreVoteTask(com.hazelcast.cp.internal.raft.impl.task.PreVoteTask)

Aggregations

PreVoteTask (com.hazelcast.cp.internal.raft.impl.task.PreVoteTask)1 IOException (java.io.IOException)1