Skip to content

Commit 8908eec

Browse files
committed
add optional db connection pool support
1 parent e7565fa commit 8908eec

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class HaGatewayProviderModule
9090
private final GatewayBackendManager gatewayBackendManager;
9191
private final QueryHistoryManager queryHistoryManager;
9292
private final PathFilter pathFilter;
93+
private final JdbcConnectionManager connectionManager;
9394

9495
@Override
9596
protected void configure()
@@ -100,6 +101,7 @@ protected void configure()
100101
binder().bind(QueryHistoryManager.class).toInstance(queryHistoryManager);
101102
binder().bind(BackendStateManager.class).in(Scopes.SINGLETON);
102103
binder().bind(PathFilter.class).toInstance(pathFilter);
104+
binder().bind(JdbcConnectionManager.class).toInstance(connectionManager);
103105
}
104106

105107
public HaGatewayProviderModule(HaGatewayConfiguration configuration)
@@ -121,8 +123,8 @@ public HaGatewayProviderModule(HaGatewayConfiguration configuration)
121123
oAuth2GatewayCookieConfigurationPropertiesProvider.initialize(configuration.getOauth2GatewayCookieConfiguration());
122124

123125
Jdbi jdbi = Jdbi.create(configuration.getDataStore().getJdbcUrl(), configuration.getDataStore().getUser(), configuration.getDataStore().getPassword());
124-
JdbcConnectionManager connectionManager = new JdbcConnectionManager(jdbi, configuration.getDataStore());
125-
resourceGroupsManager = new HaResourceGroupsManager(connectionManager);
126+
this.connectionManager = new JdbcConnectionManager(jdbi, configuration.getDataStore());
127+
resourceGroupsManager = new HaResourceGroupsManager(this.connectionManager);
126128
gatewayBackendManager = new HaGatewayManager(jdbi, configuration.getRouting());
127129
queryHistoryManager = new HaQueryHistoryManager(jdbi, configuration.getDataStore().getJdbcUrl().startsWith("jdbc:oracle"));
128130
}

gateway-ha/src/main/java/io/trino/gateway/ha/persistence/JdbcConnectionManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.trino.gateway.ha.config.DataStoreConfiguration;
2121
import io.trino.gateway.ha.persistence.dao.QueryHistoryDao;
2222
import jakarta.annotation.Nullable;
23+
import jakarta.annotation.PreDestroy;
2324
import org.jdbi.v3.core.Jdbi;
2425
import org.jdbi.v3.sqlobject.SqlObjectPlugin;
2526

@@ -154,6 +155,7 @@ private HikariDataSource getOrCreateDataSource(String routingGroupDatabase, int
154155
});
155156
}
156157

158+
@PreDestroy
157159
public void close()
158160
{
159161
for (Map.Entry<String, HikariDataSource> e : pools.entrySet()) {

0 commit comments

Comments
 (0)