Skip to content

Commit 0bd785c

Browse files
committed
refactor: log topology and increase reconnect interval
1 parent 0d01d0b commit 0bd785c

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

wrapper/src/main/java/com/amazon/awslabs/jdbc/hostlistprovider/AuroraHostListProvider.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,17 @@ public List<HostSpec> getTopology(final Connection conn, final boolean forceUpda
186186
|| refreshNeeded(clusterTopologyInfo)) {
187187

188188
final ClusterTopologyInfo latestTopologyInfo = queryForTopology(conn);
189-
189+
List<HostSpec> hosts;
190190
if (!latestTopologyInfo.hosts.isEmpty()) {
191191
clusterTopologyInfo = updateCache(clusterTopologyInfo, latestTopologyInfo);
192+
hosts = clusterTopologyInfo.hosts;
192193
} else {
193-
return (clusterTopologyInfo == null || forceUpdate)
194+
hosts = (clusterTopologyInfo == null || forceUpdate)
194195
? new ArrayList<>()
195196
: clusterTopologyInfo.hosts;
196197
}
198+
logTopology(hosts);
199+
return hosts;
197200
}
198201

199202
return clusterTopologyInfo.hosts;
@@ -536,6 +539,19 @@ private void validateHostPatternSetting(String hostPattern) {
536539
}
537540
}
538541

542+
private void logTopology(final List<HostSpec> topology) {
543+
StringBuilder msg = new StringBuilder();
544+
for (int i = 0; i < topology.size(); i++) {
545+
HostSpec hostInfo = topology.get(i);
546+
msg.append("\n [")
547+
.append(i)
548+
.append("]: ")
549+
.append(hostInfo == null ? "<null>" : hostInfo.getHost());
550+
}
551+
LOGGER.finer(
552+
Messages.get("Failover.topologyObtained", new Object[] {msg.toString()}));
553+
}
554+
539555
/**
540556
* Class that holds the topology and additional information about the topology.
541557
*/

wrapper/src/main/java/com/amazon/awslabs/jdbc/plugin/failover/ClusterAwareReaderFailoverHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private ReaderFailoverResult getConnectionFromHostGroup(List<HostTuple> hostGrou
294294
}
295295

296296
try {
297-
TimeUnit.MILLISECONDS.sleep(1);
297+
TimeUnit.SECONDS.sleep(1);
298298
} catch (InterruptedException e) {
299299
Thread.currentThread().interrupt();
300300
throw new SQLException(Messages.get("ClusterAwareReaderFailoverHandler.1"), "70100", e);

wrapper/src/main/java/com/amazon/awslabs/jdbc/plugin/failover/ClusterAwareWriterFailoverHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ private void connectToReader() throws InterruptedException {
343343
// ignore
344344
}
345345
LOGGER.fine(Messages.get("ClusterAwareWriterFailoverHandler.12"));
346-
TimeUnit.MILLISECONDS.sleep(1);
346+
TimeUnit.SECONDS.sleep(1);
347347
}
348348
}
349349

wrapper/src/main/java/com/amazon/awslabs/jdbc/plugin/failover/FailoverConnectionPlugin.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,6 @@ public <T, E extends Exception> T execute(
170170
return jdbcMethodFunc.call();
171171
}
172172

173-
try {
174-
final RdsUrlType type = this.getHostListProvider().getRdsUrlType();
175-
if (type.isRdsCluster()) {
176-
this.explicitlyReadOnly = (type == RdsUrlType.RDS_READER_CLUSTER);
177-
LOGGER.finer(
178-
Messages.get(
179-
"Failover.parameterValue",
180-
new Object[] {"explicitlyReadOnly", this.explicitlyReadOnly}));
181-
}
182-
} catch (SQLException ex) {
183-
throw wrapExceptionIfNeeded(exceptionClass, ex);
184-
}
185-
186173
if (this.isClosed && !allowedOnClosedConnection(methodName)) {
187174
try {
188175
invalidInvocationOnClosedConnection();
@@ -267,6 +254,15 @@ void initHostProvider(
267254
this.writerFailoverHandler = writerFailoverHandlerSupplier.apply(hostListProvider);
268255

269256
initHostProviderFunc.call();
257+
258+
final RdsUrlType type = this.getHostListProvider().getRdsUrlType();
259+
if (type.isRdsCluster()) {
260+
this.explicitlyReadOnly = (type == RdsUrlType.RDS_READER_CLUSTER);
261+
LOGGER.finer(
262+
Messages.get(
263+
"Failover.parameterValue",
264+
new Object[] {"explicitlyReadOnly", this.explicitlyReadOnly}));
265+
}
270266
}
271267

272268
private AuroraHostListProvider getHostListProvider() throws SQLException {
@@ -345,7 +341,7 @@ private void invalidInvocationOnClosedConnection() throws SQLException {
345341
pickNewConnection();
346342

347343
// "The active SQL connection has changed. Please re-configure session state if required."
348-
LOGGER.severe(Messages.get("Failover.connectionChangedError"));
344+
LOGGER.info(Messages.get("Failover.connectionChangedError"));
349345
throw new SQLException(
350346
Messages.get("Failover.connectionChangedError"),
351347
SqlState.COMMUNICATION_LINK_CHANGED.getState());
@@ -652,7 +648,7 @@ protected synchronized void failover(final HostSpec failedHost) throws SQLExcept
652648
// "Transaction resolution unknown. Please re-configure session state if required and try
653649
// restarting transaction."
654650
final String errorMessage = Messages.get("Failover.transactionResolutionUnknownError");
655-
LOGGER.severe(errorMessage);
651+
LOGGER.info(errorMessage);
656652
throw new SQLException(errorMessage, SqlState.CONNECTION_FAILURE_DURING_TRANSACTION.getState());
657653
} else {
658654
// "The active SQL connection has changed due to a connection failure. Please re-configure

0 commit comments

Comments
 (0)