Search in sources :

Example 61 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class HeartbeatRefreshProcessor method process.

@Override
public boolean process(Message<? extends MessageType> message) {
    if (!message.isInternal() && !message.getMessageType().equals(HeartbeatMessage.i_am_alive)) {
        try {
            String to = message.getHeader(Message.TO);
            InstanceId serverId = clusterContext.getConfiguration().getIdForUri(new URI(to));
            if (!clusterContext.isMe(serverId)) {
                outgoing.offer(Message.internal(HeartbeatMessage.reset_send_heartbeat, serverId));
            }
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    return true;
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 62 with InstanceId

use of org.neo4j.cluster.InstanceId 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 63 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class MultiPaxosServer method config.

public void config() {
    ClusterConfiguration configuration = ((ClusterContext) server.getStateMachines().getStateMachine(ClusterMessage.class).getContext()).getConfiguration();
    Collection<InstanceId> failed = ((HeartbeatContext) server.getStateMachines().getStateMachine(HeartbeatMessage.class).getContext()).getFailed();
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration)

Example 64 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class InstanceIdTest method nodeTriesToJoinRunningClusterWithExistingServerId.

@Test
public void nodeTriesToJoinRunningClusterWithExistingServerId() throws InterruptedException, ExecutionException, TimeoutException, URISyntaxException {
    List<URI> correctMembers = new ArrayList<>();
    correctMembers.add(URI.create("server1"));
    correctMembers.add(URI.create("server2"));
    correctMembers.add(URI.create("server3"));
    Map<String, InstanceId> roles = new HashMap<>();
    roles.put("coordinator", new InstanceId(1));
    testCluster(new int[] { 1, 2, 3, 3 }, new VerifyInstanceConfiguration[] { new VerifyInstanceConfiguration(correctMembers, roles, Collections.emptySet()), new VerifyInstanceConfiguration(correctMembers, roles, Collections.emptySet()), new VerifyInstanceConfiguration(correctMembers, roles, Collections.emptySet()), new VerifyInstanceConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptySet()) }, DEFAULT_NETWORK(), new ClusterTestScriptDSL().rounds(600).join(100, 1, 1).join(100, 2, 1).join(100, 3, 1).join(5000, 4, 1).message(0, "*** Conflicting node tried to join"));
}
Also used : VerifyInstanceConfiguration(org.neo4j.cluster.VerifyInstanceConfiguration) HashMap(java.util.HashMap) InstanceId(org.neo4j.cluster.InstanceId) ArrayList(java.util.ArrayList) URI(java.net.URI) Test(org.junit.Test)

Example 65 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class ElectionContextTest method testElectionOkLessThanQuorumFailed.

@Test
public void testElectionOkLessThanQuorumFailed() {
    Set<InstanceId> failed = new HashSet<InstanceId>();
    failed.add(new InstanceId(1));
    baseTestForElectionOk(failed, false);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

InstanceId (org.neo4j.cluster.InstanceId)154 Test (org.junit.Test)129 URI (java.net.URI)47 Config (org.neo4j.kernel.configuration.Config)37 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)36 Timeouts (org.neo4j.cluster.timeout.Timeouts)32 Executor (java.util.concurrent.Executor)28 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)28 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)27 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)27 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)27 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)24 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)18 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)16 Message (org.neo4j.cluster.com.message.Message)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 ClusterMemberAvailability (org.neo4j.cluster.member.ClusterMemberAvailability)13 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)12 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)12