diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 08bfc3c23..a62438986 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -25,7 +25,7 @@ dependencies { ### Direct Download and Installation -You can use pre-compiled packages that can be downloaded directly from [GitHub Releases](https://github.com/aws/aws-advanced-jdbc-wrapper/releases) or [Maven Central](https://search.maven.org/search?q=g:software.amazon.jdbc) to install the AWS JDBC Driver. After downloading the AWS JDBC Driver, install it by including the .jar file in the application's CLASSPATH. +You can use pre-compiled packages that can be downloaded directly from [GitHub Releases](https://github.com/aws/aws-advanced-jdbc-wrapper/releases) or [Maven Central](https://central.sonatype.com/artifact/software.amazon.jdbc/aws-advanced-jdbc-wrapper) to install the AWS JDBC Driver. After downloading the AWS JDBC Driver, install it by including the .jar file in the application's CLASSPATH. For example, the following command uses wget to download the wrapper: @@ -43,7 +43,7 @@ export CLASSPATH=$CLASSPATH:/home/userx/libs/aws-advanced-jdbc-wrapper-2.6.3.jar ### As a Maven Dependency -You can use [Maven's dependency management](https://search.maven.org/search?q=g:software.amazon.jdbc) to obtain the AWS JDBC Driver by adding the following configuration to the application's Project Object Model (POM) file: +You can use [Maven's dependency management](https://central.sonatype.com/artifact/software.amazon.jdbc/aws-advanced-jdbc-wrapper) to obtain the AWS JDBC Driver by adding the following configuration to the application's Project Object Model (POM) file: ```xml @@ -57,7 +57,7 @@ You can use [Maven's dependency management](https://search.maven.org/search?q=g: ### As a Gradle Dependency -You can use [Gradle's dependency management](https://search.maven.org/search?q=g:software.amazon.jdbc) to obtain the AWS JDBC Driver by adding the following configuration to the application's ```build.gradle``` file: +You can use [Gradle's dependency management](https://central.sonatype.com/artifact/software.amazon.jdbc/aws-advanced-jdbc-wrapper) to obtain the AWS JDBC Driver by adding the following configuration to the application's ```build.gradle``` file: ```gradle dependencies { diff --git a/wrapper/src/main/java/software/amazon/jdbc/PartialPluginService.java b/wrapper/src/main/java/software/amazon/jdbc/PartialPluginService.java index 67027195b..74aa8be49 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/PartialPluginService.java +++ b/wrapper/src/main/java/software/amazon/jdbc/PartialPluginService.java @@ -143,11 +143,11 @@ public HostSpec getCurrentHostSpec() { this.currentHostSpec = this.getWriter(this.getAllHosts()); final List allowedHosts = this.getHosts(); - if (!Utils.containsUrl(allowedHosts, this.currentHostSpec.getUrl())) { + if (!Utils.containsHostAndPort(allowedHosts, this.currentHostSpec.getHostAndPort())) { throw new RuntimeException( Messages.get("PluginServiceImpl.currentHostNotAllowed", new Object[] { - currentHostSpec == null ? "" : currentHostSpec.getUrl(), + currentHostSpec == null ? "" : currentHostSpec.getHostAndPort(), Utils.logTopology(allowedHosts, "")}) ); } diff --git a/wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java b/wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java index 38695c144..02d3f8e0b 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java +++ b/wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java @@ -182,11 +182,11 @@ public HostSpec getCurrentHostSpec() { this.currentHostSpec = this.getWriter(this.getAllHosts()); final List allowedHosts = this.getHosts(); - if (!Utils.containsUrl(allowedHosts, this.currentHostSpec.getUrl())) { + if (!Utils.containsHostAndPort(allowedHosts, this.currentHostSpec.getHostAndPort())) { throw new RuntimeException( Messages.get("PluginServiceImpl.currentHostNotAllowed", new Object[] { - currentHostSpec == null ? "" : currentHostSpec.getUrl(), + currentHostSpec == null ? "" : currentHostSpec.getHostAndPort(), Utils.logTopology(allowedHosts, "")}) ); } diff --git a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java index e1ef01aec..738eebcc3 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java +++ b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java @@ -27,13 +27,11 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Properties; -import java.util.Set; import java.util.UUID; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; @@ -318,11 +316,6 @@ protected void suggestPrimaryCluster(final @NonNull List primaryCluste return; } - final Set primaryClusterHostUrls = new HashSet<>(); - for (final HostSpec hostSpec : primaryClusterHosts) { - primaryClusterHostUrls.add(hostSpec.getUrl()); - } - Map entries = this.servicesContainer.getStorageService().getEntries(Topology.class); if (entries == null) { return; @@ -342,7 +335,7 @@ protected void suggestPrimaryCluster(final @NonNull List primaryCluste // The entry is non-primary for (final HostSpec host : clusterHosts) { - if (primaryClusterHostUrls.contains(host.getUrl())) { + if (Utils.containsHostAndPort(primaryClusterHosts, host.getHostAndPort())) { // Instance on this cluster matches with one of the instance on primary cluster // Suggest the primary clusterId to this entry suggestedPrimaryClusterIdCache.put(clusterId, this.clusterId, diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraConnectionTrackerPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraConnectionTrackerPlugin.java index 6d851b92f..16f1dcb71 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraConnectionTrackerPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraConnectionTrackerPlugin.java @@ -156,13 +156,16 @@ private void checkWriterChanged(boolean needRefreshHostLists) { // do nothing } } + final HostSpec hostSpecAfterFailover = this.getWriter(this.pluginService.getAllHosts()); + if (hostSpecAfterFailover == null) { + return; + } if (this.currentWriter == null) { this.currentWriter = hostSpecAfterFailover; this.needUpdateCurrentWriter = false; - - } else if (!this.currentWriter.equals(hostSpecAfterFailover)) { + } else if (!this.currentWriter.getHostAndPort().equals(hostSpecAfterFailover.getHostAndPort())) { // the writer's changed tracker.invalidateAllConnections(this.currentWriter); tracker.logOpenedConnections(); diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/ClusterAwareWriterFailoverHandler.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/ClusterAwareWriterFailoverHandler.java index 47f741b5e..eece0d519 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/ClusterAwareWriterFailoverHandler.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/ClusterAwareWriterFailoverHandler.java @@ -452,7 +452,7 @@ private boolean isSame(final HostSpec hostSpec1, final HostSpec hostSpec2) { return false; } - return hostSpec1.getUrl().equals(hostSpec2.getUrl()); + return hostSpec1.getHostAndPort().equals(hostSpec2.getHostAndPort()); } private boolean connectToWriter(final HostSpec writerCandidate) { diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java index 8c16484ea..a4d304e99 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java @@ -744,7 +744,7 @@ protected void failoverWriter() throws SQLException { } final List allowedHosts = this.pluginService.getHosts(); - if (!Utils.containsUrl(allowedHosts, writerHostSpec.getUrl())) { + if (!Utils.containsHostAndPort(allowedHosts, writerHostSpec.getHostAndPort())) { throwFailoverFailedException( Messages.get("Failover.newWriterNotAllowed", new Object[] {writerHostSpec.getUrl(), Utils.logTopology(allowedHosts, "")})); diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java index d3a53396b..76a0ec244 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java @@ -560,7 +560,7 @@ protected void failoverWriter() throws SQLException { } final List allowedHosts = this.pluginService.getHosts(); - if (!Utils.containsUrl(allowedHosts, writerCandidate.getUrl())) { + if (!Utils.containsHostAndPort(allowedHosts, writerCandidate.getHostAndPort())) { if (this.failoverWriterFailedCounter != null) { this.failoverWriterFailedCounter.inc(); } diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java index 44f5b8a97..1c91bb9a8 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java @@ -109,7 +109,7 @@ public void establishConnection(final LimitlessConnectionContext context) throws } } - if (context.getLimitlessRouters().contains(context.getHostSpec())) { + if (Utils.containsHostAndPort(context.getLimitlessRouters(), context.getHostSpec().getHostAndPort())) { LOGGER.finest(Messages.get( "LimitlessRouterServiceImpl.connectWithHost", new Object[] {context.getHostSpec().getHost()})); diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java index 7a2955843..0e660f1dc 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java @@ -420,7 +420,7 @@ private void switchToReaderConnection(final List hosts) return; } - if (this.readerHostSpec != null && !hosts.contains(this.readerHostSpec)) { + if (this.readerHostSpec != null && !Utils.containsHostAndPort(hosts, this.readerHostSpec.getHostAndPort())) { // The old reader cannot be used anymore because it is no longer in the list of allowed hosts. closeConnectionIfIdle(this.readerConnection); } diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java index ffcaaef82..0910c5d57 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java @@ -139,11 +139,11 @@ public Connection getVerifiedConnection( } final List allowedHosts = this.pluginService.getHosts(); - if (!Utils.containsUrl(allowedHosts, this.writerHostSpec.getUrl())) { + if (!Utils.containsHostAndPort(allowedHosts, this.writerHostSpec.getHostAndPort())) { throw new SQLException( Messages.get("AuroraStaleDnsHelper.currentWriterNotAllowed", new Object[] { - this.writerHostSpec == null ? "" : this.writerHostSpec.getUrl(), + this.writerHostSpec == null ? "" : this.writerHostSpec.getHostAndPort(), Utils.logTopology(allowedHosts, "")}) ); } diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/strategy/fastestresponse/FastestResponseStrategyPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/strategy/fastestresponse/FastestResponseStrategyPlugin.java index 9c5377a79..f9ae41b6d 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/strategy/fastestresponse/FastestResponseStrategyPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/strategy/fastestresponse/FastestResponseStrategyPlugin.java @@ -145,7 +145,7 @@ public HostSpec getHostSpecByStrategy(final HostRole role, final String strategy if (fastestResponseHost != null) { // Found a fastest host. Let find it in the latest topology. HostSpec foundHostSpec = this.pluginService.getHosts().stream() - .filter(x -> x.equals(fastestResponseHost)) + .filter(x -> x.getHostAndPort().equals(fastestResponseHost.getHostAndPort())) .findAny() .orElse(null); diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/strategy/fastestresponse/HostResponseTimeServiceImpl.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/strategy/fastestresponse/HostResponseTimeServiceImpl.java index 623e9b2e0..588dcec5f 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/strategy/fastestresponse/HostResponseTimeServiceImpl.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/strategy/fastestresponse/HostResponseTimeServiceImpl.java @@ -20,15 +20,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import java.util.Set; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.NonNull; import software.amazon.jdbc.HostSpec; import software.amazon.jdbc.PluginService; import software.amazon.jdbc.util.FullServicesContainer; import software.amazon.jdbc.util.Messages; -import software.amazon.jdbc.util.storage.SlidingExpirationCacheWithCleanupThread; +import software.amazon.jdbc.util.Utils; public class HostResponseTimeServiceImpl implements HostResponseTimeService { @@ -66,13 +64,13 @@ public int getResponseTime(HostSpec hostSpec) { @Override public void setHosts(final @NonNull List hosts) { - Set oldHosts = this.hosts.stream().map(HostSpec::getUrl).collect(Collectors.toSet()); + List oldHosts = this.hosts; this.hosts = hosts; // Going through all hosts in the topology and trying to find new ones. this.hosts.stream() // hostSpec is not in the set of hosts that already being monitored - .filter(hostSpec -> !oldHosts.contains(hostSpec.getUrl())) + .filter(hostSpec -> !Utils.containsHostAndPort(oldHosts, hostSpec.getHostAndPort())) .forEach(hostSpec -> { try { this.servicesContainer.getMonitorService().runIfAbsent( diff --git a/wrapper/src/main/java/software/amazon/jdbc/util/Utils.java b/wrapper/src/main/java/software/amazon/jdbc/util/Utils.java index 4927ac323..446c0f603 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/util/Utils.java +++ b/wrapper/src/main/java/software/amazon/jdbc/util/Utils.java @@ -26,9 +26,13 @@ public static boolean isNullOrEmpty(final Collection c) { return c == null || c.isEmpty(); } - public static boolean containsUrl(final List hosts, String url) { + public static boolean containsHostAndPort(final Collection hosts, String hostAndPort) { + if (Utils.isNullOrEmpty(hosts)) { + return false; + } + for (final HostSpec hostSpec : hosts) { - if (hostSpec.getUrl().equals(url)) { + if (hostSpec.getHostAndPort().equals(hostAndPort)) { return true; } }