lmccay commented on code in PR #1526:
URL: https://github.com/apache/knox/pull/1526#discussion_r4615461238


##########
gateway-server/src/main/java/org/apache/knox/gateway/database/DataSourceProvider.java:
##########
@@ -39,4 +97,62 @@ public static DataSource getDataSource(GatewayConfig 
gatewayConfig, AliasService
 
         return dsFactory.createDataSource(gatewayConfig, aliasService);
     }
+
+    static HikariDataSource createConnectionPool(GatewayConfig gatewayConfig, 
DataSource dataSource, String poolName) throws SQLException {
+        final HikariConfig poolConfig = new HikariConfig();
+        poolConfig.setPoolName(poolName);
+        poolConfig.setDataSource(dataSource);
+        
poolConfig.setMaximumPoolSize(gatewayConfig.getDatabaseConnectionPoolMaxSize());
+        if (gatewayConfig.getDatabaseConnectionPoolMinIdle() >= 0) {
+            
poolConfig.setMinimumIdle(gatewayConfig.getDatabaseConnectionPoolMinIdle());
+        }
+        
poolConfig.setConnectionTimeout(gatewayConfig.getDatabaseConnectionPoolConnectionTimeout());
+        
poolConfig.setIdleTimeout(gatewayConfig.getDatabaseConnectionPoolIdleTimeout());
+        
poolConfig.setMaxLifetime(gatewayConfig.getDatabaseConnectionPoolMaxLifetime());
+        // Connect once while building the pool and fail if that fails. 
Otherwise the pool keeps retrying
+        // in the background and every caller blocks for the connection 
timeout, e.g. a knoxcli command
+        // run while the gateway holds the embedded H2 database file. A failed 
pool is not cached.
+        poolConfig.setInitializationFailTimeout(1);
+
+        final HikariDataSource pool;
+        try {
+            pool = new HikariDataSource(poolConfig);
+        } catch (HikariPool.PoolInitializationException e) {
+            if (e.getCause() instanceof SQLException) {
+                throw (SQLException) e.getCause();
+            }
+            throw new SQLException("Cannot create database connection pool " + 
poolName + ": " + e.getMessage(), e);

Review Comment:
   These exceptions seem to be propagated back to the caller without any 
changes to handle them via fallback to nonpooled or the like. This may be 
appropriate but what sort of handling is there and what sort of diagnstics are 
provided for when this dies in a k8s pod deployment for instance?



##########
gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java:
##########
@@ -361,6 +361,16 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
   private static final String GATEWAY_DATABASE_H2_ENCRYPTION_ENABLED = 
GATEWAY_CONFIG_FILE_PREFIX + ".database.h2.encryption.enabled";
   private static final String GATEWAY_DATABASE_H2_ENCRYPTION_PASSPHRASE_ALIAS 
= GATEWAY_CONFIG_FILE_PREFIX + ".database.h2.encryption.passphrase.alias";
   private static final String 
DEFAULT_GATEWAY_DATABASE_H2_ENCRYPTION_PASSPHRASE_ALIAS = 
"h2_encryption_passphrase";
+  private static final String GATEWAY_DATABASE_POOL_ENABLED = 
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.enabled";
+  private static final String GATEWAY_DATABASE_POOL_MAX_SIZE = 
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.max.size";
+  private static final String GATEWAY_DATABASE_POOL_MIN_IDLE = 
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.min.idle";
+  private static final String GATEWAY_DATABASE_POOL_CONNECTION_TIMEOUT = 
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.connection.timeout.ms";
+  private static final String GATEWAY_DATABASE_POOL_IDLE_TIMEOUT = 
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.idle.timeout.ms";
+  private static final String GATEWAY_DATABASE_POOL_MAX_LIFETIME = 
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.max.lifetime.ms";
+  private static final int DEFAULT_GATEWAY_DATABASE_POOL_MAX_SIZE = 10;
+  private static final long DEFAULT_GATEWAY_DATABASE_POOL_CONNECTION_TIMEOUT = 
TimeUnit.SECONDS.toMillis(30);
+  private static final long DEFAULT_GATEWAY_DATABASE_POOL_IDLE_TIMEOUT = 
TimeUnit.MINUTES.toMillis(10);
+  private static final long DEFAULT_GATEWAY_DATABASE_POOL_MAX_LIFETIME = 
TimeUnit.MINUTES.toMillis(30);

Review Comment:
   What happens after the max lifetime?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to