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;
}
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);
}
}
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;
}
Aggregations