Search in sources :

Example 1 with ObservedClusterMembers

use of org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers in project neo4j by neo4j.

the class ClusterManager method allSeesAllAsJoined.

public static Predicate<ManagedCluster> allSeesAllAsJoined() {
    return new Predicate<ManagedCluster>() {

        @Override
        public boolean test(ManagedCluster cluster) {
            int clusterSize = cluster.size();
            int clusterMembersChecked = 0;
            for (HighlyAvailableGraphDatabase database : cluster.getAllMembers()) {
                clusterMembersChecked++;
                ClusterMembers members = database.getDependencyResolver().resolveDependency(ClusterMembers.class);
                if (count(members.getMembers()) < clusterSize) {
                    return false;
                }
            }
            for (ObservedClusterMembers arbiter : cluster.getArbiters()) {
                clusterMembersChecked++;
                if (count(arbiter.getMembers()) < clusterSize) {
                    return false;
                }
            }
            // Everyone sees everyone else as joined!
            return clusterMembersChecked > 0;
        }

        @Override
        public String toString() {
            return "All instances should see all others as joined";
        }
    };
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) Predicate(java.util.function.Predicate)

Example 2 with ObservedClusterMembers

use of org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers in project neo4j by neo4j.

the class HighAvailabilityMemberStateMachineTest method whenInMasterStateLosingQuorumFromThreeInstancesShouldGoToPending.

@Test
public void whenInMasterStateLosingQuorumFromThreeInstancesShouldGoToPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId other1 = new InstanceId(2);
    InstanceId other2 = new InstanceId(3);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    List<InstanceId> otherInstances = new LinkedList();
    otherInstances.add(other1);
    otherInstances.add(other2);
    ObservedClusterMembers members = mockClusterMembers(me, emptyList(), otherInstances);
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.coordinatorIsElected(me);
    memberListener.memberIsAvailable(MASTER, me, URI.create("ha://whatever"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.MASTER));
    // When
    memberListener.memberIsFailed(new InstanceId(2));
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(true));
    verify(guard, times(1)).require(any(AvailabilityRequirement.class));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) AvailabilityRequirement(org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement) LinkedList(java.util.LinkedList) ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Example 3 with ObservedClusterMembers

use of org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers in project neo4j by neo4j.

the class HighAvailabilityMemberStateMachineTest method whenInToMasterStateLosingQuorumShouldPutInPending.

@Test
public void whenInToMasterStateLosingQuorumShouldPutInPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId other = new InstanceId(2);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    ObservedClusterMembers members = mockClusterMembers(me, emptyList(), singletonList(other));
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.coordinatorIsElected(me);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.TO_MASTER));
    // When
    memberListener.memberIsFailed(new InstanceId(2));
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(true));
    verify(guard, times(1)).require(any(AvailabilityRequirement.class));
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) AvailabilityRequirement(org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement) Test(org.junit.Test)

Example 4 with ObservedClusterMembers

use of org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers in project neo4j by neo4j.

the class HighAvailabilityMemberStateMachineTest method whenInSlaveStateLosingOtherSlaveShouldNotPutInPending.

@Test
public void whenInSlaveStateLosingOtherSlaveShouldNotPutInPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId master = new InstanceId(2);
    InstanceId otherSlave = new InstanceId(3);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    ObservedClusterMembers members = mockClusterMembers(me, singletonList(master), singletonList(otherSlave));
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.memberIsAvailable(MASTER, master, URI.create("ha://whatever"), StoreId.DEFAULT);
    memberListener.memberIsAvailable(SLAVE, me, URI.create("ha://whatever3"), StoreId.DEFAULT);
    memberListener.memberIsAvailable(SLAVE, otherSlave, URI.create("ha://whatever2"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.SLAVE));
    // When
    memberListener.memberIsFailed(otherSlave);
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.SLAVE));
    assertThat(probe.instanceStops, is(false));
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Test(org.junit.Test)

Example 5 with ObservedClusterMembers

use of org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers in project neo4j by neo4j.

the class HighAvailabilityMemberStateMachineTest method whenInMasterStateLosingQuorumFromTwoInstancesShouldRemainMaster.

@Test
public void whenInMasterStateLosingQuorumFromTwoInstancesShouldRemainMaster() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId other = new InstanceId(2);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    ObservedClusterMembers members = mockClusterMembers(me, emptyList(), singletonList(other));
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.coordinatorIsElected(me);
    memberListener.memberIsAvailable(MASTER, me, URI.create("ha://whatever"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.MASTER));
    // When
    memberListener.memberIsFailed(new InstanceId(2));
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.MASTER));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(false));
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Test(org.junit.Test)

Aggregations

ObservedClusterMembers (org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers)11 InstanceId (org.neo4j.cluster.InstanceId)10 Test (org.junit.Test)8 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)8 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)7 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)7 AvailabilityRequirement (org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement)5 ClusterMember (org.neo4j.kernel.ha.cluster.member.ClusterMember)3 ClusterMembers (org.neo4j.kernel.ha.cluster.member.ClusterMembers)3 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Predicate (java.util.function.Predicate)1 ClusterClient (org.neo4j.cluster.client.ClusterClient)1 ClusterMemberAvailability (org.neo4j.cluster.member.ClusterMemberAvailability)1