Search in sources :

Example 1 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HardKillIT method testMasterSwitchHappensOnKillMinus9.

@Test
public void testMasterSwitchHappensOnKillMinus9() throws Exception {
    Process proc = null;
    HighlyAvailableGraphDatabase dbWithId2 = null, dbWithId3 = null, oldMaster = null;
    try {
        proc = run(1);
        dbWithId2 = startDb(2, path(2));
        dbWithId3 = startDb(3, path(3));
        waitUntilAllProperlyAvailable(dbWithId2, 1, MASTER, 2, SLAVE, 3, SLAVE);
        waitUntilAllProperlyAvailable(dbWithId3, 1, MASTER, 2, SLAVE, 3, SLAVE);
        final CountDownLatch newMasterAvailableLatch = new CountDownLatch(1);
        dbWithId2.getDependencyResolver().resolveDependency(ClusterClient.class).addAtomicBroadcastListener(new AtomicBroadcastListener() {

            @Override
            public void receive(Payload value) {
                try {
                    Object event = new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory()).receive(value);
                    if (event instanceof MemberIsAvailable) {
                        if (HighAvailabilityModeSwitcher.MASTER.equals(((MemberIsAvailable) event).getRole())) {
                            newMasterAvailableLatch.countDown();
                        }
                    }
                } catch (Exception e) {
                    fail(e.toString());
                }
            }
        });
        proc.destroy();
        proc = null;
        assertTrue(newMasterAvailableLatch.await(60, SECONDS));
        assertTrue(dbWithId2.isMaster());
        assertTrue(!dbWithId3.isMaster());
        // Ensure that everyone has marked the killed instance as failed, otherwise it cannot rejoin
        waitUntilAllProperlyAvailable(dbWithId2, 1, UNKNOWN, 2, MASTER, 3, SLAVE);
        waitUntilAllProperlyAvailable(dbWithId3, 1, UNKNOWN, 2, MASTER, 3, SLAVE);
        oldMaster = startDb(1, path(1));
        long oldMasterNode = createNamedNode(oldMaster, "Old master");
        assertEquals(oldMasterNode, getNamedNode(dbWithId2, "Old master"));
    } finally {
        if (proc != null) {
            proc.destroy();
        }
        if (oldMaster != null) {
            oldMaster.shutdown();
        }
        if (dbWithId2 != null) {
            dbWithId2.shutdown();
        }
        if (dbWithId3 != null) {
            dbWithId3.shutdown();
        }
    }
}
Also used : AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBroadcastListener(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastListener) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) IOException(java.io.IOException) ClusterClient(org.neo4j.cluster.client.ClusterClient) Payload(org.neo4j.cluster.protocol.atomicbroadcast.Payload) Test(org.junit.Test)

Example 2 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HANewSnapshotFunctionTest method instanceBeingMasterReappearsAsSlaveShouldBeTreatedAsSlave.

@Test
public void instanceBeingMasterReappearsAsSlaveShouldBeTreatedAsSlave() throws Exception {
    // GIVEN these events
    List<MemberIsAvailable> events = new LinkedList<>();
    events.add(roleForId(MASTER, 1));
    events.add(roleForId(SLAVE, 2));
    events.add(roleForId(SLAVE, 1));
    events.add(roleForId(SLAVE, 3));
    // and this expected outcome
    List<MemberIsAvailable> expected = new LinkedList<>();
    expected.add(roleForId(SLAVE, 2));
    expected.add(roleForId(SLAVE, 1));
    expected.add(roleForId(SLAVE, 3));
    // WHEN events start getting added
    Iterable<MemberIsAvailable> result = new LinkedList<>();
    for (MemberIsAvailable event : events) {
        result = new HANewSnapshotFunction().apply(result, event);
    }
    // THEN the result should be the expected one
    eventsMatch(result, expected);
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HANewSnapshotFunctionTest method instanceBeingBackupRepeatedlyShouldRemainBackupOnceOnly.

@Test
public void instanceBeingBackupRepeatedlyShouldRemainBackupOnceOnly() throws Exception {
    // GIVEN these events
    List<MemberIsAvailable> events = new LinkedList<>();
    events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
    events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
    events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
    events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
    // and this expected outcome
    List<MemberIsAvailable> expected = new LinkedList<>();
    expected.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
    // WHEN events start getting added
    Iterable<MemberIsAvailable> result = new LinkedList<>();
    for (MemberIsAvailable event : events) {
        result = new HANewSnapshotFunction().apply(result, event);
    }
    // THEN the result should be the expected one
    eventsMatch(result, expected);
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HANewSnapshotFunctionTest method instanceBeingMasterReplacedByAnotherInstanceShouldNotRemainMaster.

@Test
public void instanceBeingMasterReplacedByAnotherInstanceShouldNotRemainMaster() throws Exception {
    // GIVEN these events
    List<MemberIsAvailable> events = new LinkedList<>();
    events.add(roleForId(MASTER, 1));
    events.add(roleForId(MASTER, 2));
    events.add(roleForId(SLAVE, 3));
    // and this expected outcome
    List<MemberIsAvailable> expected = new LinkedList<>();
    expected.add(roleForId(MASTER, 2));
    expected.add(roleForId(SLAVE, 3));
    // WHEN events start getting added
    Iterable<MemberIsAvailable> result = new LinkedList<>();
    for (MemberIsAvailable event : events) {
        result = new HANewSnapshotFunction().apply(result, event);
    }
    // THEN the result should be the expected one
    eventsMatch(result, expected);
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable 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)

Aggregations

MemberIsAvailable (org.neo4j.cluster.member.paxos.MemberIsAvailable)18 Test (org.junit.Test)16 LinkedList (java.util.LinkedList)8 URI (java.net.URI)5 InstanceId (org.neo4j.cluster.InstanceId)5 ClusterMembersSnapshot (org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot)5 HANewSnapshotFunction (org.neo4j.kernel.ha.cluster.HANewSnapshotFunction)4 IOException (java.io.IOException)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ClusterClient (org.neo4j.cluster.client.ClusterClient)1 PaxosClusterMemberEvents (org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents)1 AtomicBroadcastListener (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastListener)1 AtomicBroadcastSerializer (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer)1 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)1 Payload (org.neo4j.cluster.protocol.atomicbroadcast.Payload)1