in wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java [598:657]
protected void failoverReader(final HostSpec failedHostSpec) throws SQLException {
TelemetryFactory telemetryFactory = this.pluginService.getTelemetryFactory();
TelemetryContext telemetryContext = telemetryFactory.openTelemetryContext(
TELEMETRY_READER_FAILOVER, TelemetryTraceLevel.NESTED);
this.failoverReaderTriggeredCounter.inc();
final long failoverStartNano = System.nanoTime();
try {
LOGGER.fine(() -> Messages.get("Failover.startReaderFailover"));
HostSpec failedHost = null;
final Set<String> oldAliases = this.pluginService.getCurrentHostSpec().getAliases();
if (failedHostSpec != null && failedHostSpec.getRawAvailability() == HostAvailability.AVAILABLE) {
failedHost = failedHostSpec;
}
final ReaderFailoverResult result = readerFailoverHandler.failover(this.pluginService.getHosts(), failedHost);
if (result != null) {
final SQLException exception = result.getException();
if (exception != null) {
throw exception;
}
}
if (result == null || !result.isConnected()) {
throwFailoverFailedException(Messages.get("Failover.unableToConnectToReader"));
return;
}
this.pluginService.setCurrentConnection(result.getConnection(), result.getHost());
this.pluginService.getCurrentHostSpec().removeAlias(oldAliases.toArray(new String[] {}));
updateTopology(true);
LOGGER.info(
() -> Messages.get(
"Failover.establishedConnection",
new Object[] {this.pluginService.getCurrentHostSpec()}));
throwFailoverSuccessException();
} catch (FailoverSuccessSQLException ex) {
this.failoverReaderSuccessCounter.inc();
telemetryContext.setSuccess(true);
telemetryContext.setException(ex);
throw ex;
} catch (Exception ex) {
telemetryContext.setSuccess(false);
telemetryContext.setException(ex);
this.failoverReaderFailedCounter.inc();
throw ex;
} finally {
LOGGER.finest(() -> Messages.get(
"Failover.readerFailoverElapsed",
new Object[]{TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - failoverStartNano)}));
telemetryContext.closeContext();
if (this.telemetryFailoverAdditionalTopTraceSetting) {
telemetryFactory.postCopy(telemetryContext, TelemetryTraceLevel.FORCE_TOP_LEVEL);
}
}
}