diff --git a/document-store/src/main/java/org/hypertrace/core/documentstore/model/config/ConnectionPoolConfig.java b/document-store/src/main/java/org/hypertrace/core/documentstore/model/config/ConnectionPoolConfig.java index fb199fe0..50c0066c 100644 --- a/document-store/src/main/java/org/hypertrace/core/documentstore/model/config/ConnectionPoolConfig.java +++ b/document-store/src/main/java/org/hypertrace/core/documentstore/model/config/ConnectionPoolConfig.java @@ -28,4 +28,7 @@ public class ConnectionPoolConfig { // Time duration to wait for surrendering an idle connection back to the pool @NonNull @Builder.Default Duration connectionSurrenderTimeout = Duration.ofMinutes(5); + + // Whether to validate connections when borrowing from the pool + @NonNull @Builder.Default Boolean testOnBorrow = true; } diff --git a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/PostgresConnectionPool.java b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/PostgresConnectionPool.java index 74e0b20f..e125e277 100644 --- a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/PostgresConnectionPool.java +++ b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/PostgresConnectionPool.java @@ -81,14 +81,16 @@ private void setPoolProperties( connectionPool.setMinIdle(getIdleCount(poolConfig.minIdlePercent(), maxConnections)); connectionPool.setBlockWhenExhausted(true); connectionPool.setMaxWaitMillis(poolConfig.connectionAccessTimeout().toMillis()); + connectionPool.setTestOnBorrow(poolConfig.testOnBorrow()); connectionPool.setAbandonedConfig(abandonedConfig); log.debug( - "Postgres connection pool properties - maxTotal: {}, maxIdle: {}, minIdle: {}, maxWaitMillis: {}, connectionSurrenderTimeout: {}", + "Postgres connection pool properties - maxTotal: {}, maxIdle: {}, minIdle: {}, maxWaitMillis: {}, connectionSurrenderTimeout: {}, testOnBorrow: {}", connectionPool.getMaxTotal(), connectionPool.getMaxIdle(), connectionPool.getMinIdle(), connectionPool.getMaxWaitMillis(), - poolConfig.connectionSurrenderTimeout()); + poolConfig.connectionSurrenderTimeout(), + poolConfig.testOnBorrow()); } private void setFactoryProperties(