use of org.neo4j.cluster.protocol.snapshot.SnapshotContext in project neo4j by neo4j.
the class MultiPaxosServerFactory method newProtocolServer.
@Override
public ProtocolServer newProtocolServer(InstanceId me, TimeoutStrategy timeoutStrategy, MessageSource input, MessageSender output, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider, Executor stateMachineExecutor, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, Config config) {
DelayedDirectExecutor executor = new DelayedDirectExecutor(logging);
// Create state machines
Timeouts timeouts = new Timeouts(timeoutStrategy);
final MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(initialConfig.getName(), logging, initialConfig.getMemberURIs()), executor, logging, objectInputStreamFactory, objectOutputStreamFactory, acceptorInstanceStore, timeouts, electionCredentialsProvider, config);
SnapshotContext snapshotContext = new SnapshotContext(context.getClusterContext(), context.getLearnerContext());
return newProtocolServer(me, input, output, stateMachineExecutor, executor, timeouts, context, snapshotContext);
}
use of org.neo4j.cluster.protocol.snapshot.SnapshotContext in project neo4j by neo4j.
the class ClusterInstance method newClusterInstance.
public static ClusterInstance newClusterInstance(InstanceId id, URI uri, Monitors monitors, ClusterConfiguration configuration, int maxSurvivableFailedMembers, LogProvider logging) {
MultiPaxosServerFactory factory = new MultiPaxosServerFactory(configuration, logging, monitors.newMonitor(StateMachines.Monitor.class));
ClusterInstanceInput input = new ClusterInstanceInput();
ClusterInstanceOutput output = new ClusterInstanceOutput(uri);
ObjectStreamFactory objStreamFactory = new ObjectStreamFactory();
ProverTimeouts timeouts = new ProverTimeouts(uri);
InMemoryAcceptorInstanceStore acceptorInstances = new InMemoryAcceptorInstanceStore();
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(maxSurvivableFailedMembers);
DelayedDirectExecutor executor = new DelayedDirectExecutor(logging);
final MultiPaxosContext context = new MultiPaxosContext(id, Iterables.<ElectionRole, ElectionRole>iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(configuration.getName(), logging, configuration.getMemberURIs()), executor, logging, objStreamFactory, objStreamFactory, acceptorInstances, timeouts, new DefaultElectionCredentialsProvider(id, new StateVerifierLastTxIdGetter(), new MemberInfoProvider()), config);
context.getClusterContext().setBoundAt(uri);
SnapshotContext snapshotContext = new SnapshotContext(context.getClusterContext(), context.getLearnerContext());
DelayedDirectExecutor taskExecutor = new DelayedDirectExecutor(logging);
ProtocolServer ps = factory.newProtocolServer(id, input, output, DIRECT_EXECUTOR, taskExecutor, timeouts, context, snapshotContext);
return new ClusterInstance(DIRECT_EXECUTOR, logging, factory, ps, context, acceptorInstances, timeouts, input, output, uri);
}
use of org.neo4j.cluster.protocol.snapshot.SnapshotContext in project neo4j by neo4j.
the class ClusterInstance method snapshotStateMachine.
private StateMachine snapshotStateMachine(LogProvider logProvider, MultiPaxosContext snapshotCtx, StateMachine stateMachine) {
// This is done this way because all the state machines are sharing one piece of global state
// (MultiPaxosContext), which is snapshotted as one coherent component. This means the state machines
// cannot snapshot themselves, an external service needs to snapshot the full shared state and then create
// new state machines sharing that state.
Object ctx;
Class<? extends MessageType> msgType = stateMachine.getMessageType();
if (msgType == AtomicBroadcastMessage.class) {
ctx = snapshotCtx.getAtomicBroadcastContext();
} else if (msgType == AcceptorMessage.class) {
ctx = snapshotCtx.getAcceptorContext();
} else if (msgType == ProposerMessage.class) {
ctx = snapshotCtx.getProposerContext();
} else if (msgType == LearnerMessage.class) {
ctx = snapshotCtx.getLearnerContext();
} else if (msgType == HeartbeatMessage.class) {
ctx = snapshotCtx.getHeartbeatContext();
} else if (msgType == ElectionMessage.class) {
ctx = snapshotCtx.getElectionContext();
} else if (msgType == SnapshotMessage.class) {
ctx = new SnapshotContext(snapshotCtx.getClusterContext(), snapshotCtx.getLearnerContext());
} else if (msgType == ClusterMessage.class) {
ctx = snapshotCtx.getClusterContext();
} else {
throw new IllegalArgumentException("I don't know how to snapshot this state machine: " + stateMachine);
}
return new StateMachine(ctx, stateMachine.getMessageType(), stateMachine.getState(), logProvider);
}
Aggregations