small but important fixes

removed var

removed resetting, delink validationTimeout from connectionTimeout

one less ref per leak task. renamed start() to schedule()

made some fields final

init of leakDetectionThreshold is not required for other instances

toString using elapsedDisplayString

fix: update poolEntry.lastBorrowed in case NopMetricsTrackerDelegate

fix tests.. try1

setting isCommitStateDirty conditionally in setAutoCommit()

again, avoid calling getNextException :)

setting lastAccess in close()

setting lastAccess required only in ctor and close

removed borrowed time from PoolEntry#toString()

now that lastAccess is moved to close(), moved condition too

one less call to System.nanoTime()

fix. using toNanos()

reverted toNanos() change, got too cumbersome

removed two calls to system time

timeout is not clock time :)

only one call saved but precise 'time taken to borrow'

unlink validation of connectionTimeout with maxLifetime

Merge

Revert
pull/590/head
Nitin 9 years ago committed by Brett Wooldridge
parent fc1aea9609
commit 6ed3b18591

@ -129,7 +129,7 @@ public class HikariConfig implements HikariConfigMXBean
isInitializationFailFast = true;
String systemProp = System.getProperty("hikaricp.configurationFile");
if ( systemProp != null) {
if (systemProp != null) {
loadProperties(systemProp);
}
}
@ -245,10 +245,6 @@ public class HikariConfig implements HikariConfigMXBean
else {
this.connectionTimeout = connectionTimeoutMs;
}
if (validationTimeout > connectionTimeoutMs) {
this.validationTimeout = connectionTimeoutMs;
}
}
/** {@inheritDoc} */
@ -265,13 +261,8 @@ public class HikariConfig implements HikariConfigMXBean
if (validationTimeoutMs < 250) {
throw new IllegalArgumentException("validationTimeout cannot be less than 250ms");
}
else {
this.validationTimeout = validationTimeoutMs;
}
if (validationTimeout > connectionTimeout) {
this.validationTimeout = connectionTimeout;
}
this.validationTimeout = validationTimeoutMs;
}
/**
@ -661,6 +652,7 @@ public class HikariConfig implements HikariConfigMXBean
* Set the default password to use for DataSource.getConnection(username, password) calls.
* @param password the password
*/
@Override
public void setPassword(String password)
{
this.password = password;
@ -736,6 +728,7 @@ public class HikariConfig implements HikariConfigMXBean
*
* @param username the username
*/
@Override
public void setUsername(String username)
{
this.username = username;
@ -821,9 +814,9 @@ public class HikariConfig implements HikariConfigMXBean
}
if (idleTimeout + SECONDS.toMillis(1) > maxLifetime && maxLifetime > 0) {
LOGGER.warn("{} - idleTimeout is close to or more than maxLifetime, disabling it.", poolName);
idleTimeout = 0;
}
LOGGER.warn("{} - idleTimeout is close to or more than maxLifetime, disabling it.", poolName);
idleTimeout = 0;
}
if (idleTimeout != 0 && idleTimeout < SECONDS.toMillis(10)) {
LOGGER.warn("{} - idleTimeout is less than 10000ms, setting to default {}ms.", poolName, IDLE_TIMEOUT);
@ -831,32 +824,21 @@ public class HikariConfig implements HikariConfigMXBean
}
if (leakDetectionThreshold > 0 && !unitTest) {
if (leakDetectionThreshold < SECONDS.toMillis(2) || (leakDetectionThreshold > maxLifetime && maxLifetime > 0)) {
if (leakDetectionThreshold < SECONDS.toMillis(2) || (leakDetectionThreshold > maxLifetime && maxLifetime > 0)) {
LOGGER.warn("{} - leakDetectionThreshold is less than 2000ms or more than maxLifetime, disabling it.", poolName);
leakDetectionThreshold = 0;
}
}
if (connectionTimeout != Integer.MAX_VALUE) {
if (connectionTimeout < 250) {
LOGGER.warn("{} - connectionTimeout is less than 250ms, setting to {}ms.", poolName, CONNECTION_TIMEOUT);
connectionTimeout = CONNECTION_TIMEOUT;
}
if (maxLifetime > 0 && connectionTimeout > maxLifetime) {
LOGGER.warn("{} - connectionTimeout is more than maxLifetime, setting connectionTimeout to maxLifetime.", poolName);
connectionTimeout = maxLifetime;
}
if (connectionTimeout < 250) {
LOGGER.warn("{} - connectionTimeout is less than 250ms, setting to {}ms.", poolName, CONNECTION_TIMEOUT);
connectionTimeout = CONNECTION_TIMEOUT;
}
if (validationTimeout < 250) {
LOGGER.warn("{} - validationTimeout is less than 250ms, setting to {}ms.", poolName, VALIDATION_TIMEOUT);
validationTimeout = VALIDATION_TIMEOUT;
}
else if (validationTimeout > connectionTimeout) {
LOGGER.warn("{} - validationTimeout is more than connectionTimeout, setting validationTimeout to connectionTimeout.", poolName);
validationTimeout = connectionTimeout;
}
if (maxPoolSize < 0) {
if (minIdle < 0) {

@ -174,7 +174,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
}
else {
metricsTracker.recordBorrowStats(poolEntry, startTime);
return poolEntry.createProxyConnection(leakTask.start(poolEntry), now);
return poolEntry.createProxyConnection(leakTask.schedule(poolEntry), now);
}
} while (timeout > 0L);
}
@ -553,7 +553,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
@Override
public Boolean call() throws Exception
{
long sleepBackoff = 200L;
long sleepBackoff = 250L;
while (poolState == POOL_NORMAL && totalConnections.get() < config.getMaximumPoolSize()) {
final PoolEntry poolEntry = createPoolEntry();
if (poolEntry != null) {
@ -564,7 +564,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
// failed to get connection from db, sleep and retry
quietlySleep(sleepBackoff);
sleepBackoff = Math.min(SECONDS.toMillis(10), Math.min(connectionTimeout, (long) (sleepBackoff * 1.3)));
sleepBackoff = Math.min(SECONDS.toMillis(10), Math.min(connectionTimeout, (long) (sleepBackoff * 1.5)));
}
// Pool is suspended or shutdown or at max size
return Boolean.FALSE;

@ -436,7 +436,7 @@ abstract class PoolBase
if (isNetworkTimeoutSupported == UNINITIALIZED) {
isNetworkTimeoutSupported = FALSE;
LOGGER.warn("{} - Unable to get/set network timeout for connection. ({})", poolName, e.getMessage());
LOGGER.warn("{} - Failed to get/set network timeout for connection. ({})", poolName, e.getMessage());
if (validationTimeout < SECONDS.toMillis(1)) {
LOGGER.warn("{} - A validationTimeout of less than 1 second cannot be honored on drivers without setNetworkTimeout() support.", poolName);
}

@ -136,8 +136,7 @@ final class PoolEntry implements IConcurrentBagEntry
{
final long now = ClockSource.INSTANCE.currentTime();
return connection
+ ", borrowed " + ClockSource.INSTANCE.elapsedMillis(lastBorrowed, now) + "ms ago"
+ ", accessed " + ClockSource.INSTANCE.elapsedMillis(lastAccessed, now) + "ms ago, "
+ ", accessed " + ClockSource.INSTANCE.elapsedDisplayString(lastAccessed, now) + " ago, "
+ stateToString();
}

@ -144,9 +144,8 @@ public abstract class ProxyConnection implements Connection
final SQLException checkException(final SQLException sqle)
{
final String sqlState = sqle.getSQLState();
if (sqlState != null) {
final boolean isForceClose = sqlState.startsWith("08") || SQL_ERRORS.contains(sqlState);
if (isForceClose && delegate != ClosedConnection.CLOSED_CONNECTION) {
if (sqlState != null && delegate != ClosedConnection.CLOSED_CONNECTION) {
if (sqlState.startsWith("08") || SQL_ERRORS.contains(sqlState)) { // broken connection
LOGGER.warn("{} - Connection {} marked as broken because of SQLSTATE({}), ErrorCode({})",
poolEntry.getPoolName(), delegate, sqlState, sqle.getErrorCode(), sqle);
leakTask.cancel();
@ -178,9 +177,6 @@ public abstract class ProxyConnection implements Connection
}
}
/**
*
*/
void cancelLeakTask()
{
leakTask.cancel();
@ -387,6 +383,7 @@ public abstract class ProxyConnection implements Connection
{
delegate.setReadOnly(readOnly);
isReadOnly = readOnly;
isCommitStateDirty = false;
dirtyBits |= DIRTY_BIT_READONLY;
}

@ -65,7 +65,7 @@ class ProxyLeakTask implements Runnable
{
}
ProxyLeakTask start(final PoolEntry bagEntry)
ProxyLeakTask schedule(final PoolEntry bagEntry)
{
return (leakDetectionThreshold == 0) ? NO_LEAK : new ProxyLeakTask(this, bagEntry);
}

@ -52,6 +52,15 @@ public interface ClockSource
*/
long toMillis(long time);
/**
* Convert an opaque time-stamp returned by currentTime() into
* nanoseconds.
*
* @param time an opaque time-stamp returned by an instance of this class
* @return the time-stamp in nanoseconds
*/
long toNanos(long time);
/**
* Convert an opaque time-stamp returned by currentTime() into an
* elapsed time in milliseconds, based on the current instant in time.
@ -178,6 +187,13 @@ public interface ClockSource
return time;
}
/** {@inheritDoc} */
@Override
public long toNanos(final long time)
{
return MILLISECONDS.toNanos(time);
}
/** {@inheritDoc} */
@Override
public long plusMillis(final long time, final long millis)
@ -209,6 +225,13 @@ public interface ClockSource
return NANOSECONDS.toMillis(time);
}
/** {@inheritDoc} */
@Override
public long toNanos(final long time)
{
return time;
}
/** {@inheritDoc} */
@Override
public long elapsedMillis(final long startTime)

@ -250,7 +250,7 @@ public class ShutdownTest
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
StubConnection.slowCreate = true;
StubConnection.slowCreate = true;
UtilityElf.quietlySleep(3000L);
}
}

Loading…
Cancel
Save