Apache Lucene open-source search software
* SOLR-9886: Add a 'enable' flag to caches to enable/disable them
Noble Paul2048b82443db
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 2b79f04c313..2a5d5bb83ee 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -230,6 +230,8 @@ New Features* SOLR-9856: Collect metrics for shard replication and tlog replay on replicas (ab).+* SOLR-9886: Add a 'enable' flag to caches to enable/disable them (Pushkar Raste, noble)+Optimizations----------------------* SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that havediff --git a/solr/core/src/java/org/apache/solr/search/CacheConfig.java b/solr/core/src/java/org/apache/solr/search/CacheConfig.javaindex d3565a691ae..648fe388580 100644--- a/solr/core/src/java/org/apache/solr/search/CacheConfig.java+++ b/solr/core/src/java/org/apache/solr/search/CacheConfig.java@@ -89,7 +89,7 @@ public class CacheConfig implements MapSerializable{public static CacheConfig getConfig(SolrConfig solrConfig, String xpath) {Node node = solrConfig.getNode(xpath, false);- if(node == null) {+ if(node == null || !"true".equals(DOMUtil.getAttrOrDefault(node, "enabled", "true"))) {Map<String, String> m = solrConfig.getOverlay().getEditableSubProperties(xpath);if(m==null) return null;List<String> parts = StrUtils.splitSmart(xpath, '/');diff --git a/solr/core/src/java/org/apache/solr/search/FastLRUCache.java b/solr/core/src/java/org/apache/solr/search/FastLRUCache.javaindex 6c2e4d55c87..9c4b8920aab 100644--- a/solr/core/src/java/org/apache/solr/search/FastLRUCache.java+++ b/solr/core/src/java/org/apache/solr/search/FastLRUCache.java@@ -69,7 +69,7 @@ public class FastLRUCache<K, V> extends SolrCacheBase implements SolrCache<K,V>} else {minLimit = Integer.parseInt(str);}- if (minLimit==0) minLimit=1;+ if (minLimit <= 0) minLimit = 1;if (limit <= minLimit) limit=minLimit+1;int acceptableLimit;diff --git a/solr/core/src/java/org/apache/solr/util/DOMUtil.java b/solr/core/src/java/org/apache/solr/util/DOMUtil.javaindex 773d08cbb57..29dab931aa7 100644--- a/solr/core/src/java/org/apache/solr/util/DOMUtil.java+++ b/solr/core/src/java/org/apache/solr/util/DOMUtil.java@@ -79,6 +79,11 @@ public class DOMUtil {return getAttr(nd.getAttributes(), name);}+ public static String getAttrOrDefault(Node nd, String name, String def) {+ String attr = getAttr(nd.getAttributes(), name);+ return attr == null ? def : attr;+ }+public static String getAttr(NamedNodeMap attrs, String name, String missing_err) {Node attr = attrs==null? null : attrs.getNamedItem(name);if (attr==null) {diff --git a/solr/core/src/resources/EditableSolrConfigAttributes.json b/solr/core/src/resources/EditableSolrConfigAttributes.jsonindex b0d6c2fee01..ce9d1ada13e 100644--- a/solr/core/src/resources/EditableSolrConfigAttributes.json+++ b/solr/core/src/resources/EditableSolrConfigAttributes.json@@ -1,4 +1,14 @@{+//-------legend----------+// 0 = string attribute+// 1 = string node+// 10 = boolean attribute+// 11 = boolean node+// 20 = int attrubute+// 21 = int node+// 30 = float attribute+// 31 = float node+//------------------------"updateHandler":{"autoCommit":{"maxDocs":20,@@ -12,6 +22,7 @@"query":{"filterCache":{"class":0,+ "enabled":10,"size":0,"initialSize":20,"autowarmCount":20,@@ -19,6 +30,7 @@"regenerator":0},"queryResultCache":{"class":0,+ "enabled":10,"size":20,"initialSize":20,"autowarmCount":20,@@ -26,12 +38,14 @@"regenerator":0},"documentCache":{"class":0,+ "enabled":10,"size":20,"initialSize":20,"autowarmCount":20,"regenerator":0},"fieldValueCache":{"class":0,+ "enabled":10,"size":20,"initialSize":20,"autowarmCount":20,@@ -56,4 +70,4 @@"peerSync":{"useRangeVersions":11}-}\ No newline at end of file+}diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xmlnew file mode 100644index 00000000000..4053ebe7f38--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml@@ -0,0 +1,80 @@+<?xml version="1.0" ?>++<!--+ Licensed to the Apache Software Foundation (ASF) under one or more+ contributor license agreements. See the NOTICE file distributed with+ this work for additional information regarding copyright ownership.+ The ASF licenses this file to You 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.+-->++<config>+ <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>+ <dataDir>${solr.data.dir:}</dataDir>+ <xi:include href="solrconfig.snippet.randomindexconfig.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>+ <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>+ <schemaFactory class="ClassicIndexSchemaFactory"/>+ <requestHandler name="standard" class="solr.StandardRequestHandler" />++ <query>+ <!-- Maximum number of clauses in a boolean query... can affect+ range or wildcard queries that expand to big boolean+ queries. An exception is thrown if exceeded.+ -->+ <maxBooleanClauses>1024</maxBooleanClauses>++ <!-- Cache specification for Filters or DocSets - unordered set of *all* documents+ that match a particular query.+ -->+ <filterCache+ enabled="${filterCache.enabled}"+ class="solr.search.FastLRUCache"+ size="512"+ initialSize="512"+ autowarmCount="2"/>++ <queryResultCache+ enabled="${queryResultCache.enabled}"+ class="solr.search.LRUCache"+ size="512"+ initialSize="512"+ autowarmCount="2"/>++ <documentCache+ enabled="${documentCache.enabled}"+ class="solr.search.LRUCache"+ size="512"+ initialSize="512"+ autowarmCount="0"/>+++ <!-- If true, stored fields that are not requested will be loaded lazily.+ -->+ <enableLazyFieldLoading>true</enableLazyFieldLoading>++ <queryResultWindowSize>10</queryResultWindowSize>++ <!-- set maxSize artificially low to exercise both types of sets -->+ <HashDocSet maxSize="3" loadFactor="0.75"/>++ <!-- boolToFilterOptimizer converts boolean clauses with zero boost+ into cached filters if the number of docs selected by the clause exceeds+ the threshold (represented as a fraction of the total index)+ -->+ <boolTofilterOptimizer enabled="false" cacheSize="32" threshold=".05"/>++ </query>++</config>+++diff --git a/solr/core/src/test/org/apache/solr/core/TestConfig.java b/solr/core/src/test/org/apache/solr/core/TestConfig.javaindex 8244b32d94a..094f01322d2 100644--- a/solr/core/src/test/org/apache/solr/core/TestConfig.java+++ b/solr/core/src/test/org/apache/solr/core/TestConfig.java@@ -105,6 +105,38 @@ public class TestConfig extends SolrTestCaseJ4 {assertTrue("file handler should have been automatically registered", handler != null);}++ @Test+ public void testCacheEnablingDisabling() throws Exception {+ // ensure if cache is not defined in the config then cache is disabled+ SolrConfig sc = new SolrConfig(new SolrResourceLoader(TEST_PATH().resolve("collection1")), "solrconfig-defaults.xml", null);+ assertNull(sc.filterCacheConfig);+ assertNull(sc.queryResultCacheConfig);+ assertNull(sc.documentCacheConfig);++ // enable all the caches via system properties and verify+ System.setProperty("filterCache.enabled", "true");+ System.setProperty("queryResultCache.enabled", "true");+ System.setProperty("documentCache.enabled", "true");+ sc = new SolrConfig(new SolrResourceLoader(TEST_PATH().resolve("collection1")), "solrconfig-cache-enable-disable.xml", null);+ assertNotNull(sc.filterCacheConfig);+ assertNotNull(sc.queryResultCacheConfig);+ assertNotNull(sc.documentCacheConfig);++ // disable all the caches via system properties and verify+ System.setProperty("filterCache.enabled", "false");+ System.setProperty("queryResultCache.enabled", "false");+ System.setProperty("documentCache.enabled", "false");+ sc = new SolrConfig(new SolrResourceLoader(TEST_PATH().resolve("collection1")), "solrconfig-cache-enable-disable.xml", null);+ assertNull(sc.filterCacheConfig);+ assertNull(sc.queryResultCacheConfig);+ assertNull(sc.documentCacheConfig);++ System.clearProperty("filterCache.enabled");+ System.clearProperty("queryResultCache.enabled");+ System.clearProperty("documentCache.enabled");+ }+// If defaults change, add test methods to cover each version@Test