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); } while (timeout > 0L);
metricsTracker.recordBorrowTimeoutStats(startTime); metricsTracker.recordBorrowTimeoutStats(startTime);
metricsTracker.recordConnectionTimeout();
} }
catch (InterruptedException e) { catch (InterruptedException e) {
if (poolEntry != null) {
poolEntry.recycle(startTime);
}
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
throw new SQLException(poolName + " - Interrupted during connection acquisition", e); 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) private SQLException createTimeoutException(long startTime)
{ {
logPoolState("Timeout failure "); logPoolState("Timeout failure ");
metricsTracker.recordConnectionTimeout();
String sqlState = null; String sqlState = null;
final Throwable originalException = getLastConnectionFailure(); final Throwable originalException = getLastConnectionFailure();

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

Loading…
Cancel
Save