Skip to content

Commit

Permalink
Replace Resolver implementations with library solution (#354)
Browse files Browse the repository at this point in the history
Removes old Resolver implementations.
Removes Resolver "hooks" that were added in core code.
Adds org.burningwave:tools dependency as the preferred solution.
Adds MultimapHostResolver implementation allowing for one-to-many mapping of
hostnames to ips.
Adds MultimapHostResolverProvider as a replacement for ResolverProvider.
Adjusts MockResolverIT to use new replacement.
  • Loading branch information
Bouncheck authored Oct 1, 2024
1 parent c698120 commit d69bdd4
Show file tree
Hide file tree
Showing 22 changed files with 173 additions and 485 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import com.datastax.oss.driver.api.core.metadata.EndPoint;
import com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint;
import com.datastax.oss.driver.internal.core.resolver.Resolver;
import com.datastax.oss.driver.internal.core.resolver.ResolverProvider;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet;
import com.datastax.oss.driver.shaded.guava.common.collect.Sets;
import java.net.InetAddress;
Expand All @@ -37,7 +35,6 @@
/** Utility class to handle the initial contact points passed to the driver. */
public class ContactPoints {
private static final Logger LOG = LoggerFactory.getLogger(ContactPoints.class);
private static Resolver RESOLVER = ResolverProvider.getResolver(ContactPoints.class);

public static Set<EndPoint> merge(
Set<EndPoint> programmaticContactPoints, List<String> configContactPoints, boolean resolve) {
Expand Down Expand Up @@ -75,7 +72,7 @@ private static Set<InetSocketAddress> extract(String spec, boolean resolve) {
return ImmutableSet.of(InetSocketAddress.createUnresolved(host, port));
} else {
try {
InetAddress[] inetAddresses = RESOLVER.getAllByName(host);
InetAddress[] inetAddresses = InetAddress.getAllByName(host);
if (inetAddresses.length > 1) {
LOG.info(
"Contact point {} resolves to multiple addresses, will use them all ({})",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import com.datastax.oss.driver.api.core.addresstranslation.AddressTranslator;
import com.datastax.oss.driver.api.core.context.DriverContext;
import com.datastax.oss.driver.internal.core.resolver.Resolver;
import com.datastax.oss.driver.internal.core.resolver.ResolverProvider;
import com.datastax.oss.driver.internal.core.util.Loggers;
import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down Expand Up @@ -59,8 +57,6 @@
public class Ec2MultiRegionAddressTranslator implements AddressTranslator {

private static final Logger LOG = LoggerFactory.getLogger(Ec2MultiRegionAddressTranslator.class);
private static Resolver RESOLVER =
ResolverProvider.getResolver(Ec2MultiRegionAddressTranslator.class);

private final DirContext ctx;
private final String logPrefix;
Expand Down Expand Up @@ -98,7 +94,7 @@ public InetSocketAddress translate(@NonNull InetSocketAddress socketAddress) {
return socketAddress;
}

InetAddress translatedAddress = RESOLVER.getByName(domainName);
InetAddress translatedAddress = InetAddress.getByName(domainName);
LOG.debug("[{}] Resolved {} to {}", logPrefix, address, translatedAddress);
return new InetSocketAddress(translatedAddress, socketAddress.getPort());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import com.datastax.oss.driver.internal.core.metrics.SessionMetricUpdater;
import com.datastax.oss.driver.internal.core.protocol.FrameDecoder;
import com.datastax.oss.driver.internal.core.protocol.FrameEncoder;
import com.datastax.oss.driver.internal.core.resolver.Resolver;
import com.datastax.oss.driver.internal.core.resolver.ResolverProvider;
import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting;
import com.datastax.oss.driver.shaded.guava.common.base.Preconditions;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
Expand All @@ -70,8 +68,6 @@ public class ChannelFactory {

private static final Logger LOG = LoggerFactory.getLogger(ChannelFactory.class);

private static Resolver RESOLVER = ResolverProvider.getResolver(ChannelFactory.class);

/**
* A value for {@link #productType} that indicates that we are connected to DataStax Cloud. This
* value matches the one defined at DSE DB server side at {@code ProductType.java}.
Expand Down Expand Up @@ -208,7 +204,7 @@ private void connect(

nettyOptions.afterBootstrapInitialized(bootstrap);

ChannelFuture connectFuture = bootstrap.connect(RESOLVER.resolve(endPoint.resolve()));
ChannelFuture connectFuture = bootstrap.connect(endPoint.resolve());

connectFuture.addListener(
cf -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package com.datastax.oss.driver.internal.core.metadata;

import com.datastax.oss.driver.api.core.metadata.EndPoint;
import com.datastax.oss.driver.internal.core.resolver.Resolver;
import com.datastax.oss.driver.internal.core.resolver.ResolverProvider;
import com.datastax.oss.driver.shaded.guava.common.primitives.UnsignedBytes;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.net.InetAddress;
Expand All @@ -32,7 +30,6 @@

public class SniEndPoint implements EndPoint {
private static final AtomicLong OFFSET = new AtomicLong();
private static Resolver RESOLVER = ResolverProvider.getResolver(SniEndPoint.class);

private final InetSocketAddress proxyAddress;
private final String serverName;
Expand All @@ -58,7 +55,7 @@ public String getServerName() {
@Override
public InetSocketAddress resolve() {
try {
InetAddress[] aRecords = RESOLVER.getAllByName(proxyAddress.getHostName());
InetAddress[] aRecords = InetAddress.getAllByName(proxyAddress.getHostName());
if (aRecords.length == 0) {
// Probably never happens, but the JDK docs don't explicitly say so
throw new IllegalArgumentException(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d69bdd4

Please sign in to comment.