Search in sources :

Example 26 with MultiPaxosContext

use of org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext in project neo4j by neo4j.

the class LearnerContextTest method shouldTrackLastKnownUpToDateAliveInstance.

@Test
public void shouldTrackLastKnownUpToDateAliveInstance() throws Exception {
    // Given
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext mpCtx = new MultiPaxosContext(null, Iterables.<ElectionRole>empty(), mock(ClusterConfiguration.class), null, NullLogProvider.getInstance(), null, null, null, null, null, config);
    LearnerContext state = mpCtx.getLearnerContext();
    // When
    state.setLastKnownLearnedInstanceInCluster(1, new InstanceId(2));
    state.setLastKnownLearnedInstanceInCluster(1, new InstanceId(3));
    state.setLastKnownLearnedInstanceInCluster(0, new InstanceId(4));
    // Then
    assertThat(state.getLastKnownLearnedInstanceInCluster(), equalTo(1L));
    assertThat(state.getLastKnownAliveUpToDateInstance(), equalTo(new InstanceId(3)));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) Test(org.junit.Test)

Example 27 with MultiPaxosContext

use of org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext 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)

Aggregations

MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)27 Config (org.neo4j.kernel.configuration.Config)25 InstanceId (org.neo4j.cluster.InstanceId)24 Test (org.junit.Test)22 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)20 Timeouts (org.neo4j.cluster.timeout.Timeouts)20 Executor (java.util.concurrent.Executor)19 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)17 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)17 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)17 ElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ElectionCredentialsProvider)11 ElectionRole (org.neo4j.cluster.protocol.election.ElectionRole)11 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)10 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)8 URI (java.net.URI)7 HashMap (java.util.HashMap)6 DelayedDirectExecutor (org.neo4j.cluster.DelayedDirectExecutor)6 Message (org.neo4j.cluster.com.message.Message)4 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)4 LearnerMessage (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage)4