Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
<dependencies>
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ public HostSpec getCurrentHostSpec() {

this.currentHostSpec = this.getWriter(this.getAllHosts());
final List<HostSpec> 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 ? "<null>" : currentHostSpec.getUrl(),
currentHostSpec == null ? "<null>" : currentHostSpec.getHostAndPort(),
Utils.logTopology(allowedHosts, "")})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ public HostSpec getCurrentHostSpec() {

this.currentHostSpec = this.getWriter(this.getAllHosts());
final List<HostSpec> 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 ? "<null>" : currentHostSpec.getUrl(),
currentHostSpec == null ? "<null>" : currentHostSpec.getHostAndPort(),
Utils.logTopology(allowedHosts, "")})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -318,11 +316,6 @@ protected void suggestPrimaryCluster(final @NonNull List<HostSpec> primaryCluste
return;
}

final Set<String> primaryClusterHostUrls = new HashSet<>();
for (final HostSpec hostSpec : primaryClusterHosts) {
primaryClusterHostUrls.add(hostSpec.getUrl());
}

Map<String, Topology> entries = this.servicesContainer.getStorageService().getEntries(Topology.class);
if (entries == null) {
return;
Expand All @@ -342,7 +335,7 @@ protected void suggestPrimaryCluster(final @NonNull List<HostSpec> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ protected void failoverWriter() throws SQLException {
}

final List<HostSpec> 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, "")}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ protected void failoverWriter() throws SQLException {
}

final List<HostSpec> allowedHosts = this.pluginService.getHosts();
if (!Utils.containsUrl(allowedHosts, writerCandidate.getUrl())) {
if (!Utils.containsHostAndPort(allowedHosts, writerCandidate.getHostAndPort())) {
if (this.failoverWriterFailedCounter != null) {
this.failoverWriterFailedCounter.inc();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private void switchToReaderConnection(final List<HostSpec> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ public Connection getVerifiedConnection(
}

final List<HostSpec> 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 ? "<null>" : this.writerHostSpec.getUrl(),
this.writerHostSpec == null ? "<null>" : this.writerHostSpec.getHostAndPort(),
Utils.logTopology(allowedHosts, "")})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -66,13 +64,13 @@ public int getResponseTime(HostSpec hostSpec) {

@Override
public void setHosts(final @NonNull List<HostSpec> hosts) {
Set<String> oldHosts = this.hosts.stream().map(HostSpec::getUrl).collect(Collectors.toSet());
List<HostSpec> 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(
Expand Down
8 changes: 6 additions & 2 deletions wrapper/src/main/java/software/amazon/jdbc/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ public static boolean isNullOrEmpty(final Collection<?> c) {
return c == null || c.isEmpty();
}

public static boolean containsUrl(final List<HostSpec> hosts, String url) {
public static boolean containsHostAndPort(final Collection<HostSpec> 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;
}
}
Expand Down
Loading