diff --git a/docs/operation.md b/docs/operation.md index 723393b4c..f7b140be9 100644 --- a/docs/operation.md +++ b/docs/operation.md @@ -81,3 +81,33 @@ taking a long time for garbage collection. completed initialization and is ready to serve requests. This means the initial connection to the database and the first round of health check on Trino clusters are completed. Otherwise, status code 503 is returned. + +## Database cache configuration + +Trino Gateway can cache database queries to improve performance and reduce load +on the backend database. This also allow gateway to continue routing queries +when the database is temporarily unavailable. Currently only the list of backend +Trino clusters used for query routing are being cached. +The cache can be configured using the `databaseCache` section in the config file. + +```yaml +databaseCache: + enabled: true + expireAfterWrite: 60m + refreshAfterWrite: 5s +``` + +Configuration options: + +* `enabled` - Enable or disable the database cache. Default is `false`. +* `expireAfterWrite` - The maximum time a cached entry is kept since it was last + loaded or refreshed. This ensures stale data is eventually removed. + If cache is not refreshed before expiration, requests will fail once the entry + expires (i.e. cache miss will attempt to reload data, but if the database is unavailable, + the request fails because there is no stale value to fall back to after + expiration). +* `refreshAfterWrite` - Duration after which cache entries are eligible for + asynchronous refresh. When a refresh is triggered, the existing cached value + continues to be served while the refresh happens in the background. + This helps keep data fresh while serving slightly stale data to avoid blocking requests. + diff --git a/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java b/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java index c73f52a25..742050427 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java +++ b/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java @@ -21,6 +21,7 @@ import io.trino.gateway.ha.clustermonitor.ClusterMetricsStatsExporter; import io.trino.gateway.ha.clustermonitor.ForMonitor; import io.trino.gateway.ha.config.DataStoreConfiguration; +import io.trino.gateway.ha.config.DatabaseCacheConfiguration; import io.trino.gateway.ha.config.HaGatewayConfiguration; import io.trino.gateway.ha.config.MonitorConfiguration; import io.trino.gateway.ha.config.RoutingConfiguration; @@ -126,6 +127,7 @@ public void configure(Binder binder) binder.bind(RoutingConfiguration.class).toInstance(configuration.getRouting()); binder.bind(DataStoreConfiguration.class).toInstance(configuration.getDataStore()); binder.bind(MonitorConfiguration.class).toInstance(configuration.getMonitor()); + binder.bind(DatabaseCacheConfiguration.class).toInstance(configuration.getDatabaseCache()); registerAuthFilters(binder); registerResources(binder); registerProxyResources(binder); diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/config/DatabaseCacheConfiguration.java b/gateway-ha/src/main/java/io/trino/gateway/ha/config/DatabaseCacheConfiguration.java new file mode 100644 index 000000000..920ba9a4b --- /dev/null +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/config/DatabaseCacheConfiguration.java @@ -0,0 +1,55 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.gateway.ha.config; + +import io.airlift.units.Duration; + +import java.util.concurrent.TimeUnit; + +public class DatabaseCacheConfiguration +{ + private boolean enabled; + private Duration expireAfterWrite = Duration.succinctDuration(60, TimeUnit.MINUTES); + private Duration refreshAfterWrite = Duration.succinctDuration(5, TimeUnit.SECONDS); + + public boolean isEnabled() + { + return enabled; + } + + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + public Duration getExpireAfterWrite() + { + return expireAfterWrite; + } + + public void setExpireAfterWrite(Duration expireAfterWrite) + { + this.expireAfterWrite = expireAfterWrite; + } + + public Duration getRefreshAfterWrite() + { + return refreshAfterWrite; + } + + public void setRefreshAfterWrite(Duration refreshAfterWrite) + { + this.refreshAfterWrite = refreshAfterWrite; + } +} diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/config/HaGatewayConfiguration.java b/gateway-ha/src/main/java/io/trino/gateway/ha/config/HaGatewayConfiguration.java index 740f1b6bd..e345a0e73 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/config/HaGatewayConfiguration.java +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/config/HaGatewayConfiguration.java @@ -42,10 +42,9 @@ public class HaGatewayConfiguration private List statementPaths = ImmutableList.of(V1_STATEMENT_PATH); private boolean includeClusterHostInResponse; private ProxyResponseConfiguration proxyResponseConfiguration = new ProxyResponseConfiguration(); - private RequestAnalyzerConfig requestAnalyzerConfig = new RequestAnalyzerConfig(); - private UIConfiguration uiConfiguration = new UIConfiguration(); + private DatabaseCacheConfiguration databaseCache = new DatabaseCacheConfiguration(); // List of Modules with FQCN (Fully Qualified Class Name) private List modules; @@ -267,6 +266,16 @@ public void setProxyResponseConfiguration(ProxyResponseConfiguration proxyRespon this.proxyResponseConfiguration = proxyResponseConfiguration; } + public DatabaseCacheConfiguration getDatabaseCache() + { + return databaseCache; + } + + public void setDatabaseCache(DatabaseCacheConfiguration databaseCache) + { + this.databaseCache = databaseCache; + } + private void validateStatementPath(String statementPath, List statementPaths) { if (statementPath.startsWith(V1_STATEMENT_PATH) || diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/GatewayBackendDao.java b/gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/GatewayBackendDao.java index 46831ca9c..746ad7559 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/GatewayBackendDao.java +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/GatewayBackendDao.java @@ -23,24 +23,6 @@ public interface GatewayBackendDao @SqlQuery("SELECT * FROM gateway_backend") List findAll(); - @SqlQuery(""" - SELECT * FROM gateway_backend - WHERE active = true - """) - List findActiveBackend(); - - @SqlQuery(""" - SELECT * FROM gateway_backend - WHERE active = true AND routing_group = :routingGroup - """) - List findActiveBackendByRoutingGroup(String routingGroup); - - @SqlQuery(""" - SELECT * FROM gateway_backend - WHERE name = :name - """) - List findByName(String name); - @SqlQuery(""" SELECT * FROM gateway_backend WHERE name = :name diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/router/HaGatewayManager.java b/gateway-ha/src/main/java/io/trino/gateway/ha/router/HaGatewayManager.java index 1c3a5027f..df84cb1e6 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/router/HaGatewayManager.java +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/router/HaGatewayManager.java @@ -13,9 +13,15 @@ */ package io.trino.gateway.ha.router; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.Ticker; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.inject.Inject; import io.airlift.log.Logger; +import io.airlift.stats.CounterStat; +import io.trino.gateway.ha.config.DatabaseCacheConfiguration; import io.trino.gateway.ha.config.ProxyBackendConfiguration; import io.trino.gateway.ha.config.RoutingConfiguration; import io.trino.gateway.ha.persistence.dao.GatewayBackend; @@ -28,34 +34,111 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.ImmutableList.toImmutableList; import static java.util.Objects.requireNonNull; public class HaGatewayManager implements GatewayBackendManager { private static final Logger log = Logger.get(HaGatewayManager.class); + private static final Object ALL_BACKEND_CACHE_KEY = new Object(); private final GatewayBackendDao dao; private final String defaultRoutingGroup; + private final boolean cacheEnabled; + private final LoadingCache> backendCache; + + private final CounterStat backendLookupSuccesses = new CounterStat(); + private final CounterStat backendLookupFailures = new CounterStat(); @Inject - public HaGatewayManager(Jdbi jdbi, RoutingConfiguration routingConfiguration) + public HaGatewayManager(Jdbi jdbi, RoutingConfiguration routingConfiguration, DatabaseCacheConfiguration databaseCacheConfiguration) + { + this(jdbi, routingConfiguration, databaseCacheConfiguration, Ticker.systemTicker()); + } + + @VisibleForTesting + public HaGatewayManager(Jdbi jdbi, RoutingConfiguration routingConfiguration, DatabaseCacheConfiguration databaseCacheConfiguration, Ticker ticker) { dao = requireNonNull(jdbi, "jdbi is null").onDemand(GatewayBackendDao.class); - this.defaultRoutingGroup = routingConfiguration.getDefaultRoutingGroup(); + defaultRoutingGroup = routingConfiguration.getDefaultRoutingGroup(); + cacheEnabled = databaseCacheConfiguration.isEnabled(); + if (cacheEnabled) { + Caffeine caffeineBuilder = Caffeine.newBuilder() + .initialCapacity(1) + .ticker(ticker); + if (databaseCacheConfiguration.getExpireAfterWrite() != null) { + caffeineBuilder = caffeineBuilder.expireAfterWrite(databaseCacheConfiguration.getExpireAfterWrite().toJavaTime()); + } + if (databaseCacheConfiguration.getRefreshAfterWrite() != null) { + caffeineBuilder = caffeineBuilder.refreshAfterWrite(databaseCacheConfiguration.getRefreshAfterWrite().toJavaTime()); + } + backendCache = caffeineBuilder.build(this::fetchAllBackends); + + // Load the data once during initialization. This ensures a fail-fast behavior in case of database misconfiguration. + try { + List _ = backendCache.get(ALL_BACKEND_CACHE_KEY); + } + catch (Exception e) { + throw new RuntimeException("Failed to warm up backend cache", e); + } + } + else { + backendCache = null; + } + } + + private List fetchAllBackends(Object ignored) + { + try { + List backends = dao.findAll(); + backendLookupSuccesses.update(1); + return backends; + } + catch (Exception e) { + backendLookupFailures.update(1); + log.warn(e, "Failed to fetch backends"); + throw e; + } + } + + private void invalidateBackendCache() + { + if (cacheEnabled) { + // Avoid using bulk invalidation like invalidateAll(), in order to invalidate in-flight loads properly. + // See https://github.com/trinodb/trino/issues/10512#issuecomment-1016398117 + backendCache.invalidate(ALL_BACKEND_CACHE_KEY); + } + } + + private List getAllBackendsInternal() + { + if (cacheEnabled) { + try { + return backendCache.get(ALL_BACKEND_CACHE_KEY); + } + catch (Exception e) { + throw new RuntimeException("Failed to load backends from database to cache", e); + } + } + else { + return fetchAllBackends(ALL_BACKEND_CACHE_KEY); + } } @Override public List getAllBackends() { - List proxyBackendList = dao.findAll(); + List proxyBackendList = getAllBackendsInternal(); return upcast(proxyBackendList); } @Override public List getAllActiveBackends() { - List proxyBackendList = dao.findActiveBackend(); + List proxyBackendList = getAllBackendsInternal().stream() + .filter(GatewayBackend::active) + .collect(toImmutableList()); return upcast(proxyBackendList); } @@ -74,14 +157,19 @@ public List getActiveDefaultBackends() @Override public List getActiveBackends(String routingGroup) { - List proxyBackendList = dao.findActiveBackendByRoutingGroup(routingGroup); + List proxyBackendList = getAllBackendsInternal().stream() + .filter(GatewayBackend::active) + .filter(backend -> backend.routingGroup().equals(routingGroup)) + .collect(toImmutableList()); return upcast(proxyBackendList); } @Override public Optional getBackendByName(String name) { - List proxyBackendList = dao.findByName(name); + List proxyBackendList = getAllBackendsInternal().stream() + .filter(backend -> backend.name().equals(name)) + .collect(toImmutableList()); return upcast(proxyBackendList).stream().findAny(); } @@ -105,6 +193,7 @@ private void updateClusterActivationStatus(String clusterName, boolean newStatus boolean previousStatus = model.active(); changeActiveStatus.run(); logActivationStatusChange(clusterName, newStatus, previousStatus); + invalidateBackendCache(); } private static void logActivationStatusChange(String clusterName, boolean newStatus, boolean previousStatus) @@ -121,6 +210,7 @@ public ProxyBackendConfiguration addBackend(ProxyBackendConfiguration backend) String backendProxyTo = removeTrailingSlash(backend.getProxyTo()); String backendExternalUrl = removeTrailingSlash(backend.getExternalUrl()); dao.create(backend.getName(), backend.getRoutingGroup(), backendProxyTo, backendExternalUrl, backend.isActive()); + invalidateBackendCache(); return backend; } @@ -138,6 +228,7 @@ public ProxyBackendConfiguration updateBackend(ProxyBackendConfiguration backend dao.update(backend.getName(), backend.getRoutingGroup(), backendProxyTo, backendExternalUrl, backend.isActive()); logActivationStatusChange(backend.getName(), backend.isActive(), model.active()); } + invalidateBackendCache(); return backend; } @@ -152,6 +243,7 @@ private static void validateBackendConfiguration(ProxyBackendConfiguration backe public void deleteBackend(String name) { dao.deleteByName(name); + invalidateBackendCache(); } private static List upcast(List gatewayBackendList) diff --git a/gateway-ha/src/test/java/io/trino/gateway/ha/TestingJdbcConnectionManager.java b/gateway-ha/src/test/java/io/trino/gateway/ha/TestingJdbcConnectionManager.java index 568c5723d..6eeb484e3 100644 --- a/gateway-ha/src/test/java/io/trino/gateway/ha/TestingJdbcConnectionManager.java +++ b/gateway-ha/src/test/java/io/trino/gateway/ha/TestingJdbcConnectionManager.java @@ -19,6 +19,8 @@ import org.jdbi.v3.core.Jdbi; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; public final class TestingJdbcConnectionManager @@ -39,4 +41,25 @@ public static JdbcConnectionManager createTestingJdbcConnectionManager(DataStore Jdbi jdbi = HaGatewayProviderModule.createJdbi(config); return new JdbcConnectionManager(jdbi, config); } + + public static void destroyTestingDatabase(DataStoreConfiguration config) + { + String tempH2DbDirPath = config.getJdbcUrl().replace("jdbc:h2:", "").replace(";NON_KEYWORDS=NAME,VALUE", ""); + File dbFile = Path.of(tempH2DbDirPath).toFile(); + File parentDir = dbFile.getParentFile(); + + if (parentDir != null && parentDir.exists()) { + File[] files = parentDir.listFiles((dir, name) -> name.startsWith(dbFile.getName())); + if (files != null) { + for (File file : files) { + try { + Files.deleteIfExists(file.toPath()); + } + catch (IOException e) { + // Ignore deletion errors in test cleanup + } + } + } + } + } } diff --git a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestHaGatewayManager.java b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestHaGatewayManager.java index bf035f7cb..afeab5044 100644 --- a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestHaGatewayManager.java +++ b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestHaGatewayManager.java @@ -13,33 +13,47 @@ */ package io.trino.gateway.ha.router; +import com.github.benmanes.caffeine.cache.Ticker; +import io.airlift.units.Duration; +import io.trino.gateway.ha.config.DataStoreConfiguration; +import io.trino.gateway.ha.config.DatabaseCacheConfiguration; import io.trino.gateway.ha.config.ProxyBackendConfiguration; import io.trino.gateway.ha.config.RoutingConfiguration; import io.trino.gateway.ha.persistence.JdbcConnectionManager; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; +import java.util.concurrent.TimeUnit; + +import static com.google.common.base.Preconditions.checkArgument; import static io.trino.gateway.ha.TestingJdbcConnectionManager.createTestingJdbcConnectionManager; import static io.trino.gateway.ha.TestingJdbcConnectionManager.dataStoreConfig; +import static io.trino.gateway.ha.TestingJdbcConnectionManager.destroyTestingDatabase; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; @TestInstance(Lifecycle.PER_CLASS) final class TestHaGatewayManager { - private HaGatewayManager haGatewayManager; - - @BeforeAll - void setUp() + @Test + void testGatewayManagerWithCache() { JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager(dataStoreConfig()); - RoutingConfiguration routingConfiguration = new RoutingConfiguration(); - haGatewayManager = new HaGatewayManager(connectionManager.getJdbi(), routingConfiguration); + DatabaseCacheConfiguration cacheConfiguration = new DatabaseCacheConfiguration(); + cacheConfiguration.setEnabled(true); + cacheConfiguration.setRefreshAfterWrite(new Duration(5, TimeUnit.SECONDS)); + testGatewayManager(new HaGatewayManager(connectionManager.getJdbi(), new RoutingConfiguration(), cacheConfiguration)); } @Test - void testGatewayManager() + void testGatewayManagerWithoutCache() + { + JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager(dataStoreConfig()); + testGatewayManager(new HaGatewayManager(connectionManager.getJdbi(), new RoutingConfiguration(), new DatabaseCacheConfiguration())); + } + + void testGatewayManager(HaGatewayManager haGatewayManager) { ProxyBackendConfiguration backend = new ProxyBackendConfiguration(); backend.setActive(true); @@ -99,9 +113,48 @@ void testGatewayManager() assertThat(backendConfigurationAdhoc2.getExternalUrl()).isEqualTo(adhoc2.getExternalUrl()); } + @Test + void testGatewayManagerCacheExpire() + { + DataStoreConfiguration dataStoreConfig = dataStoreConfig(); + JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager(dataStoreConfig); + DatabaseCacheConfiguration cacheConfiguration = new DatabaseCacheConfiguration(); + cacheConfiguration.setEnabled(true); + cacheConfiguration.setRefreshAfterWrite(new Duration(3, TimeUnit.SECONDS)); + cacheConfiguration.setExpireAfterWrite(new Duration(5, TimeUnit.SECONDS)); + TestingTicker ticker = new TestingTicker(); + HaGatewayManager haGatewayManager = new HaGatewayManager(connectionManager.getJdbi(), new RoutingConfiguration(), cacheConfiguration, ticker); + + ProxyBackendConfiguration etl = new ProxyBackendConfiguration(); + etl.setActive(false); + etl.setRoutingGroup("etl"); + etl.setName("new-etl1"); + etl.setProxyTo("https://etl1.trino.gateway.io:443/"); + etl.setExternalUrl("https://etl1.trino.gateway.io:443/"); + haGatewayManager.addBackend(etl); + + // Initial fetch + assertThat(haGatewayManager.getBackendByName("new-etl1").map(ProxyBackendConfiguration::getProxyTo).orElseThrow()).isEqualTo("https://etl1.trino.gateway.io:443"); + + // Read from cache + destroyTestingDatabase(dataStoreConfig); + assertThat(haGatewayManager.getBackendByName("new-etl1").map(ProxyBackendConfiguration::getProxyTo).orElseThrow()).isEqualTo("https://etl1.trino.gateway.io:443"); + + // Failed to refresh from DB, but still read from cache + ticker.increment(4, TimeUnit.SECONDS); + assertThat(haGatewayManager.getBackendByName("new-etl1").map(ProxyBackendConfiguration::getProxyTo).orElseThrow()).isEqualTo("https://etl1.trino.gateway.io:443"); + + // Expired from cache, failed to read from DB + ticker.increment(2, TimeUnit.SECONDS); + assertThatThrownBy(() -> haGatewayManager.getBackendByName("new-etl1")).hasMessage("Failed to load backends from database to cache"); + } + @Test void testRemoveTrailingSlashInUrl() { + JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager(dataStoreConfig()); + HaGatewayManager haGatewayManager = new HaGatewayManager(connectionManager.getJdbi(), new RoutingConfiguration(), new DatabaseCacheConfiguration()); + ProxyBackendConfiguration etl = new ProxyBackendConfiguration(); etl.setActive(false); etl.setRoutingGroup("etl"); @@ -124,4 +177,22 @@ void testRemoveTrailingSlashInUrl() assertThat(haGatewayManager.getBackendByName("new-etl1").map(ProxyBackendConfiguration::getProxyTo).orElseThrow()).isEqualTo("https://etl2.trino.gateway.io:443"); assertThat(haGatewayManager.getBackendByName("new-etl1").map(ProxyBackendConfiguration::getExternalUrl).orElseThrow()).isEqualTo("https://etl2.trino.gateway.io:443"); } + + public static class TestingTicker + implements Ticker + { + private long time; + + @Override + public synchronized long read() + { + return this.time; + } + + public synchronized void increment(long delta, TimeUnit unit) + { + checkArgument(delta >= 0L, "delta is negative"); + this.time += unit.toNanos(delta); + } + } } diff --git a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestQueryCountBasedRouter.java b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestQueryCountBasedRouter.java index 511626ab8..407b0d79b 100644 --- a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestQueryCountBasedRouter.java +++ b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestQueryCountBasedRouter.java @@ -17,6 +17,7 @@ import io.trino.gateway.ha.clustermonitor.ClusterStats; import io.trino.gateway.ha.clustermonitor.TrinoStatus; import io.trino.gateway.ha.config.DataStoreConfiguration; +import io.trino.gateway.ha.config.DatabaseCacheConfiguration; import io.trino.gateway.ha.config.ProxyBackendConfiguration; import io.trino.gateway.ha.config.RoutingConfiguration; import io.trino.gateway.ha.persistence.JdbcConnectionManager; @@ -177,7 +178,7 @@ public void init() { DataStoreConfiguration dataStoreConfig = dataStoreConfig(); JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager(dataStoreConfig); - backendManager = new HaGatewayManager(connectionManager.getJdbi(), routingConfiguration); + backendManager = new HaGatewayManager(connectionManager.getJdbi(), routingConfiguration, new DatabaseCacheConfiguration()); historyManager = new HaQueryHistoryManager(connectionManager.getJdbi(), dataStoreConfig); queryCountBasedRouter = new QueryCountBasedRouter(backendManager, historyManager, routingConfiguration); populateData(); diff --git a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingManagerNotFound.java b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingManagerNotFound.java index 8621c0695..e33ec1273 100644 --- a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingManagerNotFound.java +++ b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingManagerNotFound.java @@ -14,6 +14,7 @@ package io.trino.gateway.ha.router; import io.trino.gateway.ha.config.DataStoreConfiguration; +import io.trino.gateway.ha.config.DatabaseCacheConfiguration; import io.trino.gateway.ha.config.RoutingConfiguration; import io.trino.gateway.ha.persistence.JdbcConnectionManager; import org.junit.jupiter.api.Test; @@ -33,7 +34,7 @@ public TestRoutingManagerNotFound() RoutingConfiguration routingConfiguration = new RoutingConfiguration(); routingConfiguration.setDefaultRoutingGroup("default"); - GatewayBackendManager backendManager = new HaGatewayManager(connectionManager.getJdbi(), routingConfiguration); + GatewayBackendManager backendManager = new HaGatewayManager(connectionManager.getJdbi(), routingConfiguration, new DatabaseCacheConfiguration()); QueryHistoryManager historyManager = new HaQueryHistoryManager(connectionManager.getJdbi(), dataStoreConfig); this.routingManager = new StochasticRoutingManager(backendManager, historyManager, routingConfiguration); diff --git a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestStochasticRoutingManager.java b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestStochasticRoutingManager.java index 8714896f5..bf0aaeaf5 100644 --- a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestStochasticRoutingManager.java +++ b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestStochasticRoutingManager.java @@ -15,6 +15,7 @@ import io.trino.gateway.ha.clustermonitor.TrinoStatus; import io.trino.gateway.ha.config.DataStoreConfiguration; +import io.trino.gateway.ha.config.DatabaseCacheConfiguration; import io.trino.gateway.ha.config.ProxyBackendConfiguration; import io.trino.gateway.ha.config.RoutingConfiguration; import io.trino.gateway.ha.persistence.JdbcConnectionManager; @@ -40,7 +41,7 @@ void setUp() DataStoreConfiguration dataStoreConfig = dataStoreConfig(); JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager(dataStoreConfig); RoutingConfiguration routingConfiguration = new RoutingConfiguration(); - backendManager = new HaGatewayManager(connectionManager.getJdbi(), routingConfiguration); + backendManager = new HaGatewayManager(connectionManager.getJdbi(), routingConfiguration, new DatabaseCacheConfiguration()); historyManager = new HaQueryHistoryManager(connectionManager.getJdbi(), dataStoreConfig); haRoutingManager = new StochasticRoutingManager(backendManager, historyManager, routingConfiguration); }