Search in sources :

Example 6 with MultiPaxosContext

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

the class ClusterInstance method newCopy.

public ClusterInstance newCopy() {
    // A very invasive method of cloning a protocol server. Nonetheless, since this is mostly an experiment at this
    // point, it seems we can refactor later on to have a cleaner clone mechanism.
    // Because state machines share state, and are simultaneously conceptually unaware of each other, implementing
    // a clean snapshot mechanism is very hard. I've opted for having a dirty one here in the test code rather
    // than introducing a hack into the runtime code.
    ProverTimeouts timeoutsSnapshot = timeouts.snapshot();
    InMemoryAcceptorInstanceStore snapshotAcceptorInstances = acceptorInstanceStore.snapshot();
    ClusterInstanceOutput output = new ClusterInstanceOutput(uri);
    ClusterInstanceInput input = new ClusterInstanceInput();
    DelayedDirectExecutor executor = new DelayedDirectExecutor(logging);
    ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory();
    MultiPaxosContext snapshotCtx = ctx.snapshot(logging, timeoutsSnapshot, executor, snapshotAcceptorInstances, objectStreamFactory, objectStreamFactory, new DefaultElectionCredentialsProvider(server.getServerId(), new StateVerifierLastTxIdGetter(), new MemberInfoProvider()));
    List<StateMachine> snapshotMachines = new ArrayList<>();
    for (StateMachine stateMachine : server.getStateMachines().getStateMachines()) {
        snapshotMachines.add(snapshotStateMachine(logging, snapshotCtx, stateMachine));
    }
    ProtocolServer snapshotProtocolServer = factory.constructSupportingInfrastructureFor(server.getServerId(), input, output, executor, timeoutsSnapshot, stateMachineExecutor, snapshotCtx, snapshotMachines.toArray(new StateMachine[snapshotMachines.size()]));
    return new ClusterInstance(stateMachineExecutor, logging, factory, snapshotProtocolServer, snapshotCtx, snapshotAcceptorInstances, timeoutsSnapshot, input, output, uri);
}
Also used : StateMachine(org.neo4j.cluster.statemachine.StateMachine) ArrayList(java.util.ArrayList) HighAvailabilityMemberInfoProvider(org.neo4j.kernel.ha.HighAvailabilityMemberInfoProvider) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) DefaultElectionCredentialsProvider(org.neo4j.kernel.ha.cluster.DefaultElectionCredentialsProvider) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) ProtocolServer(org.neo4j.cluster.ProtocolServer) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) InMemoryAcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InMemoryAcceptorInstanceStore)

Example 7 with MultiPaxosContext

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

the class MultiPaxosContextTest method shouldDeepClone.

@Test
public void shouldDeepClone() throws Exception {
    // Given
    ObjectStreamFactory objStream = new ObjectStreamFactory();
    AcceptorInstanceStore acceptorInstances = mock(AcceptorInstanceStore.class);
    Executor executor = mock(Executor.class);
    Timeouts timeouts = mock(Timeouts.class);
    ClusterConfiguration clusterConfig = new ClusterConfiguration("myCluster", NullLogProvider.getInstance());
    ElectionCredentialsProvider electionCredentials = mock(ElectionCredentialsProvider.class);
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext ctx = new MultiPaxosContext(new InstanceId(1), Collections.<ElectionRole>emptyList(), clusterConfig, executor, NullLogProvider.getInstance(), objStream, objStream, acceptorInstances, timeouts, electionCredentials, config);
    // When
    MultiPaxosContext snapshot = ctx.snapshot(NullLogProvider.getInstance(), timeouts, executor, acceptorInstances, objStream, objStream, electionCredentials);
    // Then
    assertEquals(ctx, snapshot);
}
Also used : Executor(java.util.concurrent.Executor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) Config(org.neo4j.kernel.configuration.Config) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) Test(org.junit.Test)

Example 8 with MultiPaxosContext

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

the class ElectionContextTest method testElectionNotOkQuorumFailedFourInstances.

@Test
public void testElectionNotOkQuorumFailedFourInstances() {
    Set<InstanceId> failed = new HashSet<InstanceId>();
    failed.add(new InstanceId(2));
    failed.add(new InstanceId(3));
    Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
    members.put(new InstanceId(1), URI.create("server1"));
    members.put(new InstanceId(2), URI.create("server2"));
    members.put(new InstanceId(3), URI.create("server3"));
    members.put(new InstanceId(4), URI.create("server4"));
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
    when(clusterConfiguration.getMembers()).thenReturn(members);
    ClusterContext clusterContext = mock(ClusterContext.class);
    when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
    MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    context.getHeartbeatContext().getFailed().addAll(failed);
    ElectionContext toTest = context.getElectionContext();
    assertFalse(toTest.electionOk());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) Executor(java.util.concurrent.Executor) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with MultiPaxosContext

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

the class ElectionContextTest method electionBeingForgottenMustIncreaseElectionId.

@Test
public void electionBeingForgottenMustIncreaseElectionId() throws Exception {
    // Given
    final String coordinatorRole = "coordinator";
    HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
    when(heartbeatContext.getFailed()).thenReturn(Collections.<InstanceId>emptySet());
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    ElectionContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(ClusterConfiguration.class), mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config).getElectionContext();
    ElectionContext.VoteRequest voteRequestBefore = context.voteRequestForRole(new ElectionRole(coordinatorRole));
    context.forgetElection(coordinatorRole);
    ElectionContext.VoteRequest voteRequestAfter = context.voteRequestForRole(new ElectionRole(coordinatorRole));
    assertEquals(voteRequestBefore.getVersion() + 1, voteRequestAfter.getVersion());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) Test(org.junit.Test)

Example 10 with MultiPaxosContext

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

the class ElectionContextTest method testElectionNotOkQuorumFailedFiveInstances.

@Test
public void testElectionNotOkQuorumFailedFiveInstances() {
    Set<InstanceId> failed = new HashSet<InstanceId>();
    failed.add(new InstanceId(2));
    failed.add(new InstanceId(3));
    failed.add(new InstanceId(4));
    Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
    members.put(new InstanceId(1), URI.create("server1"));
    members.put(new InstanceId(2), URI.create("server2"));
    members.put(new InstanceId(3), URI.create("server3"));
    members.put(new InstanceId(4), URI.create("server4"));
    members.put(new InstanceId(5), URI.create("server5"));
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
    when(clusterConfiguration.getMembers()).thenReturn(members);
    ClusterContext clusterContext = mock(ClusterContext.class);
    when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
    MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    context.getHeartbeatContext().getFailed().addAll(failed);
    ElectionContext toTest = context.getElectionContext();
    assertFalse(toTest.electionOk());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) Executor(java.util.concurrent.Executor) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) HashSet(java.util.HashSet) Test(org.junit.Test)

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