Search in sources :

Example 26 with InstanceId

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

the class HeartbeatContextImpl method checkSuspectEverybody.

/**
     * Returns true iff this instance suspects every other instance currently in the cluster, except for itself.
     */
private boolean checkSuspectEverybody() {
    Map<InstanceId, URI> allClusterMembers = getMembers();
    Set<InstanceId> suspectedInstances = getSuspicionsFor(getMyId());
    int suspected = 0;
    for (InstanceId suspectedInstance : suspectedInstances) {
        if (allClusterMembers.containsKey(suspectedInstance)) {
            suspected++;
        }
    }
    return suspected == allClusterMembers.size() - 1;
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) URI(java.net.URI)

Example 27 with InstanceId

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

the class ClusterMembersSnapshotTest method snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromSlaveToMaster.

@Test
public void snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromSlaveToMaster() throws Exception {
    // GIVEN
    // -- a snapshot containing one member with a role
    ClusterMembersSnapshot snapshot = new ClusterMembersSnapshot(new HANewSnapshotFunction());
    URI clusterUri = new URI(URI);
    InstanceId instanceId = new InstanceId(1);
    MemberIsAvailable event1 = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
    snapshot.availableMember(event1);
    // WHEN
    // -- the same member, although different role, gets added to the snapshot
    MemberIsAvailable event2 = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
    snapshot.availableMember(event2);
    // THEN
    // -- getting the snapshot list should reveal both
    assertEquals(1, Iterables.count(snapshot.getCurrentAvailable(instanceId)));
    assertThat(snapshot.getCurrentAvailable(instanceId), hasItems(memberIsAvailable(event2)));
    assertEquals(1, Iterables.count(snapshot.getCurrentAvailableMembers()));
    assertThat(snapshot.getCurrentAvailableMembers(), hasItems(memberIsAvailable(event2)));
}
Also used : HANewSnapshotFunction(org.neo4j.kernel.ha.cluster.HANewSnapshotFunction) InstanceId(org.neo4j.cluster.InstanceId) MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) ClusterMembersSnapshot(org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot) URI(java.net.URI) Test(org.junit.Test)

Example 28 with InstanceId

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

the class ClusterMembersSnapshotTest method snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave.

@Test
public void snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave() throws Exception {
    // GIVEN
    // -- a snapshot containing one member with a role
    ClusterMembersSnapshot snapshot = new ClusterMembersSnapshot(new HANewSnapshotFunction());
    URI clusterUri = new URI(URI);
    InstanceId instanceId = new InstanceId(1);
    MemberIsAvailable event1 = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
    snapshot.availableMember(event1);
    // WHEN
    // -- the same member, although different role, gets added to the snapshot
    MemberIsAvailable event2 = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
    snapshot.availableMember(event2);
    // THEN
    // -- getting the snapshot list should reveal both
    assertEquals(1, Iterables.count(snapshot.getCurrentAvailable(instanceId)));
    assertThat(snapshot.getCurrentAvailable(instanceId), hasItems(memberIsAvailable(event2)));
    assertEquals(1, Iterables.count(snapshot.getCurrentAvailableMembers()));
    assertThat(snapshot.getCurrentAvailableMembers(), hasItems(memberIsAvailable(event2)));
}
Also used : HANewSnapshotFunction(org.neo4j.kernel.ha.cluster.HANewSnapshotFunction) InstanceId(org.neo4j.cluster.InstanceId) MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) ClusterMembersSnapshot(org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot) URI(java.net.URI) Test(org.junit.Test)

Example 29 with InstanceId

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

the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException.

@Test
public void givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException() throws Throwable {
    // Given
    ManagedCluster cluster = clusterRule.startCluster();
    Node node;
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        node = master.createNode();
        tx.success();
    }
    // When
    HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
    try (Transaction tx = readOnlySlave.beginTx()) {
        Node slaveNode = readOnlySlave.getNodeById(node.getId());
        // Then
        slaveNode.addLabel(Label.label("FOO"));
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ex) {
    // Ok!
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) InstanceId(org.neo4j.cluster.InstanceId) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 30 with InstanceId

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

the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails.

@Test
public void givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails() throws Throwable {
    // When
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
    try (Transaction tx = readOnlySlave.beginTx()) {
        readOnlySlave.createNode();
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ex) {
    // Then
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) InstanceId(org.neo4j.cluster.InstanceId) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) 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