Search in sources :

Example 1 with ConsensusOutcome

use of org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome in project neo4j by neo4j.

the class RaftMachineBuilder method build.

public RaftMachine build() {
    SendToMyself leaderOnlyReplicator = new SendToMyself(member, outbound);
    RaftMembershipManager membershipManager = new RaftMembershipManager(leaderOnlyReplicator, memberSetBuilder, raftLog, logProvider, expectedClusterSize, electionTimeout, clock, catchupTimeout, raftMembership);
    membershipManager.setRecoverFromIndexSupplier(() -> 0);
    RaftLogShippingManager logShipping = new RaftLogShippingManager(outbound, logProvider, raftLog, shippingClock, member, membershipManager, retryTimeMillis, catchupBatchSize, maxAllowedShippingLag, inFlightMap);
    RaftMachine raft = new RaftMachine(member, termState, voteState, raftLog, electionTimeout, heartbeatInterval, renewableTimeoutService, outbound, logProvider, membershipManager, logShipping, inFlightMap, false, monitors, clock);
    inbound.registerHandler((incomingMessage) -> {
        try {
            ConsensusOutcome outcome = raft.handle(incomingMessage);
            commitListener.notifyCommitted(outcome.getCommitIndex());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    try {
        membershipManager.start();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return raft;
}
Also used : RaftMembershipManager(org.neo4j.causalclustering.core.consensus.membership.RaftMembershipManager) IOException(java.io.IOException) SendToMyself(org.neo4j.causalclustering.core.replication.SendToMyself) RaftLogShippingManager(org.neo4j.causalclustering.core.consensus.shipping.RaftLogShippingManager) ConsensusOutcome(org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome)

Example 2 with ConsensusOutcome

use of org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome in project neo4j by neo4j.

the class CoreState method handle.

public synchronized void handle(RaftMessages.ClusterIdAwareMessage clusterIdAwareMessage) {
    Optional<ClusterId> optionalClusterId = clusterBinder.get();
    if (!allowMessageHandling || !optionalClusterId.isPresent()) {
        return;
    }
    ClusterId boundClusterId = optionalClusterId.get();
    ClusterId msgClusterId = clusterIdAwareMessage.clusterId();
    if (msgClusterId.equals(boundClusterId)) {
        try {
            ConsensusOutcome outcome = raftMachine.handle(clusterIdAwareMessage.message());
            if (outcome.needsFreshSnapshot()) {
                downloadSnapshot(clusterIdAwareMessage.message().from());
            } else {
                notifyCommitted(outcome.getCommitIndex());
            }
        } catch (Throwable e) {
            log.error("Error handling message", e);
            raftMachine.panic();
            localDatabase.panic(e);
        }
    } else {
        log.info("Discarding message[%s] owing to mismatched clusterId. Expected: %s, Encountered: %s", clusterIdAwareMessage.message(), boundClusterId, msgClusterId);
    }
}
Also used : ClusterId(org.neo4j.causalclustering.identity.ClusterId) ConsensusOutcome(org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome)

Example 3 with ConsensusOutcome

use of org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome in project neo4j by neo4j.

the class RaftMachine method handle.

public synchronized ConsensusOutcome handle(RaftMessages.RaftMessage incomingMessage) throws IOException {
    Outcome outcome = currentRole.handler.handle(incomingMessage, state, log);
    boolean newLeaderWasElected = leaderChanged(outcome, state.leader());
    // updates to raft log happen within
    state.update(outcome);
    sendMessages(outcome);
    handleTimers(outcome);
    handleLogShipping(outcome);
    driveMembership(outcome);
    volatileLeader.set(outcome.getLeader());
    if (newLeaderWasElected) {
        notifyLeaderChanges(outcome);
    }
    return outcome;
}
Also used : ConsensusOutcome(org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome)

Aggregations

ConsensusOutcome (org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome)3 IOException (java.io.IOException)1 RaftMembershipManager (org.neo4j.causalclustering.core.consensus.membership.RaftMembershipManager)1 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)1 RaftLogShippingManager (org.neo4j.causalclustering.core.consensus.shipping.RaftLogShippingManager)1 SendToMyself (org.neo4j.causalclustering.core.replication.SendToMyself)1 ClusterId (org.neo4j.causalclustering.identity.ClusterId)1