Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add connection health checking to static discovery strategy for WAN [HZ-2888] #25364

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@ public final class MetricDescriptorConstants {
public static final String WAN_METRIC_ACK_DELAY_CURRENT_MILLIS = "ackDelayCurrentMillis";
public static final String WAN_METRIC_ACK_DELAY_LAST_START = "ackDelayLastStart";
public static final String WAN_METRIC_ACK_DELAY_LAST_END = "ackDelayLastEnd";
public static final String WAN_METRIC_CONNECTION_HEALTH = "connectionHealth";
public static final String WAN_DISCRIMINATOR_CONNECTION_ADDRESS = "address";
public static final String WAN_TAG_DISCOVERY_STRATEGY = "discoveryStrategy";
public static final String WAN_QUEUE_FILL_PERCENT = "queueFillPercent";
// ===[/WAN]========================================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

package com.hazelcast.spi.discovery;

import com.hazelcast.cluster.Address;
import com.hazelcast.cluster.Member;
import com.hazelcast.spi.annotation.PrivateApi;
import com.hazelcast.spi.partitiongroup.PartitionGroupStrategy;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

/**
* The <code>DiscoveryStrategy</code> itself is the actual implementation to discover
Expand Down Expand Up @@ -112,4 +116,29 @@ default PartitionGroupStrategy getPartitionGroupStrategy() {
* @since 3.7
*/
Map<String, String> discoverLocalMetadata();

/**
* Marks the passed {@link Address} as unhealthy, which prevents it from being offered as a
* viable endpoint in some {@link DiscoveryStrategy} implementations, usually prompting
* this endpoint to be periodically probed for liveliness. If not supported by the underlying
* implementation, then this call does nothing.
*
* @param address the address to mark as unhealthy
* @since 5.4
*/
@PrivateApi
default void markEndpointAsUnhealthy(Address address) { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would remove these 2 new methods from public api, if target is only using it for wan discovery.
It can be made an implementation detail for wan discovery for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ahmetmircik, I've marked these methods as @PrivateApi in both DiscoveryStrategy and DiscoveryService for now 👍 de3c107


/**
* Fetches a set of {@link Address} marked as unhealthy by the underlying implementation.
* If not supported by the underlying implementation, then this call returns an empty set.
*
* @return set of {@link Address} which are currently marked as unhealthy if supported by the
* underlying implementation, otherwise an empty set.
* @since 5.4
*/
@PrivateApi
default Set<Address> getUnhealthyEndpoints() {
return Collections.emptySet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hazelcast.spi.discovery.impl;

import com.hazelcast.cluster.Address;
import com.hazelcast.config.DiscoveryConfig;
import com.hazelcast.config.DiscoveryStrategyConfig;
import com.hazelcast.config.InvalidConfigurationException;
Expand All @@ -41,8 +42,7 @@

import static com.hazelcast.internal.util.CollectionUtil.nullToEmpty;

public class DefaultDiscoveryService
implements DiscoveryService {
public class DefaultDiscoveryService implements DiscoveryService {

private static final String SERVICE_LOADER_TAG = DiscoveryStrategyFactory.class.getCanonicalName();

Expand Down Expand Up @@ -98,6 +98,28 @@ public void destroy() {
}
}

@Override
public void markEndpointAsUnhealthy(Address address) {
for (DiscoveryStrategy discoveryStrategy : discoveryStrategies) {
discoveryStrategy.markEndpointAsUnhealthy(address);
}
}

@Override
public Set<Address> getUnhealthyEndpoints() {
Set<Address> combinedAddresses = null;
for (DiscoveryStrategy strategy : discoveryStrategies) {
Set<Address> strategyAddresses = strategy.getUnhealthyEndpoints();
if (!strategyAddresses.isEmpty()) {
if (combinedAddresses == null) {
combinedAddresses = new HashSet<>(strategyAddresses.size());
}
combinedAddresses.addAll(strategyAddresses);
}
}
return combinedAddresses == null ? Collections.emptySet() : combinedAddresses;
}

public Iterable<DiscoveryStrategy> getDiscoveryStrategies() {
return discoveryStrategies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.hazelcast.spi.discovery.impl;

import com.hazelcast.cluster.Address;
import com.hazelcast.spi.discovery.DiscoveryNode;
import com.hazelcast.spi.discovery.DiscoveryStrategy;
import com.hazelcast.spi.discovery.integration.DiscoveryService;

import java.util.Map;
import java.util.Set;

import static com.hazelcast.internal.util.Preconditions.checkNotNull;

Expand Down Expand Up @@ -49,8 +51,22 @@ public Map<String, String> discoverLocalMetadata() {
return strategy.discoverLocalMetadata();
}

@Override
public void markEndpointAsUnhealthy(Address address) {
strategy.markEndpointAsUnhealthy(address);
}

@Override
public Set<Address> getUnhealthyEndpoints() {
return strategy.getUnhealthyEndpoints();
}

@Override
public void destroy() {
strategy.destroy();
}

public DiscoveryStrategy getStrategy() {
return strategy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

package com.hazelcast.spi.discovery.integration;

import com.hazelcast.cluster.Address;
import com.hazelcast.cluster.Member;
import com.hazelcast.spi.annotation.PrivateApi;
import com.hazelcast.spi.discovery.DiscoveryNode;
import com.hazelcast.spi.discovery.DiscoveryStrategy;
import com.hazelcast.spi.discovery.NodeFilter;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

/**
* The <code>DiscoveryService</code> interface defines the basic entry point
Expand Down Expand Up @@ -83,4 +87,33 @@ public interface DiscoveryService {
* @since 3.7
*/
Map<String, String> discoverLocalMetadata();

/**
* Marks the passed {@link Address} as unhealthy, which prevents it from being offered as a
* viable endpoint in some {@link DiscoveryStrategy} implementations, usually prompting
* this endpoint to be periodically probed for liveliness. If not supported by the underlying
* implementation, then this call does nothing.
*
* @see DiscoveryStrategy#markEndpointAsUnhealthy(Address)
*
* @param address the address to mark as unhealthy
* @since 5.4
*/
@PrivateApi
default void markEndpointAsUnhealthy(Address address) { }
JamesHazelcast marked this conversation as resolved.
Show resolved Hide resolved

/**
* Fetches a set of {@link Address} marked as unhealthy by the underlying {@link DiscoveryStrategy}.
* If not supported by the underlying implementation, then this call returns an empty set.
*
* @see DiscoveryStrategy#getUnhealthyEndpoints()
*
* @return set of {@link Address} which are currently marked as unhealthy if supported by the
* underlying implementation, otherwise an empty set.
* @since 5.4
*/
@PrivateApi
default Set<Address> getUnhealthyEndpoints() {
return Collections.emptySet();
}
}