Search in sources :

Example 46 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ElectionPerformanceIT method electionPerformance_NormalConditions.

@Test
public void electionPerformance_NormalConditions() throws Throwable {
    /* This test runs with with few iterations. Hence it does not have the power to catch
         * regressions efficiently. Its purpose is mainly to run elections using real-world
         * parameters and catch very obvious regressions while not contributing overly much to the
         * regression test suites total runtime. */
    // given parameters
    final long networkLatency = 15L;
    final long electionTimeout = 500L;
    final long heartbeatInterval = 250L;
    final int iterations = 10;
    TestNetwork net = new TestNetwork<>((i, o) -> networkLatency);
    Set<MemberId> members = asSet(member(0), member(1), member(2));
    Fixture fixture = new Fixture(members, net, electionTimeout, heartbeatInterval);
    DisconnectLeaderScenario scenario = new DisconnectLeaderScenario(fixture, electionTimeout);
    try {
        // when running scenario
        fixture.boot();
        scenario.run(iterations, 10 * electionTimeout);
    } finally {
        fixture.tearDown();
    }
    DisconnectLeaderScenario.Result result = scenario.result();
    /* These bounds have been experimentally established and should have a very low
         * likelihood for false positives without an actual major regression. If this test fails
         * then the recommended action is to run the test manually and interpret the results
         * to guide further action. Perhaps the power of the test has to be improved, but
         * the intention here is not to catch anything but the most major of regressions. */
    assertThat(result.nonCollidingAverage, lessThan(2.0 * electionTimeout));
    if (result.collisionCount > 3) {
        assertThat(result.collidingAverage, lessThan(6.0 * electionTimeout));
    }
    assertThat(result.timeoutCount, is(0L));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) TestNetwork(org.neo4j.causalclustering.messaging.TestNetwork) Test(org.junit.Test)

Example 47 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ElectionUtil method waitForLeaderAgreement.

public static MemberId waitForLeaderAgreement(Iterable<RaftMachine> validRafts, long maxTimeMillis) throws InterruptedException, TimeoutException {
    long viewCount = Iterables.count(validRafts);
    Map<MemberId, MemberId> leaderViews = new HashMap<>();
    CompletableFuture<MemberId> futureAgreedLeader = new CompletableFuture<>();
    Collection<Runnable> destructors = new ArrayList<>();
    for (RaftMachine raft : validRafts) {
        destructors.add(leaderViewUpdatingListener(raft, validRafts, leaderViews, viewCount, futureAgreedLeader));
    }
    try {
        try {
            return futureAgreedLeader.get(maxTimeMillis, TimeUnit.MILLISECONDS);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    } finally {
        destructors.forEach(Runnable::run);
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) CompletableFuture(java.util.concurrent.CompletableFuture) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException)

Example 48 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ClusterState method toString.

@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    for (MemberId member : roles.keySet()) {
        builder.append(member).append(" : ").append(roles.get(member)).append("\n");
        builder.append("  state: ").append(states.get(member)).append("\n");
        builder.append("  queue: ").append(queues.get(member)).append("\n");
    }
    return builder.toString();
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId)

Example 49 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class RaftContentByteBufferMarshalTest method shouldSerializeMemberSet.

@Test
public void shouldSerializeMemberSet() throws Exception {
    // given
    CoreReplicatedContentMarshal serializer = new CoreReplicatedContentMarshal();
    MemberIdSet in = new MemberIdSet(asSet(new MemberId(UUID.randomUUID()), new MemberId(UUID.randomUUID())));
    // when
    ByteBuf buf = Unpooled.buffer();
    assertMarshalingEquality(serializer, buf, in);
}
Also used : CoreReplicatedContentMarshal(org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal) MemberId(org.neo4j.causalclustering.identity.MemberId) MemberIdSet(org.neo4j.causalclustering.core.consensus.membership.MemberIdSet) ByteBuf(io.netty.buffer.ByteBuf) NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) Test(org.junit.Test)

Example 50 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class HazelcastClusterTopology method readReplicas.

private static Map<MemberId, ReadReplicaInfo> readReplicas(HazelcastInstance hazelcastInstance) {
    IMap<String, String> /*boltAddress*/
    clientAddressMap = hazelcastInstance.getMap(READ_REPLICA_BOLT_ADDRESS_MAP_NAME);
    IMap<String, String> txServerMap = hazelcastInstance.getMap(READ_REPLICA_TRANSACTION_SERVER_ADDRESS_MAP_NAME);
    IMap<String, String> memberIdMap = hazelcastInstance.getMap(READ_REPLICA_MEMBER_ID_MAP_NAME);
    MultiMap<String, String> serverGroups = hazelcastInstance.getMultiMap(SERVER_GROUPS_MULTIMAP_NAME);
    Map<MemberId, ReadReplicaInfo> result = new HashMap<>();
    for (String hzUUID : clientAddressMap.keySet()) {
        ClientConnectorAddresses clientConnectorAddresses = ClientConnectorAddresses.fromString(clientAddressMap.get(hzUUID));
        AdvertisedSocketAddress catchupAddress = socketAddress(txServerMap.get(hzUUID), AdvertisedSocketAddress::new);
        result.put(new MemberId(UUID.fromString(memberIdMap.get(hzUUID))), new ReadReplicaInfo(clientConnectorAddresses, catchupAddress, asSet(serverGroups.get(hzUUID))));
    }
    return result;
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress)

Aggregations

MemberId (org.neo4j.causalclustering.identity.MemberId)114 Test (org.junit.Test)83 HashMap (java.util.HashMap)26 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)16 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)15 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)13 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)12 DirectNetworking (org.neo4j.causalclustering.core.consensus.DirectNetworking)10 RaftTestFixture (org.neo4j.causalclustering.core.consensus.RaftTestFixture)10 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)10 Log (org.neo4j.logging.Log)10 ClusterId (org.neo4j.causalclustering.identity.ClusterId)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)8 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)7 ByteBuf (io.netty.buffer.ByteBuf)6 File (java.io.File)6 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 HashSet (java.util.HashSet)5