diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java index 24500a7d2..d40131295 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java @@ -131,6 +131,9 @@ public void establishConnection(final LimitlessConnectionContext context) throws try { context.setConnection(context.getConnectFunc().call()); } catch (final SQLException e) { + if (this.isLoginException(e)) { + throw e; + } retryConnectWithLeastLoadedRouters(context); } } @@ -150,6 +153,9 @@ public void establishConnection(final LimitlessConnectionContext context) throws "LimitlessRouterServiceImpl.selectedHost", new Object[] {selectedHostSpec != null ? selectedHostSpec.getHost() : "null"})); } catch (SQLException e) { + if (this.isLoginException(e)) { + throw e; + } retryConnectWithLeastLoadedRouters(context); return; } @@ -162,6 +168,9 @@ public void establishConnection(final LimitlessConnectionContext context) throws try { context.setConnection(this.pluginService.connect(selectedHostSpec, context.getProps(), context.getPlugin())); } catch (SQLException e) { + if (this.isLoginException(e)) { + throw e; + } if (selectedHostSpec != null) { LOGGER.fine(Messages.get( "LimitlessRouterServiceImpl.failedToConnectToHost", @@ -205,7 +214,12 @@ private void retryConnectWithLeastLoadedRouters( context.setConnection(context.getConnectFunc().call()); return; } catch (final SQLException e) { - throw new SQLException(Messages.get("LimitlessRouterServiceImpl.noRoutersAvailable")); + if (this.isLoginException(e)) { + throw e; + } + throw new SQLException(Messages.get( + "LimitlessRouterServiceImpl.unableToConnectNoRoutersAvailable", + new Object[] {context.getHostSpec().getHost()}), e); } } } @@ -236,6 +250,9 @@ private void retryConnectWithLeastLoadedRouters( return; } } catch (final SQLException e) { + if (this.isLoginException(e)) { + throw e; + } selectedHostSpec.setAvailability(HostAvailability.NOT_AVAILABLE); LOGGER.finest(Messages.get( "LimitlessRouterServiceImpl.failedToConnectToHost", @@ -259,6 +276,9 @@ protected void synchronouslyGetLimitlessRoutersWithRetry(final LimitlessConnecti } Thread.sleep(retryIntervalMs); } catch (final SQLException e) { + if (this.isLoginException(e)) { + throw e; + } LOGGER.finest(Messages.get("LimitlessRouterServiceImpl.getLimitlessRoutersException", new Object[] {e})); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); @@ -309,6 +329,10 @@ protected void synchronouslyGetLimitlessRouters(final LimitlessConnectionContext } } + protected boolean isLoginException(Throwable throwable) { + return this.pluginService.isLoginException(throwable, this.pluginService.getTargetDriverDialect()); + } + @Override public void startMonitoring(final @NonNull HostSpec hostSpec, final @NonNull Properties props, diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java index 8355c9de3..9909c613f 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java @@ -24,10 +24,10 @@ import java.util.List; import java.util.Properties; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import org.checkerframework.checker.nullness.qual.NonNull; import software.amazon.jdbc.AwsWrapperProperty; -import software.amazon.jdbc.ConnectionProviderManager; import software.amazon.jdbc.HostListProviderService; import software.amazon.jdbc.HostRole; import software.amazon.jdbc.HostSpec; @@ -35,7 +35,6 @@ import software.amazon.jdbc.NodeChangeOptions; import software.amazon.jdbc.OldConnectionSuggestedAction; import software.amazon.jdbc.PluginService; -import software.amazon.jdbc.PooledConnectionProvider; import software.amazon.jdbc.PropertyDefinition; import software.amazon.jdbc.cleanup.CanReleaseResources; import software.amazon.jdbc.plugin.AbstractConnectionPlugin; @@ -484,11 +483,14 @@ private void getNewReaderConnection() throws SQLException { readerHost = hostSpec; break; } catch (final SQLException e) { - LOGGER.warning( - () -> Messages.get( - "ReadWriteSplittingPlugin.failedToConnectToReader", - new Object[] { - hostSpec.getUrl()})); + if (LOGGER.isLoggable(Level.WARNING)) { + LOGGER.log(Level.WARNING, + Messages.get( + "ReadWriteSplittingPlugin.failedToConnectToReader", + new Object[]{ + hostSpec.getUrl()}), + e); + } } } diff --git a/wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties b/wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties index 2395331ac..2e327a87b 100644 --- a/wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties +++ b/wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties @@ -259,9 +259,10 @@ LimitlessRouterServiceImpl.getLimitlessRoutersException=Exception encountered ge LimitlessRouterServiceImpl.incorrectConfiguration=Limitless Connection Plugin is unable to run. Please ensure the connection settings are correct. LimitlessRouterServiceImpl.interruptedSynchronousGetRouter=Limitless Router Service thread was interrupted while waiting to fetch Limitless Transaction Routers. LimitlessRouterServiceImpl.limitlessRouterCacheEmpty=Limitless Router cache is empty. This normal during application start up when the cache is not yet populated. -LimitlessRouterServiceImpl.maxRetriesExceeded=Max number of connection retries has been exceeded. -LimitlessRouterServiceImpl.noRoutersAvailable=No transaction routers available. +LimitlessRouterServiceImpl.maxRetriesExceeded=Max number of connection retries has been exceeded. Unable to connect to any transaction router. +LimitlessRouterServiceImpl.noRoutersAvailable=Unable to connect to any transaction router. LimitlessRouterServiceImpl.noRoutersAvailableForRetry=No transaction routers available for connection retry. Retrying with original connection. +LimitlessRouterServiceImpl.unableToConnectNoRoutersAvailable=Unable to connect to original host {0}. All transaction routers are unavailable. Please verify connection credentials and network connectivity. LimitlessRouterServiceImpl.selectedHost=Host {0} has been selected. LimitlessRouterServiceImpl.selectedHostForRetry=Host {0} has been selected for connection retry. LimitlessRouterServiceImpl.synchronouslyGetLimitlessRouters=Fetching Limitless Routers synchronously.