Removed some maturity wrinkles :)

1. isConnectionAlive() if connection is invalid/broken, avoid delay
caused by calls (and probably more exception) on connection to be
closed.
2. getConection() removed dead code. poolEntry is always null if
connectionBag.borrow() throws InterruptedException.
probably metricsTracker.recordBorrowTimeoutStats(startTime);
and      metricsTracker.recordConnectionTimeout() are same/ should be
one call?
pull/989/head
nitin_000 8 years ago
parent 26ee91b35c
commit baf7520c39

@ -181,11 +181,9 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag
} while (timeout > 0L);
metricsTracker.recordBorrowTimeoutStats(startTime);
metricsTracker.recordConnectionTimeout();
}
catch (InterruptedException e) {
if (poolEntry != null) {
poolEntry.recycle(startTime);
}
Thread.currentThread().interrupt();
throw new SQLException(poolName + " - Interrupted during connection acquisition", e);
}
@ -596,7 +594,6 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag
private SQLException createTimeoutException(long startTime)
{
logPoolState("Timeout failure ");
metricsTracker.recordConnectionTimeout();
String sqlState = null;
final Throwable originalException = getLastConnectionFailure();

@ -152,38 +152,38 @@ abstract class PoolBase
boolean isConnectionAlive(final Connection connection)
{
try {
try {
setNetworkTimeout(connection, validationTimeout);
final long validationSeconds = (int) Math.max(1000L, validationTimeout) / 1000;
setNetworkTimeout(connection, validationTimeout);
if (isUseJdbc4Validation) {
return connection.isValid((int) validationSeconds);
}
final int validationSeconds = (int) Math.max(1000L, validationTimeout) / 1000;
boolean valid = true;
if (isUseJdbc4Validation) {
valid = connection.isValid(validationSeconds);
}
else {
try (Statement statement = connection.createStatement()) {
if (isNetworkTimeoutSupported != TRUE) {
setQueryTimeout(statement, (int) validationSeconds);
if (isNetworkTimeoutSupported == FALSE) {
setQueryTimeout(statement, validationSeconds);
}
statement.execute(config.getConnectionTestQuery());
}
}
finally {
setNetworkTimeout(connection, networkTimeout);
}
}
if (isIsolateInternalQueries && !isAutoCommit) {
connection.rollback();
}
}
if (valid) {
if (isIsolateInternalQueries && !isAutoCommit) {
connection.rollback();
}
return true;
setNetworkTimeout(connection, networkTimeout);
return true;
}
}
catch (Exception e) {
lastConnectionFailure.set(e);
LOGGER.warn("{} - Failed to validate connection {} ({})", poolName, connection, e.getMessage());
return false;
}
return false;
}
Throwable getLastConnectionFailure()

Loading…
Cancel
Save