use of org.jgroups.protocols.Discovery in project JGroups by belaban.
the class DiscoveryTest method testLeak.
protected static void testLeak(JChannel discovery_initiator) throws Exception {
ProtocolStack stack = discovery_initiator.getProtocolStack();
Discovery ping = stack.findProtocol(Discovery.class);
ping.discoveryRspExpiryTime(1000);
Field ping_rsps_field = Util.getField(Discovery.class, "ping_responses");
Map<Long, Responses> ping_rsps = (Map<Long, Responses>) Util.getField(ping_rsps_field, ping);
for (int i = 1; i <= 10; i++) {
ping.down(new Event(Event.FIND_INITIAL_MBRS, 1000L));
}
for (int i = 0; i < 10; i++) {
Util.sleep(500);
ping.weedOutCompletedDiscoveryResponses();
if (ping_rsps.isEmpty())
break;
System.out.printf("responses map has %d elements:\n%s\n", ping_rsps.size(), print(ping_rsps));
}
assert ping_rsps.isEmpty() : String.format("responses map has %d elements:\n%s\n", ping_rsps.size(), print(ping_rsps));
}
use of org.jgroups.protocols.Discovery in project jgroups-kubernetes by jgroups-extras.
the class KUBE_PING method findMembers.
public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) {
List<Pod> hosts = readAll();
List<PhysicalAddress> cluster_members = new ArrayList<>(hosts != null ? hosts.size() : 16);
PhysicalAddress physical_addr = null;
PingData data = null;
physical_addr = getCurrentPhysicalAddress(local_addr);
// https://issues.jboss.org/browse/JGRP-1670
data = new PingData(local_addr, false, NameCache.get(local_addr), physical_addr);
if (members != null && members.size() <= max_members_in_discovery_request)
data.mbrs(members);
if (hosts != null) {
if (log.isTraceEnabled())
log.trace("%s: hosts fetched from Kubernetes: %s", local_addr, hosts);
for (Pod host : hosts) {
if (!host.isReady() && !useNotReadyAddresses)
continue;
for (int i = 0; i <= port_range; i++) {
try {
IpAddress addr = new IpAddress(host.getIp(), tp_bind_port + i);
if (!cluster_members.contains(addr))
cluster_members.add(addr);
} catch (Exception ex) {
log.warn("failed translating host %s into InetAddress: %s", host, ex);
}
}
}
}
if (use_disk_cache) {
// this only makes sense if we have PDC below us
Collection<PhysicalAddress> list = (Collection<PhysicalAddress>) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESSES));
if (list != null)
list.stream().filter(phys_addr -> !cluster_members.contains(phys_addr)).forEach(cluster_members::add);
}
if (split_clusters_during_rolling_update) {
if (physical_addr != null) {
String senderIp = ((IpAddress) physical_addr).getIpAddress().getHostAddress();
// Please note we search for sender parent group through all pods, ever not ready. It's because JGroup discovery is performed
// before WildFly can respond to http readiness probe.
hosts.stream().filter(p -> p.getPodGroup() == null).forEach(p -> log.warn("Pod %s doesn't have group assigned. Impossible to reliably determine pod group during Rolling Update."));
String senderPodGroup = hosts.stream().filter(pod -> senderIp.contains(pod.getIp())).map(Pod::getPodGroup).findFirst().orElse(null);
if (senderPodGroup != null) {
Set<String> allowedAddresses = hosts.stream().filter(pod -> senderPodGroup.equals(pod.getPodGroup())).map(Pod::getIp).collect(Collectors.toSet());
for (Iterator<PhysicalAddress> memberIterator = cluster_members.iterator(); memberIterator.hasNext(); ) {
IpAddress podAddress = (IpAddress) memberIterator.next();
if (!allowedAddresses.contains(podAddress.getIpAddress().getHostAddress())) {
log.trace("removing pod %s from cluster members list since its parent domain is different than senders (%s). Allowed hosts: %s", podAddress, senderPodGroup, allowedAddresses);
memberIterator.remove();
}
}
} else {
log.warn("split_clusters_during_rolling_update is set to 'true' but can't obtain local node parent deployment. All nodes will be placed in the same cluster.");
}
} else {
log.warn("split_clusters_during_rolling_update is set to 'true' but can't obtain local node IP address. All nodes will be placed in the same cluster.");
}
}
if (log.isTraceEnabled())
log.trace("%s: sending discovery requests to %s", local_addr, cluster_members);
PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name).initialDiscovery(initial_discovery);
for (final PhysicalAddress addr : cluster_members) {
if (// no need to send the request to myself
addr.equals(physical_addr))
continue;
// the message needs to be DONT_BUNDLE, see explanation above
final Message msg = new BytesMessage(addr).setFlag(Message.Flag.DONT_BUNDLE, Message.Flag.OOB).putHeader(this.id, hdr);
if (data != null)
msg.setArray(marshal(data));
if (async_discovery_use_separate_thread_per_request)
timer.execute(() -> sendDiscoveryRequest(msg), sends_can_block);
else
sendDiscoveryRequest(msg);
}
}
Aggregations