From b525e0f7ef2c37217d4aa7f36b8071f53d45798c Mon Sep 17 00:00:00 2001 From: Nitin Date: Wed, 20 Jan 2016 17:02:07 +0530 Subject: [PATCH] set maxPoolSize = minIdle only if undefined, consistent error messages --- src/main/java/com/zaxxer/hikari/HikariConfig.java | 14 ++++++++------ .../java/com/zaxxer/hikari/pool/HikariPool.java | 2 +- src/main/java/com/zaxxer/hikari/pool/PoolBase.java | 12 ++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/HikariConfig.java b/src/main/java/com/zaxxer/hikari/HikariConfig.java index f0aab1e6..ce6fe609 100644 --- a/src/main/java/com/zaxxer/hikari/HikariConfig.java +++ b/src/main/java/com/zaxxer/hikari/HikariConfig.java @@ -117,7 +117,7 @@ public class HikariConfig implements HikariConfigMXBean healthCheckProperties = new Properties(); minIdle = -1; - maxPoolSize = 10; + maxPoolSize = -1; maxLifetime = MAX_LIFETIME; connectionTimeout = CONNECTION_TIMEOUT; validationTimeout = VALIDATION_TIMEOUT; @@ -855,13 +855,15 @@ public class HikariConfig implements HikariConfigMXBean } } - if (minIdle < 0) { - minIdle = maxPoolSize; - } - else if (minIdle > maxPoolSize) { - LOGGER.warn("minIdle should be less than maxPoolSize, setting maxPoolSize to minIdle"); + if (maxPoolSize < 0) { + if (minIdle < 0) { + minIdle = 10; + } maxPoolSize = minIdle; } + else if (minIdle < 0 || minIdle > maxPoolSize) { + minIdle = maxPoolSize; + } } private void logConfiguration() diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index f053b564..a71f9fc8 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -405,7 +405,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL if (connectionBag.remove(poolEntry)) { final int tc = totalConnections.decrementAndGet(); if (tc < 0) { - LOGGER.warn("{} - Internal accounting inconsistency, totalConnections={}", poolName, tc, new Exception()); + LOGGER.warn("{} - Unexpected value of totalConnections={}", poolName, tc, new Exception()); } final Connection connection = poolEntry.connection; poolEntry.close(); diff --git a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java index 5a2f3152..7be2fb5f 100644 --- a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java +++ b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java @@ -145,7 +145,7 @@ abstract class PoolBase } catch (SQLException e) { lastConnectionFailure.set(e); - LOGGER.warn("{} - Connection {} failed alive test with exception {}", poolName, connection, e.getMessage()); + LOGGER.warn("{} - Failed to validate connection {} ({})", poolName, connection, e.getMessage()); return false; } } @@ -355,7 +355,7 @@ abstract class PoolBase connection.isValid(1); } catch (Throwable e) { - LOGGER.debug("{} - Connection.isValid() is not supported, configure connection test query. ({})", poolName, e.getMessage()); + LOGGER.debug("{} - Failed to execute isValid() for connection, configure connection test query. ({})", poolName, e.getMessage()); throw e; } } @@ -388,7 +388,7 @@ abstract class PoolBase catch (Throwable e) { if (isQueryTimeoutSupported == UNINITIALIZED) { isQueryTimeoutSupported = FALSE; - LOGGER.debug("{} - Statement.setQueryTimeout() is not supported ({})", poolName, e.getMessage()); + LOGGER.debug("{} - Unable to set query timeout for statement. ({})", poolName, e.getMessage()); } } } @@ -414,7 +414,7 @@ abstract class PoolBase catch (Throwable e) { if (isNetworkTimeoutSupported == UNINITIALIZED) { isNetworkTimeoutSupported = FALSE; - LOGGER.debug("{} - Connection.setNetworkTimeout() is not supported ({})", poolName, e.getMessage()); + LOGGER.debug("{} - Unable to get/set network timeout for connection. ({})", poolName, e.getMessage()); } } } @@ -491,7 +491,7 @@ abstract class PoolBase command.run(); } catch (Throwable t) { - LoggerFactory.getLogger(PoolBase.class).debug("Exception executing {}", command, t); + LoggerFactory.getLogger(PoolBase.class).debug("Failed to execute: {}", command, t); } } } @@ -509,7 +509,7 @@ abstract class PoolBase dataSource.setLoginTimeout((int) TimeUnit.MILLISECONDS.toSeconds(Math.max(1000L, connectionTimeout))); } catch (Throwable e) { - LOGGER.warn("{} - Unable to set DataSource login timeout", poolName, e); + LOGGER.warn("{} - Unable to set login timeout for data source. ({})", poolName, e.getMessage()); } } }