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());
}
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()));
}
Aggregations