Search in sources :

Example 11 with MultiPaxosContext

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

the class MultiPaxosContextTest method shouldNotConsiderInstanceJoiningWithSameIdAndIpAProblem.

@Test
public void shouldNotConsiderInstanceJoiningWithSameIdAndIpAProblem() throws Exception {
    // Given
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext ctx = new MultiPaxosContext(new InstanceId(1), Collections.<ElectionRole>emptyList(), mock(ClusterConfiguration.class), mock(Executor.class), NullLogProvider.getInstance(), new ObjectStreamFactory(), new ObjectStreamFactory(), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    InstanceId joiningId = new InstanceId(12);
    String joiningUri = "http://127.0.0.1:900";
    // When
    ctx.getClusterContext().instanceIsJoining(joiningId, new URI(joiningUri));
    // Then
    assertFalse(ctx.getClusterContext().isInstanceJoiningFromDifferentUri(joiningId, new URI(joiningUri)));
    assertTrue(ctx.getClusterContext().isInstanceJoiningFromDifferentUri(joiningId, new URI("http://127.0.0.1:80")));
    assertFalse(ctx.getClusterContext().isInstanceJoiningFromDifferentUri(new InstanceId(13), new URI(joiningUri)));
}
Also used : Executor(java.util.concurrent.Executor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) Test(org.junit.Test)

Example 12 with MultiPaxosContext

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

the class HeartbeatStateTest method shouldIgnoreSuspicionsForOurselvesButKeepTheRest.

@Test
public void shouldIgnoreSuspicionsForOurselvesButKeepTheRest() throws Throwable {
    // Given
    InstanceId myId = new InstanceId(1);
    InstanceId foreignId = new InstanceId(3);
    HeartbeatState heartbeat = HeartbeatState.heartbeat;
    ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.getInstance(), "cluster://1", "cluster://2");
    configuration.joined(myId, URI.create("cluster://1"));
    configuration.joined(new InstanceId(2), URI.create("cluster://2"));
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext context = new MultiPaxosContext(myId, iterable(new ElectionRole("coordinator")), configuration, Mockito.mock(Executor.class), NullLogProvider.getInstance(), Mockito.mock(ObjectInputStreamFactory.class), Mockito.mock(ObjectOutputStreamFactory.class), Mockito.mock(AcceptorInstanceStore.class), Mockito.mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    HeartbeatContext heartbeatContext = context.getHeartbeatContext();
    Message received = Message.internal(HeartbeatMessage.suspicions, new HeartbeatMessage.SuspicionsState(asSet(iterable(myId, foreignId))));
    received.setHeader(Message.FROM, "cluster://2").setHeader(Message.INSTANCE_ID, "2");
    // When
    heartbeat.handle(heartbeatContext, received, mock(MessageHolder.class));
    // Then
    assertThat(heartbeatContext.getSuspicionsOf(myId).size(), equalTo(0));
    assertThat(heartbeatContext.getSuspicionsOf(foreignId).size(), equalTo(1));
}
Also used : LearnerMessage(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage) Message(org.neo4j.cluster.com.message.Message) InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) MessageHolder(org.neo4j.cluster.com.message.MessageHolder) Executor(java.util.concurrent.Executor) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) 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) Test(org.junit.Test)

Example 13 with MultiPaxosContext

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

the class ElectionContextTest method electorLeavingAndRejoiningWithNoElectionsInBetweenMustStillHaveElectionsGoThrough.

/*
     * This assumes an instance leaves the cluster normally and then rejoins, without any elections in between. The
     * expected result is that it will succeed in sending election results.
     */
@Test
public void electorLeavingAndRejoiningWithNoElectionsInBetweenMustStillHaveElectionsGoThrough() throws Exception {
    // Given
    final String role1 = "coordinator1";
    InstanceId me = new InstanceId(1);
    InstanceId leavingInstance = new InstanceId(2);
    InstanceId forQuorum = new InstanceId(3);
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
    List<InstanceId> clusterMemberIds = new LinkedList<InstanceId>();
    clusterMemberIds.add(leavingInstance);
    clusterMemberIds.add(me);
    clusterMemberIds.add(forQuorum);
    when(clusterConfiguration.getMemberIds()).thenReturn(clusterMemberIds);
    MultiPaxosContext context = new MultiPaxosContext(me, Iterables.<ElectionRole, ElectionRole>iterable(new ElectionRole(role1)), clusterConfiguration, new Executor() {

        @Override
        public void execute(Runnable command) {
            command.run();
        }
    }, NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    HeartbeatContext heartbeatContext = context.getHeartbeatContext();
    ClusterContext clusterContext = context.getClusterContext();
    clusterContext.setLastElector(leavingInstance);
    clusterContext.setLastElectorVersion(8);
    // When the elector leaves the cluster
    clusterContext.left(leavingInstance);
    // Then the elector is reset to defaults
    assertEquals(clusterContext.getLastElector(), InstanceId.NONE);
    assertEquals(clusterContext.getLastElectorVersion(), ClusterContext.NO_ELECTOR_VERSION);
    // When the elector comes back with an election result
    // We don't need to join, election results do not check for elector membership
    clusterContext.elected(role1, forQuorum, leavingInstance, 9);
    // Then the result is actually respected
    assertEquals(clusterContext.getLastElector(), leavingInstance);
    assertEquals(clusterContext.getLastElectorVersion(), 9);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) 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) LinkedList(java.util.LinkedList) Executor(java.util.concurrent.Executor) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) Test(org.junit.Test)

Example 14 with MultiPaxosContext

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

the class ElectionContextTest method voteFromPreviousSuccessfulElectionMustNotBeCounted.

@Test
public void voteFromPreviousSuccessfulElectionMustNotBeCounted() 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();
    // When
    ElectionContext.VoteRequest voteRequestBefore = context.voteRequestForRole(new ElectionRole(coordinatorRole));
    context.forgetElection(coordinatorRole);
    // Then
    assertFalse(context.voted(coordinatorRole, new InstanceId(2), null, voteRequestBefore.getVersion() - 1));
}
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 15 with MultiPaxosContext

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

the class ElectionContextTest method failedElectorRejoiningMustHaveItsVersionFromVoteRequestsSetTheElectorVersion.

@Test
public void failedElectorRejoiningMustHaveItsVersionFromVoteRequestsSetTheElectorVersion() throws Throwable {
    // Given
    final String role1 = "coordinator1";
    InstanceId me = new InstanceId(1);
    InstanceId failingInstance = new InstanceId(2);
    InstanceId forQuorum = new InstanceId(3);
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
    List<InstanceId> clusterMemberIds = new LinkedList<InstanceId>();
    clusterMemberIds.add(failingInstance);
    clusterMemberIds.add(me);
    clusterMemberIds.add(forQuorum);
    when(clusterConfiguration.getMemberIds()).thenReturn(clusterMemberIds);
    MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(role1)), clusterConfiguration, new Executor() {

        @Override
        public void execute(Runnable command) {
            command.run();
        }
    }, NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    HeartbeatContext heartbeatContext = context.getHeartbeatContext();
    ClusterContext clusterContext = context.getClusterContext();
    clusterContext.setLastElector(failingInstance);
    clusterContext.setLastElectorVersion(8);
    // When the elector fails
    heartbeatContext.suspicions(forQuorum, Collections.singleton(failingInstance));
    heartbeatContext.suspect(failingInstance);
    // Then the elector is reset to defaults
    assertEquals(clusterContext.getLastElector(), InstanceId.NONE);
    assertEquals(clusterContext.getLastElectorVersion(), ClusterContext.NO_ELECTOR_VERSION);
    // When the elector comes back with an election result
    clusterContext.elected(role1, forQuorum, failingInstance, 9);
    // Then the result is actually respected
    assertEquals(clusterContext.getLastElector(), failingInstance);
    assertEquals(clusterContext.getLastElectorVersion(), 9);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) 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) LinkedList(java.util.LinkedList) Executor(java.util.concurrent.Executor) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) 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