Search in sources :

Example 6 with NoLeaderFoundException

use of org.neo4j.causalclustering.core.consensus.NoLeaderFoundException 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 7 with NoLeaderFoundException

use of org.neo4j.causalclustering.core.consensus.NoLeaderFoundException in project neo4j by neo4j.

the class ClusterOverviewProcedure method apply.

@Override
public RawIterator<Object[], ProcedureException> apply(Context ctx, Object[] input) throws ProcedureException {
    List<ReadWriteEndPoint> endpoints = new ArrayList<>();
    CoreTopology coreTopology = topologyService.coreServers();
    Set<MemberId> coreMembers = coreTopology.members().keySet();
    MemberId leader = null;
    try {
        leader = leaderLocator.getLeader();
    } catch (NoLeaderFoundException e) {
        log.debug("No write server found. This can happen during a leader switch.");
    }
    for (MemberId memberId : coreMembers) {
        Optional<CoreServerInfo> coreServerInfo = coreTopology.find(memberId);
        if (coreServerInfo.isPresent()) {
            Role role = memberId.equals(leader) ? Role.LEADER : Role.FOLLOWER;
            endpoints.add(new ReadWriteEndPoint(coreServerInfo.get().connectors(), role, memberId.getUuid(), asList(coreServerInfo.get().groups())));
        } else {
            log.debug("No Address found for " + memberId);
        }
    }
    for (Map.Entry<MemberId, ReadReplicaInfo> readReplica : topologyService.readReplicas().members().entrySet()) {
        ReadReplicaInfo readReplicaInfo = readReplica.getValue();
        endpoints.add(new ReadWriteEndPoint(readReplicaInfo.connectors(), Role.READ_REPLICA, readReplica.getKey().getUuid(), asList(readReplicaInfo.groups())));
    }
    endpoints.sort(comparing(o -> o.addresses().toString()));
    return map((endpoint) -> new Object[] { endpoint.memberId().toString(), endpoint.addresses().uriList().stream().map(URI::toString).toArray(), endpoint.role().name(), endpoint.groups() }, asRawIterator(endpoints.iterator()));
}
Also used : ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Neo4jTypes(org.neo4j.kernel.api.proc.Neo4jTypes) Log(org.neo4j.logging.Log) RawIterator(org.neo4j.collection.RawIterator) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) LogProvider(org.neo4j.logging.LogProvider) ArrayList(java.util.ArrayList) Iterators.asRawIterator(org.neo4j.helpers.collection.Iterators.asRawIterator) Map(java.util.Map) MemberId(org.neo4j.causalclustering.identity.MemberId) URI(java.net.URI) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) Comparator.comparing(java.util.Comparator.comparing) ProcedureSignature.procedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) Iterators.map(org.neo4j.helpers.collection.Iterators.map) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Set(java.util.Set) UUID(java.util.UUID) Iterables.asList(org.neo4j.helpers.collection.Iterables.asList) List(java.util.List) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Optional(java.util.Optional) Context(org.neo4j.kernel.api.proc.Context) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) ArrayList(java.util.ArrayList) URI(java.net.URI) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) MemberId(org.neo4j.causalclustering.identity.MemberId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) Map(java.util.Map)

Aggregations

NoLeaderFoundException (org.neo4j.causalclustering.core.consensus.NoLeaderFoundException)7 MemberId (org.neo4j.causalclustering.identity.MemberId)5 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)4 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)3 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)3 Log (org.neo4j.logging.Log)3 LogProvider (org.neo4j.logging.LogProvider)3 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 ExecutionException (java.util.concurrent.ExecutionException)2 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)2 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)2 Endpoint (org.neo4j.causalclustering.load_balancing.Endpoint)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 Comparator.comparing (java.util.Comparator.comparing)1 HashMap (java.util.HashMap)1