Skip to content

Commit 10f4a56

Browse files
committed
chore: address review comments
1 parent 2997d86 commit 10f4a56

File tree

10 files changed

+49
-29
lines changed

10 files changed

+49
-29
lines changed

wrapper/build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,6 @@ tasks.register<Test>("test-all-mysql-aurora") {
315315
systemProperty("test-no-performance", "true")
316316
systemProperty("test-no-pg-driver", "true")
317317
systemProperty("test-no-pg-engine", "true")
318-
systemProperty("test-no-mariadb-driver", "true")
319-
systemProperty("test-no-mariadb-engine", "true")
320-
systemProperty("test-no-iam", "true")
321-
systemProperty("test-no-hikari", "true")
322-
systemProperty("test-no-secrets-manager", "true")
323318
}
324319
}
325320

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public void removeAlias(final String... alias) {
152152
public void resetAliases() {
153153
this.aliases.clear();
154154
this.allAliases.clear();
155+
this.allAliases.add(this.asAlias());
155156
}
156157

157158
public String getUrl() {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public HostSpec identifyConnection(Connection connection) throws SQLException {
503503

504504
@Override
505505
public void fillAliases(Connection connection, HostSpec hostSpec) throws SQLException {
506-
if (!hostSpec.getAliases().isEmpty()) {
506+
if (hostSpec == null || !hostSpec.getAliases().isEmpty()) {
507507
LOGGER.finest(() -> Messages.get("PluginServiceImpl.nonEmptyAliases", new Object[] {hostSpec.getAliases()}));
508508
return;
509509
}
@@ -524,8 +524,8 @@ public void fillAliases(Connection connection, HostSpec hostSpec) throws SQLExce
524524

525525
// Add the instance endpoint if the current connection is associated with a topology aware database cluster.
526526
final HostSpec host = this.identifyConnection(connection);
527-
if (host != this.currentHostSpec) {
528-
hostSpec.addAlias(host.asAlias());
527+
if (host != null) {
528+
hostSpec.addAlias(host.asAliases().toArray(new String[] {}));
529529
}
530530
}
531531
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,7 @@ public HostSpec identifyConnection(Connection connection) throws SQLException {
622622
final List<HostSpec> topology = this.refresh(connection);
623623

624624
if (topology == null) {
625-
final HostSpec host = new HostSpec(getHostEndpoint(instanceName));
626-
host.setHostId(instanceName);
627-
return host;
625+
return null;
628626
}
629627
return topology
630628
.stream()

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
package software.amazon.jdbc.hostlistprovider;
1818

1919
import java.sql.Connection;
20+
import java.sql.ResultSet;
2021
import java.sql.SQLException;
22+
import java.sql.Statement;
2123
import java.util.ArrayList;
2224
import java.util.Collections;
2325
import java.util.List;
26+
import java.util.Objects;
2427
import java.util.Properties;
2528
import org.checkerframework.checker.nullness.qual.NonNull;
2629
import software.amazon.jdbc.AwsWrapperProperty;
@@ -112,6 +115,27 @@ public HostRole getHostRole(Connection connection) {
112115

113116
@Override
114117
public HostSpec identifyConnection(Connection connection) throws SQLException {
115-
return this.hostList.get(0);
118+
try (final Statement stmt = connection.createStatement();
119+
final ResultSet resultSet = stmt.executeQuery(this.hostListProviderService.getDialect().getHostAliasQuery())) {
120+
if (resultSet.next()) {
121+
final String instance = resultSet.getString(1);
122+
123+
final List<HostSpec> topology = this.refresh(connection);
124+
125+
if (topology == null) {
126+
return null;
127+
}
128+
129+
return topology
130+
.stream()
131+
.filter(host -> Objects.equals(instance, host.getHostId()))
132+
.findAny()
133+
.orElse(null);
134+
}
135+
} catch (final SQLException e) {
136+
throw new SQLException(Messages.get("ConnectionStringHostListProvider.errorIdentifyConnection"), e);
137+
}
138+
139+
throw new SQLException(Messages.get("ConnectionStringHostListProvider.errorIdentifyConnection"));
116140
}
117141
}

wrapper/src/main/java/software/amazon/jdbc/plugin/efm/HostMonitoringConnectionPlugin.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ public <T, E extends Exception> T execute(
179179
this.monitorService.stopMonitoring(monitorContext);
180180

181181
if (monitorContext.isNodeUnhealthy()) {
182-
this.pluginService.setAvailability(this.getMonitoringHostSpec().asAliases(), HostAvailability.NOT_AVAILABLE);
182+
this.pluginService.setAvailability(
183+
this.getMonitoringHostSpec().asAliases(),
184+
HostAvailability.NOT_AVAILABLE);
183185

184186
final boolean isConnectionClosed;
185187
try {
@@ -305,11 +307,19 @@ public HostSpec getMonitoringHostSpec() {
305307
LOGGER.finest("Monitoring HostSpec is associated with a cluster endpoint, "
306308
+ "plugin needs to identify the cluster connection.");
307309
this.monitoringHostSpec = this.pluginService.identifyConnection(this.pluginService.getCurrentConnection());
310+
if (this.monitoringHostSpec == null) {
311+
throw new RuntimeException(Messages.get(
312+
"HostMonitoringConnectionPlugin.unableToIdentifyConnection",
313+
new Object[] {
314+
this.pluginService.getCurrentHostSpec().getHost(),
315+
this.pluginService.getHostListProvider()}));
316+
}
308317
this.pluginService.fillAliases(this.pluginService.getCurrentConnection(), monitoringHostSpec);
309318
}
310319
} catch (SQLException e) {
311-
// Log and ignore
320+
// Log and throw.
312321
LOGGER.finest(Messages.get("HostMonitoringConnectionPlugin.errorIdentifyingConnection", new Object[] {e}));
322+
throw new RuntimeException(e);
313323
}
314324
}
315325
return this.monitoringHostSpec;

wrapper/src/main/java/software/amazon/jdbc/plugin/efm/MonitorServiceImpl.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,9 @@ public MonitorConnectionContext startMonitoring(
9090
final int failureDetectionCount) {
9191

9292
if (nodeKeys.isEmpty()) {
93-
LOGGER.warning(
94-
() -> Messages.get(
95-
"MonitorServiceImpl.emptyAliasSet",
96-
new Object[] {hostSpec}));
97-
try {
98-
this.pluginService.fillAliases(connectionToAbort, hostSpec);
99-
} catch (SQLException e) {
100-
// Log and ignore the error.
101-
LOGGER.finest(Messages.get("MonitorServiceImpl.errorPopulatingAliases", new Object[] {e}));
102-
}
93+
throw new IllegalArgumentException(Messages.get(
94+
"MonitorServiceImpl.emptyAliasSet",
95+
new Object[] {hostSpec}));
10396
}
10497

10598
final Monitor monitor;

wrapper/src/main/resources/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ ClusterAwareWriterFailoverHandler.alreadyWriter=Current reader connection is act
7979

8080
# Connection String Host List Provider
8181
ConnectionStringHostListProvider.parsedListEmpty=Can''t parse connection string: ''{0}''.
82+
ConnectionStringHostListProvider.errorIdentifyConnection=An error occurred while obtaining the connection's host ID.
8283

8384
# Connection Plugin Manager
8485
ConnectionPluginManager.configurationProfileNotFound=Configuration profile ''{0}'' not found.
@@ -142,6 +143,7 @@ HostMonitoringConnectionPlugin.activatedMonitoring=Executing method ''{0}'', mon
142143
HostMonitoringConnectionPlugin.monitoringDeactivated=Monitoring deactivated for method ''{0}''.
143144
HostMonitoringConnectionPlugin.unavailableNode=Node ''{0}'' is unavailable.
144145
HostMonitoringConnectionPlugin.errorIdentifyingConnection=Error occurred while identifying connection: ''{0}''.
146+
HostMonitoringConnectionPlugin.unableToIdentifyConnection=Unable to identify the given connection: ''{0}'', please ensure the correct host list provider is specified. The host list provider in use is: ''{1}''.
145147

146148
# IAM Auth Connection Plugin
147149
IamAuthConnectionPlugin.unsupportedHostname=Unsupported AWS hostname {0}. Amazon domain name in format *.AWS-Region.rds.amazonaws.com or *.rds.AWS-Region.amazonaws.com.cn is expected.

wrapper/src/test/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ tasks.register<Test>("in-container") {
8686

8787
// modify below filter to select specific integration tests
8888
// see https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/TestFilter.html
89-
filter.includeTestsMatching("integration.refactored.container.tests.AuroraFailoverTest.testServerFailoverWithIdleConnections")
89+
filter.includeTestsMatching("integration.refactored.container.tests.*")
9090
}

wrapper/src/test/java/software/amazon/jdbc/hostlistprovider/AuroraHostListProviderTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,7 @@ void testIdentifyConnectionNullTopology() throws SQLException {
435435
when(mockResultSet.getString(eq(1))).thenReturn("instance-1");
436436
when(auroraHostListProvider.refresh(eq(mockConnection))).thenReturn(null);
437437

438-
final HostSpec actual = auroraHostListProvider.identifyConnection(mockConnection);
439-
440-
assertEquals("instance-1.pattern", actual.getHost());
441-
assertEquals("instance-1", actual.getHostId());
438+
assertNull(auroraHostListProvider.identifyConnection(mockConnection));
442439
}
443440

444441
@Test

0 commit comments

Comments
 (0)