Skip to content

Commit

Permalink
SOLR-14307: User defined "<cache/>" entries in solrconfig.xml now sup…
Browse files Browse the repository at this point in the history
…port enabled="true|false" just like core searcher caches.
  • Loading branch information
hossman committed Apr 1, 2020
1 parent d6cef4f commit f779bc6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions solr/core/src/java/org/apache/solr/search/CacheConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ public static Map<String, CacheConfig> getMultipleConfigs(SolrConfig solrConfig,
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
26 changes: 24 additions & 2 deletions solr/core/src/test/org/apache/solr/core/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand All @@ -29,6 +30,7 @@
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;
Expand Down Expand Up @@ -114,25 +116,45 @@ public void testCacheEnablingDisabling() throws Exception {
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");
Expand Down

0 comments on commit f779bc6

Please sign in to comment.