Skip to content

Commit 054938b

Browse files
authored
fix: writer host comparison in AuroraConnectionTrackerPlugin (#1523)
1 parent 9b6d290 commit 054938b

File tree

14 files changed

+30
-32
lines changed

14 files changed

+30
-32
lines changed

docs/GettingStarted.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525

2626
### Direct Download and Installation
2727

28-
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.
28+
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.
2929

3030
For example, the following command uses wget to download the wrapper:
3131

@@ -43,7 +43,7 @@ export CLASSPATH=$CLASSPATH:/home/userx/libs/aws-advanced-jdbc-wrapper-2.6.3.jar
4343
4444
### As a Maven Dependency
4545

46-
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:
46+
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:
4747

4848
```xml
4949
<dependencies>
@@ -57,7 +57,7 @@ You can use [Maven's dependency management](https://search.maven.org/search?q=g:
5757

5858
### As a Gradle Dependency
5959

60-
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:
60+
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:
6161

6262
```gradle
6363
dependencies {

wrapper/src/main/java/software/amazon/jdbc/PartialPluginService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ public HostSpec getCurrentHostSpec() {
143143

144144
this.currentHostSpec = this.getWriter(this.getAllHosts());
145145
final List<HostSpec> allowedHosts = this.getHosts();
146-
if (!Utils.containsUrl(allowedHosts, this.currentHostSpec.getUrl())) {
146+
if (!Utils.containsHostAndPort(allowedHosts, this.currentHostSpec.getHostAndPort())) {
147147
throw new RuntimeException(
148148
Messages.get("PluginServiceImpl.currentHostNotAllowed",
149149
new Object[] {
150-
currentHostSpec == null ? "<null>" : currentHostSpec.getUrl(),
150+
currentHostSpec == null ? "<null>" : currentHostSpec.getHostAndPort(),
151151
Utils.logTopology(allowedHosts, "")})
152152
);
153153
}

wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ public HostSpec getCurrentHostSpec() {
182182

183183
this.currentHostSpec = this.getWriter(this.getAllHosts());
184184
final List<HostSpec> allowedHosts = this.getHosts();
185-
if (!Utils.containsUrl(allowedHosts, this.currentHostSpec.getUrl())) {
185+
if (!Utils.containsHostAndPort(allowedHosts, this.currentHostSpec.getHostAndPort())) {
186186
throw new RuntimeException(
187187
Messages.get("PluginServiceImpl.currentHostNotAllowed",
188188
new Object[] {
189-
currentHostSpec == null ? "<null>" : currentHostSpec.getUrl(),
189+
currentHostSpec == null ? "<null>" : currentHostSpec.getHostAndPort(),
190190
Utils.logTopology(allowedHosts, "")})
191191
);
192192
}

wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/RdsHostListProvider.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727
import java.util.Collections;
2828
import java.util.Comparator;
2929
import java.util.HashMap;
30-
import java.util.HashSet;
3130
import java.util.List;
3231
import java.util.Map;
3332
import java.util.Map.Entry;
3433
import java.util.Objects;
3534
import java.util.Properties;
36-
import java.util.Set;
3735
import java.util.UUID;
3836
import java.util.concurrent.Executor;
3937
import java.util.concurrent.TimeUnit;
@@ -318,11 +316,6 @@ protected void suggestPrimaryCluster(final @NonNull List<HostSpec> primaryCluste
318316
return;
319317
}
320318

321-
final Set<String> primaryClusterHostUrls = new HashSet<>();
322-
for (final HostSpec hostSpec : primaryClusterHosts) {
323-
primaryClusterHostUrls.add(hostSpec.getUrl());
324-
}
325-
326319
Map<String, Topology> entries = this.servicesContainer.getStorageService().getEntries(Topology.class);
327320
if (entries == null) {
328321
return;
@@ -342,7 +335,7 @@ protected void suggestPrimaryCluster(final @NonNull List<HostSpec> primaryCluste
342335

343336
// The entry is non-primary
344337
for (final HostSpec host : clusterHosts) {
345-
if (primaryClusterHostUrls.contains(host.getUrl())) {
338+
if (Utils.containsHostAndPort(primaryClusterHosts, host.getHostAndPort())) {
346339
// Instance on this cluster matches with one of the instance on primary cluster
347340
// Suggest the primary clusterId to this entry
348341
suggestedPrimaryClusterIdCache.put(clusterId, this.clusterId,

wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraConnectionTrackerPlugin.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,16 @@ private void checkWriterChanged(boolean needRefreshHostLists) {
156156
// do nothing
157157
}
158158
}
159+
159160
final HostSpec hostSpecAfterFailover = this.getWriter(this.pluginService.getAllHosts());
161+
if (hostSpecAfterFailover == null) {
162+
return;
163+
}
160164

161165
if (this.currentWriter == null) {
162166
this.currentWriter = hostSpecAfterFailover;
163167
this.needUpdateCurrentWriter = false;
164-
165-
} else if (!this.currentWriter.equals(hostSpecAfterFailover)) {
168+
} else if (!this.currentWriter.getHostAndPort().equals(hostSpecAfterFailover.getHostAndPort())) {
166169
// the writer's changed
167170
tracker.invalidateAllConnections(this.currentWriter);
168171
tracker.logOpenedConnections();

wrapper/src/main/java/software/amazon/jdbc/plugin/failover/ClusterAwareWriterFailoverHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ private boolean isSame(final HostSpec hostSpec1, final HostSpec hostSpec2) {
452452
return false;
453453
}
454454

455-
return hostSpec1.getUrl().equals(hostSpec2.getUrl());
455+
return hostSpec1.getHostAndPort().equals(hostSpec2.getHostAndPort());
456456
}
457457

458458
private boolean connectToWriter(final HostSpec writerCandidate) {

wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ protected void failoverWriter() throws SQLException {
744744
}
745745

746746
final List<HostSpec> allowedHosts = this.pluginService.getHosts();
747-
if (!Utils.containsUrl(allowedHosts, writerHostSpec.getUrl())) {
747+
if (!Utils.containsHostAndPort(allowedHosts, writerHostSpec.getHostAndPort())) {
748748
throwFailoverFailedException(
749749
Messages.get("Failover.newWriterNotAllowed",
750750
new Object[] {writerHostSpec.getUrl(), Utils.logTopology(allowedHosts, "")}));

wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ protected void failoverWriter() throws SQLException {
560560
}
561561

562562
final List<HostSpec> allowedHosts = this.pluginService.getHosts();
563-
if (!Utils.containsUrl(allowedHosts, writerCandidate.getUrl())) {
563+
if (!Utils.containsHostAndPort(allowedHosts, writerCandidate.getHostAndPort())) {
564564
if (this.failoverWriterFailedCounter != null) {
565565
this.failoverWriterFailedCounter.inc();
566566
}

wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void establishConnection(final LimitlessConnectionContext context) throws
109109
}
110110
}
111111

112-
if (context.getLimitlessRouters().contains(context.getHostSpec())) {
112+
if (Utils.containsHostAndPort(context.getLimitlessRouters(), context.getHostSpec().getHostAndPort())) {
113113
LOGGER.finest(Messages.get(
114114
"LimitlessRouterServiceImpl.connectWithHost",
115115
new Object[] {context.getHostSpec().getHost()}));

wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private void switchToReaderConnection(final List<HostSpec> hosts)
420420
return;
421421
}
422422

423-
if (this.readerHostSpec != null && !hosts.contains(this.readerHostSpec)) {
423+
if (this.readerHostSpec != null && !Utils.containsHostAndPort(hosts, this.readerHostSpec.getHostAndPort())) {
424424
// The old reader cannot be used anymore because it is no longer in the list of allowed hosts.
425425
closeConnectionIfIdle(this.readerConnection);
426426
}

0 commit comments

Comments
 (0)