Apache Lucene open-source search software
SOLR-14307: User defined "<cache/>" entries in solrconfig.xml now support enabled="true|false" just like core searcher caches.
Chris Hostetterf779bc632d10
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex b345e76599c..441458d4618 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -74,6 +74,9 @@ Improvements* SOLR-14329: Add support to choose collapse group to expand in ExpandComponent based on cost (Munendra S N)+* SOLR-14307: User defined "<cache/>" entries in solrconfig.xml now support enabled="true|false" just like+ core searcher caches. (hossman)+Optimizations---------------------* SOLR-8306: Do not collect expand documents when expand.rows=0 (Marshall Sanders, Amelia Henderson)diff --git a/solr/core/src/java/org/apache/solr/search/CacheConfig.java b/solr/core/src/java/org/apache/solr/search/CacheConfig.javaindex f41e5360824..864054fd1c7 100644--- a/solr/core/src/java/org/apache/solr/search/CacheConfig.java+++ b/solr/core/src/java/org/apache/solr/search/CacheConfig.java@@ -80,8 +80,12 @@ public class CacheConfig implements MapSerializable{if (nodes == null || nodes.getLength() == 0) return new LinkedHashMap<>();Map<String, CacheConfig> result = new HashMap<>(nodes.getLength());for (int i = 0; i < nodes.getLength(); i++) {- CacheConfig config = getConfig(solrConfig, nodes.item(i).getNodeName(), DOMUtil.toMap(nodes.item(i).getAttributes()), configPath);- result.put(config.args.get(NAME), config);+ Node node = nodes.item(i);+ if ("true".equals(DOMUtil.getAttrOrDefault(node, "enabled", "true"))) {+ CacheConfig config = getConfig(solrConfig, node.getNodeName(),+ DOMUtil.toMap(node.getAttributes()), configPath);+ result.put(config.args.get(NAME), config);+ }}return result;}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.xmlindex c01fb61fa7e..29e1799d5d9 100644--- 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.xml@@ -53,7 +53,17 @@initialSize="512"autowarmCount="0"/>+ <cache+ name="user_definied_cache_XXX"+ enabled="${user_definied_cache_XXX.enabled:false}"+ />+ <cache+ name="user_definied_cache_ZZZ"+ enabled="${user_definied_cache_ZZZ.enabled:false}"+ />++<!-- If true, stored fields that are not requested will be loaded lazily.--><enableLazyFieldLoading>true</enableLazyFieldLoading>diff --git a/solr/core/src/test/org/apache/solr/core/TestConfig.java b/solr/core/src/test/org/apache/solr/core/TestConfig.javaindex 893cf0ab49a..fe564886ac3 100644--- a/solr/core/src/test/org/apache/solr/core/TestConfig.java+++ b/solr/core/src/test/org/apache/solr/core/TestConfig.java@@ -20,6 +20,7 @@ import javax.xml.xpath.XPathConstants;import java.io.IOException;import java.io.InputStream;import java.util.LinkedHashMap;+import java.util.Collections;import org.apache.lucene.index.ConcurrentMergeScheduler;import org.apache.lucene.index.IndexWriterConfig;@@ -29,6 +30,7 @@ import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.handler.admin.ShowFileRequestHandler;import org.apache.solr.schema.IndexSchema;import org.apache.solr.schema.IndexSchemaFactory;+import org.apache.solr.search.CacheConfig;import org.apache.solr.update.SolrIndexConfig;import org.junit.Assert;import org.junit.BeforeClass;@@ -114,25 +116,45 @@ public class TestConfig extends SolrTestCaseJ4 {assertNull(sc.filterCacheConfig);assertNull(sc.queryResultCacheConfig);assertNull(sc.documentCacheConfig);+ //+ assertNotNull(sc.userCacheConfigs);+ assertEquals(Collections.<String, CacheConfig>emptyMap(), sc.userCacheConfigs);- // enable all the caches via system properties and verify+ // enable all the core caches (and one user cache) via system properties and verifySystem.setProperty("filterCache.enabled", "true");System.setProperty("queryResultCache.enabled", "true");System.setProperty("documentCache.enabled", "true");+ System.setProperty("user_definied_cache_XXX.enabled","true");+ // user_definied_cache_ZZZ.enabled defaults to false in config+sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-cache-enable-disable.xml");assertNotNull(sc.filterCacheConfig);assertNotNull(sc.queryResultCacheConfig);assertNotNull(sc.documentCacheConfig);+ //+ assertNotNull(sc.userCacheConfigs);+ assertEquals(1, sc.userCacheConfigs.size());+ assertNotNull(sc.userCacheConfigs.get("user_definied_cache_XXX"));- // disable all the caches via system properties and verify+ // disable all the core caches (and enable both user caches) via system properties and verifySystem.setProperty("filterCache.enabled", "false");System.setProperty("queryResultCache.enabled", "false");System.setProperty("documentCache.enabled", "false");+ System.setProperty("user_definied_cache_XXX.enabled","true");+ System.setProperty("user_definied_cache_ZZZ.enabled","true");+sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-cache-enable-disable.xml");assertNull(sc.filterCacheConfig);assertNull(sc.queryResultCacheConfig);assertNull(sc.documentCacheConfig);+ //+ assertNotNull(sc.userCacheConfigs);+ assertEquals(2, sc.userCacheConfigs.size());+ assertNotNull(sc.userCacheConfigs.get("user_definied_cache_XXX"));+ assertNotNull(sc.userCacheConfigs.get("user_definied_cache_ZZZ"));+ System.clearProperty("user_definied_cache_XXX.enabled");+ System.clearProperty("user_definied_cache_ZZZ.enabled");System.clearProperty("filterCache.enabled");System.clearProperty("queryResultCache.enabled");System.clearProperty("documentCache.enabled");