Skip to content

Commit b98dc8b

Browse files
committed
improve logging
1 parent 5c584e9 commit b98dc8b

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ public void establishConnection(final LimitlessConnectionContext context) throws
131131
try {
132132
context.setConnection(context.getConnectFunc().call());
133133
} catch (final SQLException e) {
134+
if (this.isLoginException(e)) {
135+
throw e;
136+
}
134137
retryConnectWithLeastLoadedRouters(context);
135138
}
136139
}
@@ -150,6 +153,9 @@ public void establishConnection(final LimitlessConnectionContext context) throws
150153
"LimitlessRouterServiceImpl.selectedHost",
151154
new Object[] {selectedHostSpec != null ? selectedHostSpec.getHost() : "null"}));
152155
} catch (SQLException e) {
156+
if (this.isLoginException(e)) {
157+
throw e;
158+
}
153159
retryConnectWithLeastLoadedRouters(context);
154160
return;
155161
}
@@ -162,6 +168,9 @@ public void establishConnection(final LimitlessConnectionContext context) throws
162168
try {
163169
context.setConnection(this.pluginService.connect(selectedHostSpec, context.getProps(), context.getPlugin()));
164170
} catch (SQLException e) {
171+
if (this.isLoginException(e)) {
172+
throw e;
173+
}
165174
if (selectedHostSpec != null) {
166175
LOGGER.fine(Messages.get(
167176
"LimitlessRouterServiceImpl.failedToConnectToHost",
@@ -205,7 +214,12 @@ private void retryConnectWithLeastLoadedRouters(
205214
context.setConnection(context.getConnectFunc().call());
206215
return;
207216
} catch (final SQLException e) {
208-
throw new SQLException(Messages.get("LimitlessRouterServiceImpl.noRoutersAvailable"));
217+
if (this.isLoginException(e)) {
218+
throw e;
219+
}
220+
throw new SQLException(Messages.get(
221+
"LimitlessRouterServiceImpl.unableToConnectNoRoutersAvailable",
222+
new Object[] {context.getHostSpec().getHost()}), e);
209223
}
210224
}
211225
}
@@ -236,6 +250,9 @@ private void retryConnectWithLeastLoadedRouters(
236250
return;
237251
}
238252
} catch (final SQLException e) {
253+
if (this.isLoginException(e)) {
254+
throw e;
255+
}
239256
selectedHostSpec.setAvailability(HostAvailability.NOT_AVAILABLE);
240257
LOGGER.finest(Messages.get(
241258
"LimitlessRouterServiceImpl.failedToConnectToHost",
@@ -259,6 +276,9 @@ protected void synchronouslyGetLimitlessRoutersWithRetry(final LimitlessConnecti
259276
}
260277
Thread.sleep(retryIntervalMs);
261278
} catch (final SQLException e) {
279+
if (this.isLoginException(e)) {
280+
throw e;
281+
}
262282
LOGGER.finest(Messages.get("LimitlessRouterServiceImpl.getLimitlessRoutersException", new Object[] {e}));
263283
} catch (final InterruptedException e) {
264284
Thread.currentThread().interrupt();
@@ -309,6 +329,10 @@ protected void synchronouslyGetLimitlessRouters(final LimitlessConnectionContext
309329
}
310330
}
311331

332+
protected boolean isLoginException(Throwable throwable) {
333+
return this.pluginService.isLoginException(throwable, this.pluginService.getTargetDriverDialect());
334+
}
335+
312336
@Override
313337
public void startMonitoring(final @NonNull HostSpec hostSpec,
314338
final @NonNull Properties props,

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424
import java.util.List;
2525
import java.util.Properties;
2626
import java.util.Set;
27+
import java.util.logging.Level;
2728
import java.util.logging.Logger;
2829
import org.checkerframework.checker.nullness.qual.NonNull;
2930
import software.amazon.jdbc.AwsWrapperProperty;
30-
import software.amazon.jdbc.ConnectionProviderManager;
3131
import software.amazon.jdbc.HostListProviderService;
3232
import software.amazon.jdbc.HostRole;
3333
import software.amazon.jdbc.HostSpec;
3434
import software.amazon.jdbc.JdbcCallable;
3535
import software.amazon.jdbc.NodeChangeOptions;
3636
import software.amazon.jdbc.OldConnectionSuggestedAction;
3737
import software.amazon.jdbc.PluginService;
38-
import software.amazon.jdbc.PooledConnectionProvider;
3938
import software.amazon.jdbc.PropertyDefinition;
4039
import software.amazon.jdbc.cleanup.CanReleaseResources;
4140
import software.amazon.jdbc.plugin.AbstractConnectionPlugin;
@@ -484,11 +483,14 @@ private void getNewReaderConnection() throws SQLException {
484483
readerHost = hostSpec;
485484
break;
486485
} catch (final SQLException e) {
487-
LOGGER.warning(
488-
() -> Messages.get(
489-
"ReadWriteSplittingPlugin.failedToConnectToReader",
490-
new Object[] {
491-
hostSpec.getUrl()}));
486+
if (LOGGER.isLoggable(Level.WARNING)) {
487+
LOGGER.log(Level.WARNING,
488+
Messages.get(
489+
"ReadWriteSplittingPlugin.failedToConnectToReader",
490+
new Object[]{
491+
hostSpec.getUrl()}),
492+
e);
493+
}
492494
}
493495
}
494496

wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ LimitlessRouterServiceImpl.getLimitlessRoutersException=Exception encountered ge
259259
LimitlessRouterServiceImpl.incorrectConfiguration=Limitless Connection Plugin is unable to run. Please ensure the connection settings are correct.
260260
LimitlessRouterServiceImpl.interruptedSynchronousGetRouter=Limitless Router Service thread was interrupted while waiting to fetch Limitless Transaction Routers.
261261
LimitlessRouterServiceImpl.limitlessRouterCacheEmpty=Limitless Router cache is empty. This normal during application start up when the cache is not yet populated.
262-
LimitlessRouterServiceImpl.maxRetriesExceeded=Max number of connection retries has been exceeded.
263-
LimitlessRouterServiceImpl.noRoutersAvailable=No transaction routers available.
262+
LimitlessRouterServiceImpl.maxRetriesExceeded=Max number of connection retries has been exceeded. Unable to connect to any transaction router.
263+
LimitlessRouterServiceImpl.noRoutersAvailable=Unable to connect to any transaction router.
264264
LimitlessRouterServiceImpl.noRoutersAvailableForRetry=No transaction routers available for connection retry. Retrying with original connection.
265+
LimitlessRouterServiceImpl.unableToConnectNoRoutersAvailable=Unable to connect to original host {0}. All transaction routers are unavailable. Please verify connection credentials and network connectivity.
265266
LimitlessRouterServiceImpl.selectedHost=Host {0} has been selected.
266267
LimitlessRouterServiceImpl.selectedHostForRetry=Host {0} has been selected for connection retry.
267268
LimitlessRouterServiceImpl.synchronouslyGetLimitlessRouters=Fetching Limitless Routers synchronously.

0 commit comments

Comments
 (0)