Search in sources :

Example 51 with MemberId

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

the class HazelcastClusterTopology method getCoreTopology.

static CoreTopology getCoreTopology(HazelcastInstance hazelcastInstance, Config config, Log log) {
    Map<MemberId, CoreServerInfo> coreMembers = emptyMap();
    boolean canBeBootstrapped = false;
    ClusterId clusterId = null;
    if (hazelcastInstance != null) {
        Set<Member> hzMembers = hazelcastInstance.getCluster().getMembers();
        canBeBootstrapped = canBeBootstrapped(hazelcastInstance, config);
        coreMembers = toCoreMemberMap(hzMembers, log, hazelcastInstance);
        clusterId = getClusterId(hazelcastInstance);
    } else {
        log.info("Cannot currently bind to distributed discovery service.");
    }
    return new CoreTopology(clusterId, canBeBootstrapped, coreMembers);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ClusterId(org.neo4j.causalclustering.identity.ClusterId) Member(com.hazelcast.core.Member)

Example 52 with MemberId

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

the class HazelcastClusterTopology method toCoreMemberMap.

static Map<MemberId, CoreServerInfo> toCoreMemberMap(Set<Member> members, Log log, HazelcastInstance hazelcastInstance) {
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    MultiMap<String, String> serverGroupsMMap = hazelcastInstance.getMultiMap(SERVER_GROUPS_MULTIMAP_NAME);
    for (Member member : members) {
        try {
            MemberId memberId = new MemberId(UUID.fromString(member.getStringAttribute(MEMBER_UUID)));
            CoreServerInfo coreServerInfo = new CoreServerInfo(socketAddress(member.getStringAttribute(RAFT_SERVER), AdvertisedSocketAddress::new), socketAddress(member.getStringAttribute(TRANSACTION_SERVER), AdvertisedSocketAddress::new), ClientConnectorAddresses.fromString(member.getStringAttribute(CLIENT_CONNECTOR_ADDRESSES)), asSet(serverGroupsMMap.get(memberId.getUuid().toString())));
            coreMembers.put(memberId, coreServerInfo);
        } catch (IllegalArgumentException e) {
            log.warn("Incomplete member attributes supplied from Hazelcast", e);
        }
    }
    return coreMembers;
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member)

Example 53 with MemberId

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

the class ServerPoliciesPlugin method writeEndpoints.

private List<Endpoint> writeEndpoints(CoreTopology cores) {
    MemberId leader;
    try {
        leader = leaderLocator.getLeader();
    } catch (NoLeaderFoundException e) {
        return emptyList();
    }
    Optional<Endpoint> endPoint = cores.find(leader).map(extractBoltAddress()).map(Endpoint::write);
    return asList(endPoint);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) Endpoint(org.neo4j.causalclustering.load_balancing.Endpoint)

Example 54 with MemberId

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

the class ServerPoliciesPlugin method readEndpoints.

private List<Endpoint> readEndpoints(CoreTopology coreTopology, ReadReplicaTopology rrTopology, Policy policy) {
    Set<ServerInfo> possibleReaders = rrTopology.members().entrySet().stream().map(entry -> new ServerInfo(entry.getValue().connectors().boltAddress(), entry.getKey(), entry.getValue().groups())).collect(Collectors.toSet());
    if (allowReadsOnFollowers || possibleReaders.size() == 0) {
        Set<MemberId> validCores = coreTopology.members().keySet();
        try {
            MemberId leader = leaderLocator.getLeader();
            validCores = validCores.stream().filter(memberId -> !memberId.equals(leader)).collect(Collectors.toSet());
        } catch (NoLeaderFoundException ignored) {
        // we might end up using the leader for reading during this ttl, should be fine in general
        }
        for (MemberId validCore : validCores) {
            Optional<CoreServerInfo> coreServerInfo = coreTopology.find(validCore);
            if (coreServerInfo.isPresent()) {
                CoreServerInfo serverInfo = coreServerInfo.get();
                possibleReaders.add(new ServerInfo(serverInfo.connectors().boltAddress(), validCore, serverInfo.groups()));
            }
        }
    }
    Set<ServerInfo> readers = policy.apply(possibleReaders);
    return readers.stream().map(r -> Endpoint.read(r.boltAddress())).collect(Collectors.toList());
}
Also used : ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) Service(org.neo4j.helpers.Service) LoadBalancingResult(org.neo4j.causalclustering.load_balancing.LoadBalancingResult) Log(org.neo4j.logging.Log) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) Util.asList(org.neo4j.causalclustering.load_balancing.Util.asList) LogProvider(org.neo4j.logging.LogProvider) FilteringPolicyLoader.load(org.neo4j.causalclustering.load_balancing.plugins.server_policies.FilteringPolicyLoader.load) Map(java.util.Map) MemberId(org.neo4j.causalclustering.identity.MemberId) Endpoint(org.neo4j.causalclustering.load_balancing.Endpoint) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) LoadBalancingPlugin(org.neo4j.causalclustering.load_balancing.LoadBalancingPlugin) Config(org.neo4j.kernel.configuration.Config) Collections.emptyList(java.util.Collections.emptyList) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) Optional(java.util.Optional) Util.extractBoltAddress(org.neo4j.causalclustering.load_balancing.Util.extractBoltAddress) MemberId(org.neo4j.causalclustering.identity.MemberId) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo)

Example 55 with MemberId

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

the class CatchUpTest method newMemberWithNoLogShouldCatchUpFromPeers.

@Test
public void newMemberWithNoLogShouldCatchUpFromPeers() throws Throwable {
    DirectNetworking net = new DirectNetworking();
    // given
    final MemberId leaderId = member(0);
    final MemberId sleepyId = member(2);
    final MemberId[] awakeMembers = { leaderId, member(1) };
    final MemberId[] allMembers = { leaderId, member(1), sleepyId };
    RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
    fixture.bootstrap(allMembers);
    fixture.members().withId(leaderId).raftInstance().installCoreState(new RaftCoreState(new MembershipEntry(0, new HashSet<>(Arrays.asList(allMembers)))));
    fixture.members().withId(leaderId).timeoutService().invokeTimeout(RaftMachine.Timeouts.ELECTION);
    net.processMessages();
    final MemberId leader = fixture.members().withId(leaderId).member();
    net.disconnect(sleepyId);
    // when
    fixture.members().withId(leaderId).raftInstance().handle(new Request(leader, valueOf(10)));
    fixture.members().withId(leaderId).raftInstance().handle(new Request(leader, valueOf(20)));
    fixture.members().withId(leaderId).raftInstance().handle(new Request(leader, valueOf(30)));
    fixture.members().withId(leaderId).raftInstance().handle(new Request(leader, valueOf(40)));
    net.processMessages();
    // then
    for (MemberId awakeMember : awakeMembers) {
        assertThat(integerValues(fixture.members().withId(awakeMember).raftLog()), hasItems(10, 20, 30, 40));
    }
    assertThat(integerValues(fixture.members().withId(sleepyId).raftLog()), empty());
    // when
    net.reconnect(sleepyId);
    // TODO: This needs an injectable/controllable timeout service for the log shipper.
    Thread.sleep(500);
    net.processMessages();
    // then
    assertThat(integerValues(fixture.members().withId(sleepyId).raftLog()), hasItems(10, 20, 30, 40));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) Request(org.neo4j.causalclustering.core.consensus.RaftMessages.NewEntry.Request) Test(org.junit.Test)

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