public static CassandraClientPool create(MetricsManager metricsManager, CassandraKeyValueServiceConfig config, Supplier<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, boolean initializeAsync) { Blacklist blacklist = new Blacklist(config); CassandraRequestExceptionHandler exceptionHandler = new CassandraRequestExceptionHandler( () -> runtimeConfig.get().numberOfRetriesOnSameHost(), () -> runtimeConfig.get().numberOfRetriesOnAllHosts(), () -> runtimeConfig.get().conservativeRequestExceptionHandler(), blacklist); CassandraClientPoolImpl cassandraClientPool = new CassandraClientPoolImpl( metricsManager, config, StartupChecks.RUN, exceptionHandler, blacklist); cassandraClientPool.wrapper.initialize(initializeAsync); return cassandraClientPool.wrapper.isInitialized() ? cassandraClientPool : cassandraClientPool.wrapper; }
/** * This is the maximum number of times we'll accept connection failures to one host before blacklisting it. Note * that subsequent hosts we try in the same call will actually be blacklisted after one connection failure */ @VisibleForTesting static int getMaxRetriesPerHost() { return CassandraKeyValueServiceRuntimeConfig.getDefault().numberOfRetriesOnSameHost(); }
@VisibleForTesting static int getMaxTriesTotal() { return CassandraKeyValueServiceRuntimeConfig.getDefault().numberOfRetriesOnAllHosts(); }
@VisibleForTesting Supplier<CassandraKeyValueServiceRuntimeConfig> preprocessKvsRuntimeConfig( Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig) { return () -> { Optional<KeyValueServiceRuntimeConfig> configOptional = runtimeConfig.get(); return configOptional.map(config -> { if (!(config instanceof CassandraKeyValueServiceRuntimeConfig)) { log.error("Invalid KeyValueServiceRuntimeConfig. Expected a KeyValueServiceRuntimeConfig of type" + " CassandraKeyValueServiceRuntimeConfig, found %s." + " Using latest valid CassandraKeyValueServiceRuntimeConfig.", config.getClass()); return latestValidRuntimeConfig; } latestValidRuntimeConfig = (CassandraKeyValueServiceRuntimeConfig) config; return latestValidRuntimeConfig; }).orElse(CassandraKeyValueServiceRuntimeConfig.getDefault()); }; }
@Test public void ifInstallAndRuntimeConfig_resolvesToRuntimeConfig() { CassandraReloadableKvsConfig reloadableConfig = getReloadableConfigWithRuntimeConfig(); int installConfigParam = 1; when(config.sweepReadThreads()).thenReturn(installConfigParam); int runtimeConfigParam = 2; when(runtimeConfig.sweepReadThreads()).thenReturn(runtimeConfigParam); assertThat(reloadableConfig.sweepReadThreads(), is(runtimeConfigParam)); }
@VisibleForTesting static int getMaxTriesTotal() { return CassandraKeyValueServiceRuntimeConfig.getDefault().numberOfRetriesOnAllHosts(); }
@VisibleForTesting Supplier<CassandraKeyValueServiceRuntimeConfig> preprocessKvsRuntimeConfig( Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig) { return () -> { Optional<KeyValueServiceRuntimeConfig> configOptional = runtimeConfig.get(); return configOptional.map(config -> { if (!(config instanceof CassandraKeyValueServiceRuntimeConfig)) { log.error("Invalid KeyValueServiceRuntimeConfig. Expected a KeyValueServiceRuntimeConfig of type" + " CassandraKeyValueServiceRuntimeConfig, found %s." + " Using latest valid CassandraKeyValueServiceRuntimeConfig.", config.getClass()); return latestValidRuntimeConfig; } latestValidRuntimeConfig = (CassandraKeyValueServiceRuntimeConfig) config; return latestValidRuntimeConfig; }).orElse(CassandraKeyValueServiceRuntimeConfig.getDefault()); }; }
@Test public void ifRuntimeConfigIsModified_reloadableConfigIsAlsoModified() { CassandraReloadableKvsConfig reloadableConfig = getReloadableConfigWithRuntimeConfig(); int firstValue = 1; int secondValue = 2; when(runtimeConfig.sweepReadThreads()).thenReturn(firstValue, secondValue); assertThat(reloadableConfig.sweepReadThreads(), is(firstValue)); assertThat(reloadableConfig.sweepReadThreads(), is(secondValue)); }
public static CassandraClientPool create(MetricsManager metricsManager, CassandraKeyValueServiceConfig config, Supplier<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, boolean initializeAsync) { Blacklist blacklist = new Blacklist(config); CassandraRequestExceptionHandler exceptionHandler = new CassandraRequestExceptionHandler( () -> runtimeConfig.get().numberOfRetriesOnSameHost(), () -> runtimeConfig.get().numberOfRetriesOnAllHosts(), () -> runtimeConfig.get().conservativeRequestExceptionHandler(), blacklist); CassandraClientPoolImpl cassandraClientPool = new CassandraClientPoolImpl( metricsManager, config, StartupChecks.RUN, exceptionHandler, blacklist); cassandraClientPool.wrapper.initialize(initializeAsync); return cassandraClientPool.wrapper.isInitialized() ? cassandraClientPool : cassandraClientPool.wrapper; }
/** * This is the maximum number of times we'll accept connection failures to one host before blacklisting it. Note * that subsequent hosts we try in the same call will actually be blacklisted after one connection failure */ @VisibleForTesting static int getMaxRetriesPerHost() { return CassandraKeyValueServiceRuntimeConfig.getDefault().numberOfRetriesOnSameHost(); }