diff --git a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index 3dacd94afa64e..28807877cdc95 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -368,9 +368,6 @@ public void apply(Settings value, Settings current, Settings previous) { NetworkService.TCP_RECEIVE_BUFFER_SIZE, IndexSettings.QUERY_STRING_ANALYZE_WILDCARD, IndexSettings.QUERY_STRING_ALLOW_LEADING_WILDCARD, - ScriptService.SCRIPT_GENERAL_CACHE_SIZE_SETTING, - ScriptService.SCRIPT_GENERAL_CACHE_EXPIRE_SETTING, - ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING, ScriptService.SCRIPT_CACHE_SIZE_SETTING, ScriptService.SCRIPT_CACHE_EXPIRE_SETTING, ScriptService.SCRIPT_DISABLE_MAX_COMPILATIONS_RATE_SETTING, diff --git a/server/src/main/java/org/elasticsearch/script/ScriptCacheStats.java b/server/src/main/java/org/elasticsearch/script/ScriptCacheStats.java index a5d6fd1cf46b8..44b4a7a2bee38 100644 --- a/server/src/main/java/org/elasticsearch/script/ScriptCacheStats.java +++ b/server/src/main/java/org/elasticsearch/script/ScriptCacheStats.java @@ -121,13 +121,6 @@ public Map getContextStats() { return context; } - /** - * Get the general stats, null if using context cache - */ - public ScriptStats getGeneralStats() { - return general; - } - /** * The sum of all script stats, either the general stats or the sum of all stats of the context stats. */ diff --git a/server/src/main/java/org/elasticsearch/script/ScriptService.java b/server/src/main/java/org/elasticsearch/script/ScriptService.java index d968ef54ffcd7..98f9c4090cb25 100644 --- a/server/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/server/src/main/java/org/elasticsearch/script/ScriptService.java @@ -584,19 +584,12 @@ ScriptCache contextCache(Settings settings, ScriptContext context) { * 2) context mode, if the context script cache is configured. There is no general cache in this case. */ static class CacheHolder { - final ScriptCache general; final Map> contextCache; - CacheHolder(int cacheMaxSize, TimeValue cacheExpire, Tuple maxCompilationRate, String contextRateSetting) { - contextCache = null; - general = new ScriptCache(cacheMaxSize, cacheExpire, maxCompilationRate, contextRateSetting); - } - CacheHolder(Map context) { Map> refs = new HashMap<>(context.size()); context.forEach((k, v) -> refs.put(k, new AtomicReference<>(v))); contextCache = Collections.unmodifiableMap(refs); - general = null; } /** @@ -604,9 +597,6 @@ static class CacheHolder { * the given context. Returns null in context mode if the requested context does not exist. */ ScriptCache get(String context) { - if (general != null) { - return general; - } AtomicReference ref = contextCache.get(context); if (ref == null) { return null; @@ -615,16 +605,10 @@ ScriptCache get(String context) { } ScriptStats stats() { - if (general != null) { - return general.stats(); - } return ScriptStats.sum(contextCache.values().stream().map(AtomicReference::get).map(ScriptCache::stats)::iterator); } ScriptCacheStats cacheStats() { - if (general != null) { - return new ScriptCacheStats(general.stats()); - } Map context = new HashMap<>(contextCache.size()); for (String name: contextCache.keySet()) { context.put(name, contextCache.get(name).get().stats()); @@ -636,9 +620,6 @@ ScriptCacheStats cacheStats() { * Update a single context cache if we're in the context cache mode otherwise no-op. */ void set(String name, ScriptCache cache) { - if (general != null) { - return; - } AtomicReference ref = contextCache.get(name); assert ref != null : "expected script cache to exist for context [" + name + "]"; ScriptCache oldCache = ref.get(); diff --git a/server/src/test/java/org/elasticsearch/script/ScriptCacheTests.java b/server/src/test/java/org/elasticsearch/script/ScriptCacheTests.java index 6c53624ab0cd3..7b83dd515e69c 100644 --- a/server/src/test/java/org/elasticsearch/script/ScriptCacheTests.java +++ b/server/src/test/java/org/elasticsearch/script/ScriptCacheTests.java @@ -20,34 +20,46 @@ import org.elasticsearch.common.breaker.CircuitBreakingException; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESTestCase; +import java.util.stream.Collectors; + public class ScriptCacheTests extends ESTestCase { // even though circuit breaking is allowed to be configured per minute, we actually weigh this over five minutes // simply by multiplying by five, so even setting it to one, requires five compilations to break + public void testCompilationCircuitBreaking() throws Exception { - final TimeValue expire = ScriptService.SCRIPT_GENERAL_CACHE_EXPIRE_SETTING.get(Settings.EMPTY); - final Integer size = ScriptService.SCRIPT_GENERAL_CACHE_SIZE_SETTING.get(Settings.EMPTY); - Tuple rate = ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.get(Settings.EMPTY); - String settingName = ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(); - ScriptCache cache = new ScriptCache(size, expire, Tuple.tuple(1, TimeValue.timeValueMinutes(1)), settingName); + String context = randomFrom( + ScriptModule.CORE_CONTEXTS.values().stream().filter( + c -> c.maxCompilationRateDefault.equals(ScriptCache.UNLIMITED_COMPILATION_RATE) == false + ).collect(Collectors.toList()) + ).name; + final TimeValue expire = ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getConcreteSettingForNamespace(context).get(Settings.EMPTY); + final Integer size = ScriptService.SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace(context).get(Settings.EMPTY); + Setting> rateSetting = + ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(context); + Tuple rate = + ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(context).get(Settings.EMPTY); + String rateSettingName = rateSetting.getKey(); + ScriptCache cache = new ScriptCache(size, expire, Tuple.tuple(1, TimeValue.timeValueMinutes(1)), rateSettingName); cache.checkCompilationLimit(); // should pass expectThrows(CircuitBreakingException.class, cache::checkCompilationLimit); - cache = new ScriptCache(size, expire, (Tuple.tuple(2, TimeValue.timeValueMinutes(1))), settingName); + cache = new ScriptCache(size, expire, (Tuple.tuple(2, TimeValue.timeValueMinutes(1))), rateSettingName); cache.checkCompilationLimit(); // should pass cache.checkCompilationLimit(); // should pass expectThrows(CircuitBreakingException.class, cache::checkCompilationLimit); int count = randomIntBetween(5, 50); - cache = new ScriptCache(size, expire, (Tuple.tuple(count, TimeValue.timeValueMinutes(1))), settingName); + cache = new ScriptCache(size, expire, (Tuple.tuple(count, TimeValue.timeValueMinutes(1))), rateSettingName); for (int i = 0; i < count; i++) { cache.checkCompilationLimit(); // should pass } expectThrows(CircuitBreakingException.class, cache::checkCompilationLimit); - cache = new ScriptCache(size, expire, (Tuple.tuple(0, TimeValue.timeValueMinutes(1))), settingName); + cache = new ScriptCache(size, expire, (Tuple.tuple(0, TimeValue.timeValueMinutes(1))), rateSettingName); expectThrows(CircuitBreakingException.class, cache::checkCompilationLimit); - cache = new ScriptCache(size, expire, (Tuple.tuple(Integer.MAX_VALUE, TimeValue.timeValueMinutes(1))), settingName); + cache = new ScriptCache(size, expire, (Tuple.tuple(Integer.MAX_VALUE, TimeValue.timeValueMinutes(1))), rateSettingName); int largeLimit = randomIntBetween(1000, 10000); for (int i = 0; i < largeLimit; i++) { cache.checkCompilationLimit(); @@ -55,9 +67,14 @@ public void testCompilationCircuitBreaking() throws Exception { } public void testUnlimitedCompilationRate() { - final Integer size = ScriptService.SCRIPT_GENERAL_CACHE_SIZE_SETTING.get(Settings.EMPTY); - final TimeValue expire = ScriptService.SCRIPT_GENERAL_CACHE_EXPIRE_SETTING.get(Settings.EMPTY); - String settingName = ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(); + String context = randomFrom( + ScriptModule.CORE_CONTEXTS.values().stream().filter( + c -> c.maxCompilationRateDefault.equals(ScriptCache.UNLIMITED_COMPILATION_RATE) == false + ).collect(Collectors.toList()) + ).name; + final Integer size = ScriptService.SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace(context).get(Settings.EMPTY); + final TimeValue expire = ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getConcreteSettingForNamespace(context).get(Settings.EMPTY); + String settingName = ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(context).getKey(); ScriptCache cache = new ScriptCache(size, expire, ScriptCache.UNLIMITED_COMPILATION_RATE, settingName); ScriptCache.TokenBucketState initialState = cache.tokenBucketState.get(); for(int i=0; i < 3000; i++) { diff --git a/server/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/server/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index b59f6cea6755f..742833af1b55a 100644 --- a/server/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/server/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.settings.ClusterSettings; -import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; @@ -45,12 +44,9 @@ import java.util.function.BiFunction; import java.util.function.Function; -import static org.elasticsearch.script.ScriptService.CacheHolder; import static org.elasticsearch.script.ScriptService.MAX_COMPILATION_RATE_FUNCTION; import static org.elasticsearch.script.ScriptService.SCRIPT_CACHE_EXPIRE_SETTING; import static org.elasticsearch.script.ScriptService.SCRIPT_CACHE_SIZE_SETTING; -import static org.elasticsearch.script.ScriptService.SCRIPT_GENERAL_CACHE_SIZE_SETTING; -import static org.elasticsearch.script.ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING; import static org.elasticsearch.script.ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.is; @@ -230,17 +226,12 @@ public void testMultipleCompilationsCountedInCompilationStats() throws IOExcepti } public void testCompilationStatsOnCacheHit() throws IOException { - Settings.Builder builder = Settings.builder() - .put(SCRIPT_GENERAL_CACHE_SIZE_SETTING.getKey(), 1) - .put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), "2/1m"); - buildScriptService(builder.build()); + buildScriptService(Settings.EMPTY); Script script = new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()); ScriptContext context = randomFrom(contexts.values()); scriptService.compile(script, context); scriptService.compile(script, context); assertEquals(1L, scriptService.stats().getCompilations()); - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_CACHE_SIZE_SETTING, - SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); } public void testIndexedScriptCountedInCompilationStats() throws IOException { @@ -252,18 +243,15 @@ public void testIndexedScriptCountedInCompilationStats() throws IOException { } public void testCacheEvictionCountedInCacheEvictionsStats() throws IOException { - Settings.Builder builder = Settings.builder(); - builder.put(SCRIPT_GENERAL_CACHE_SIZE_SETTING.getKey(), 1); - builder.put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), "10/1m"); - buildScriptService(builder.build()); - scriptService.compile(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(contexts.values())); - scriptService.compile(new Script(ScriptType.INLINE, "test", "2+2", Collections.emptyMap()), randomFrom(contexts.values())); + ScriptContext context = randomFrom(contexts.values()); + buildScriptService(Settings.builder() + .put(SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace(context.name).getKey(), 1) + .build() + ); + scriptService.compile(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), context); + scriptService.compile(new Script(ScriptType.INLINE, "test", "2+2", Collections.emptyMap()), context); assertEquals(2L, scriptService.stats().getCompilations()); - assertEquals(2L, scriptService.cacheStats().getGeneralStats().getCompilations()); assertEquals(1L, scriptService.stats().getCacheEvictions()); - assertEquals(1L, scriptService.cacheStats().getGeneralStats().getCacheEvictions()); - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_CACHE_SIZE_SETTING, - SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); } public void testContextCacheStats() throws IOException { @@ -312,7 +300,6 @@ public void testContextCacheStats() throws IOException { assertEquals(3L, stats.getContextStats().get(contextB.name).getCompilations()); assertEquals(1L, stats.getContextStats().get(contextB.name).getCacheEvictions()); assertEquals(2L, stats.getContextStats().get(contextB.name).getCompilationLimitTriggered()); - assertNull(scriptService.cacheStats().getGeneralStats()); // Summed up assertEquals(5L, scriptService.stats().getCompilations()); @@ -382,84 +369,22 @@ public void testMaxSizeLimit() throws Exception { iae.getMessage()); } - public void testConflictContextSettings() throws IOException { - IllegalArgumentException illegal = expectThrows(IllegalArgumentException.class, () -> { - buildScriptService(Settings.builder() - .put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), "10/1m") - .put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace("field").getKey(), 123).build()); - }); - assertEquals("Context cache settings [script.context.field.cache_max_size] requires " + - "[script.max_compilations_rate] to be [use-context]", - illegal.getMessage() - ); - - illegal = expectThrows(IllegalArgumentException.class, () -> { - buildScriptService(Settings.builder() - .put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), "10/1m") - .put(ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getConcreteSettingForNamespace("ingest").getKey(), "5m").build()); - }); - - assertEquals("Context cache settings [script.context.ingest.cache_expire] requires " + - "[script.max_compilations_rate] to be [use-context]", - illegal.getMessage() - ); - - illegal = expectThrows(IllegalArgumentException.class, () -> { - buildScriptService(Settings.builder() - .put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), "10/1m") - .put(ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace("score").getKey(), "50/5m").build()); - }); - - assertEquals("Context cache settings [script.context.score.max_compilations_rate] requires " + - "[script.max_compilations_rate] to be [use-context]", - illegal.getMessage() - ); - - buildScriptService( - Settings.builder() - .put(ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getConcreteSettingForNamespace("ingest").getKey(), "5m") - .put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace("field").getKey(), 123) - .put(ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace("score").getKey(), "50/5m") - .build()); - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); - } - public void testUseContextSettingValue() { Settings s = Settings.builder() - .put(ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), ScriptService.USE_CONTEXT_RATE_KEY) .put(ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace("foo").getKey(), ScriptService.USE_CONTEXT_RATE_KEY) .build(); - assertEquals(ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.get(s), ScriptService.USE_CONTEXT_RATE_VALUE); - IllegalArgumentException illegal = expectThrows(IllegalArgumentException.class, () -> { ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getAsMap(s); }); assertEquals("parameter must contain a positive integer and a timevalue, i.e. 10/1m, but was [use-context]", illegal.getMessage()); - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); - } - - public void testCacheHolderGeneralConstructor() throws IOException { - String compilationRate = "77/5m"; - Tuple rate = ScriptService.MAX_COMPILATION_RATE_FUNCTION.apply(compilationRate); - buildScriptService( - Settings.builder().put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), compilationRate).build() - ); - - CacheHolder holder = scriptService.cacheHolder.get(); - - assertNotNull(holder.general); - assertNull(holder.contextCache); - assertEquals(holder.general.rate, rate); - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); } public void testCacheHolderContextConstructor() throws IOException { String a = randomFrom(contexts.keySet()); String b = randomValueOtherThan(a, () -> randomFrom(contexts.keySet())); - String c = randomValueOtherThanMany(Set.of(a, b)::contains, () -> randomFrom(contexts.keySet())); String aCompilationRate = "77/5m"; String bCompilationRate = "78/6m"; @@ -468,7 +393,6 @@ public void testCacheHolderContextConstructor() throws IOException { .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(b).getKey(), bCompilationRate) .build()); - assertNull(scriptService.cacheHolder.get().general); assertNotNull(scriptService.cacheHolder.get().contextCache); assertEquals(contexts.keySet(), scriptService.cacheHolder.get().contextCache.keySet()); @@ -478,25 +402,6 @@ public void testCacheHolderContextConstructor() throws IOException { scriptService.cacheHolder.get().contextCache.get(b).get().rate); } - public void testCompilationRateUnlimitedContextOnly() throws IOException { - IllegalArgumentException illegal = expectThrows(IllegalArgumentException.class, () -> { - buildScriptService(Settings.builder() - .put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), ScriptService.UNLIMITED_COMPILATION_RATE_KEY) - .build()); - }); - assertEquals("parameter must contain a positive integer and a timevalue, i.e. 10/1m, but was [unlimited]", illegal.getMessage()); - - // Should not throw. - buildScriptService(Settings.builder() - .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace("ingest").getKey(), - ScriptService.UNLIMITED_COMPILATION_RATE_KEY) - .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace("field").getKey(), - ScriptService.UNLIMITED_COMPILATION_RATE_KEY) - .put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), ScriptService.USE_CONTEXT_RATE_KEY) - .build()); - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); - } - public void testDisableCompilationRateSetting() throws IOException { IllegalArgumentException illegal = expectThrows(IllegalArgumentException.class, () -> { buildScriptService(Settings.builder() @@ -510,21 +415,9 @@ public void testDisableCompilationRateSetting() throws IOException { "[script.disable_max_compilations_rate]", illegal.getMessage()); - illegal = expectThrows(IllegalArgumentException.class, () -> { - buildScriptService(Settings.builder() - .put("script.disable_max_compilations_rate", true) - .put("script.max_compilations_rate", "76/10m") - .build()); - }); - assertEquals("Cannot set custom general compilation rates [script.max_compilations_rate] " + - "to [Tuple [v1=76, v2=10m]] if compile " + - "rates disabled via [script.disable_max_compilations_rate]", - illegal.getMessage()); - buildScriptService(Settings.builder() .put("script.disable_max_compilations_rate", true) .build()); - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); } public void testCacheHolderChangeSettings() throws IOException { @@ -534,31 +427,20 @@ public void testCacheHolderChangeSettings() throws IOException { String b = randomValueOtherThan(a, () -> randomFrom(contextNames)); String bRate = "78/6m"; String c = randomValueOtherThanMany(s -> a.equals(s) || b.equals(s), () -> randomFrom(contextNames)); - String compilationRate = "77/5m"; - Tuple generalRate = MAX_COMPILATION_RATE_FUNCTION.apply(compilationRate); - - Settings s = Settings.builder() - .put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), compilationRate) - .build(); - - buildScriptService(s); - assertNotNull(scriptService.cacheHolder.get().general); - // Set should not throw when using general cache - scriptService.cacheHolder.get().set(c, scriptService.contextCache(s, contexts.get(c))); - assertNull(scriptService.cacheHolder.get().contextCache); - assertEquals(generalRate, scriptService.cacheHolder.get().general.rate); + buildScriptService(Settings.EMPTY); - scriptService.setCacheHolder(Settings.builder() - .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(a).getKey(), aRate) - .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(b).getKey(), bRate) - .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(c).getKey(), - ScriptService.UNLIMITED_COMPILATION_RATE_KEY) - .build() - ); + Settings settings = Settings.builder() + .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(a).getKey(), aRate) + .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(b).getKey(), bRate) + .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(c).getKey(), + ScriptService.UNLIMITED_COMPILATION_RATE_KEY) + .build(); - assertNull(scriptService.cacheHolder.get().general); assertNotNull(scriptService.cacheHolder.get().contextCache); + scriptService.cacheHolder.get().set(a, scriptService.contextCache(settings, contexts.get(a))); + scriptService.cacheHolder.get().set(b, scriptService.contextCache(settings, contexts.get(b))); + scriptService.cacheHolder.get().set(c, scriptService.contextCache(settings, contexts.get(c))); // get of missing context should be null assertNull(scriptService.cacheHolder.get().get( randomValueOtherThanMany(contexts.keySet()::contains, () -> randomAlphaOfLength(8))) @@ -578,27 +460,6 @@ public void testCacheHolderChangeSettings() throws IOException { contexts.get(b))); assertEquals(ScriptService.MAX_COMPILATION_RATE_FUNCTION.apply(aRate), scriptService.cacheHolder.get().contextCache.get(b).get().rate); - - scriptService.setCacheHolder(s); - assertNotNull(scriptService.cacheHolder.get().general); - assertNull(scriptService.cacheHolder.get().contextCache); - assertEquals(generalRate, scriptService.cacheHolder.get().general.rate); - - scriptService.setCacheHolder( - Settings.builder().put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), bRate).build() - ); - - assertNotNull(scriptService.cacheHolder.get().general); - assertNull(scriptService.cacheHolder.get().contextCache); - assertEquals(MAX_COMPILATION_RATE_FUNCTION.apply(bRate), scriptService.cacheHolder.get().general.rate); - - CacheHolder holder = scriptService.cacheHolder.get(); - scriptService.setCacheHolder( - Settings.builder().put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), bRate).build() - ); - assertEquals(holder, scriptService.cacheHolder.get()); - - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); } public void testFallbackToContextDefaults() throws IOException { @@ -607,19 +468,20 @@ public void testFallbackToContextDefaults() throws IOException { int contextCacheSize = randomIntBetween(1, 1024); TimeValue contextExpire = TimeValue.timeValueMinutes(randomIntBetween(10, 200)); - buildScriptService( - Settings.builder().put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), "75/5m").build() - ); + buildScriptService(Settings.EMPTY); String name = "ingest"; // Use context specific - scriptService.setCacheHolder(Settings.builder() + scriptService.cacheHolder.get().set( + name, + scriptService.contextCache(Settings.builder() .put(SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace(name).getKey(), contextCacheSize) .put(SCRIPT_CACHE_EXPIRE_SETTING.getConcreteSettingForNamespace(name).getKey(), contextExpire) .put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(name).getKey(), contextRateStr) - .build() - ); + .build(), + contexts.get(name) + )); ScriptService.CacheHolder holder = scriptService.cacheHolder.get(); assertNotNull(holder.contextCache); @@ -642,8 +504,6 @@ public void testFallbackToContextDefaults() throws IOException { assertEquals(ingest.maxCompilationRateDefault, holder.contextCache.get(name).get().rate); assertEquals(ingest.cacheSizeDefault, holder.contextCache.get(name).get().cacheSize); assertEquals(ingest.cacheExpireDefault, holder.contextCache.get(name).get().cacheExpire); - - assertSettingDeprecationsAndWarnings(new Setting[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING}); } private void assertCompileRejected(String lang, String script, ScriptType scriptType, ScriptContext scriptContext) {