|
|
|
@ -110,11 +110,13 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
*/
|
|
|
|
|
public HikariPool(HikariConfig config)
|
|
|
|
|
{
|
|
|
|
|
this.configuration = config;
|
|
|
|
|
this.username = config.getUsername();
|
|
|
|
|
this.password = config.getPassword();
|
|
|
|
|
this.configuration = config;
|
|
|
|
|
|
|
|
|
|
this.poolUtils = new PoolUtilities(config);
|
|
|
|
|
this.dataSource = poolUtils.initializeDataSource(config.getDataSourceClassName(), config.getDataSource(), config.getDataSourceProperties(), config.getDriverClassName(), config.getJdbcUrl(), username, password);
|
|
|
|
|
|
|
|
|
|
this.connectionBag = new ConcurrentBag<PoolBagEntry>(this);
|
|
|
|
|
this.totalConnections = new AtomicInteger();
|
|
|
|
|
this.connectionTimeout = config.getConnectionTimeout();
|
|
|
|
@ -134,8 +136,6 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
setMetricRegistry(config.getMetricRegistry());
|
|
|
|
|
setHealthCheckRegistry(config.getHealthCheckRegistry());
|
|
|
|
|
|
|
|
|
|
this.dataSource = poolUtils.initializeDataSource(config.getDataSourceClassName(), config.getDataSource(), config.getDataSourceProperties(), config.getDriverClassName(), config.getJdbcUrl(), username, password);
|
|
|
|
|
|
|
|
|
|
this.addConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "HikariCP connection filler (pool " + config.getPoolName() + ")", config.getThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
|
|
|
|
|
this.closeConnectionExecutor = createThreadPoolExecutor(4, "HikariCP connection closer (pool " + config.getPoolName() + ")", config.getThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
|
|
|
|
|
|
|
|
|
@ -218,7 +218,6 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
metricsTracker.recordConnectionUsage(bagEntry);
|
|
|
|
|
|
|
|
|
|
if (bagEntry.evicted) {
|
|
|
|
|
LOGGER.debug("Connection returned to pool {} is broken or evicted. Closing connection.", configuration.getPoolName());
|
|
|
|
|
closeConnection(bagEntry, "connection broken or evicted");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
@ -427,6 +426,11 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
{
|
|
|
|
|
// Speculative increment of totalConnections with expectation of success
|
|
|
|
|
if (totalConnections.incrementAndGet() <= configuration.getMaximumPoolSize()) {
|
|
|
|
|
totalConnections.decrementAndGet(); // Pool is maxed out, so undo speculative increment of totalConnections
|
|
|
|
|
lastConnectionFailure.set(new SQLException(String.format("HikariCP pool %s is at maximum capacity", configuration.getPoolName())));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connection connection = null;
|
|
|
|
|
try {
|
|
|
|
|
connection = (username == null && password == null) ? dataSource.getConnection() : dataSource.getConnection(username, password);
|
|
|
|
@ -456,12 +460,6 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
totalConnections.decrementAndGet(); // Pool is maxed out, so undo speculative increment of totalConnections
|
|
|
|
|
lastConnectionFailure.set(new SQLException(String.format("HikariCP pool %s is at maximum capacity", configuration.getPoolName())));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fill pool up from current idle connections (as they are perceived at the point of execution) to minimumIdle connections.
|
|
|
|
|