Search in sources :

Example 1 with SnapshotContext

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);
}
Also used : Timeouts(org.neo4j.cluster.timeout.Timeouts) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) SnapshotContext(org.neo4j.cluster.protocol.snapshot.SnapshotContext)

Example 2 with 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);
}
Also used : Config(org.neo4j.kernel.configuration.Config) HighAvailabilityMemberInfoProvider(org.neo4j.kernel.ha.HighAvailabilityMemberInfoProvider) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) DefaultElectionCredentialsProvider(org.neo4j.kernel.ha.cluster.DefaultElectionCredentialsProvider) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) SnapshotContext(org.neo4j.cluster.protocol.snapshot.SnapshotContext) ProtocolServer(org.neo4j.cluster.ProtocolServer) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) MultiPaxosServerFactory(org.neo4j.cluster.MultiPaxosServerFactory) InMemoryAcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InMemoryAcceptorInstanceStore)

Example 3 with SnapshotContext

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);
}
Also used : ElectionMessage(org.neo4j.cluster.protocol.election.ElectionMessage) StateMachine(org.neo4j.cluster.statemachine.StateMachine) AcceptorMessage(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorMessage) ClusterMessage(org.neo4j.cluster.protocol.cluster.ClusterMessage) LearnerMessage(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage) SnapshotContext(org.neo4j.cluster.protocol.snapshot.SnapshotContext)

Aggregations

SnapshotContext (org.neo4j.cluster.protocol.snapshot.SnapshotContext)3 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)2 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)2 ElectionRole (org.neo4j.cluster.protocol.election.ElectionRole)2 DelayedDirectExecutor (org.neo4j.cluster.DelayedDirectExecutor)1 MultiPaxosServerFactory (org.neo4j.cluster.MultiPaxosServerFactory)1 ProtocolServer (org.neo4j.cluster.ProtocolServer)1 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)1 AcceptorMessage (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorMessage)1 InMemoryAcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InMemoryAcceptorInstanceStore)1 LearnerMessage (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage)1 ClusterMessage (org.neo4j.cluster.protocol.cluster.ClusterMessage)1 ElectionMessage (org.neo4j.cluster.protocol.election.ElectionMessage)1 StateMachine (org.neo4j.cluster.statemachine.StateMachine)1 Timeouts (org.neo4j.cluster.timeout.Timeouts)1 Config (org.neo4j.kernel.configuration.Config)1 HighAvailabilityMemberInfoProvider (org.neo4j.kernel.ha.HighAvailabilityMemberInfoProvider)1 DefaultElectionCredentialsProvider (org.neo4j.kernel.ha.cluster.DefaultElectionCredentialsProvider)1