SOLR-14307: User defined "<cache/>" entries in solrconfig.xml now support enabled="true|false" just like core searcher caches.

This commit is contained in:
Chris Hostetter 2020-04-01 11:29:08 -07:00
parent d6cef4f39c
commit f779bc632d
4 changed files with 43 additions and 4 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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>

View File

@ -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 verify
System.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 verify
System.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");