* SOLR-9886: Add a 'enable' flag to caches to enable/disable them

This commit is contained in:
Noble Paul 2017-01-10 21:05:38 +10:30
parent 2b4e3dd941
commit 2048b82443
7 changed files with 136 additions and 3 deletions
solr
CHANGES.txt
core/src
java/org/apache/solr
resources
test-files/solr/collection1/conf
test/org/apache/solr/core

View File

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

View File

@ -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, '/');

View File

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

View File

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

View File

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

View File

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

View File

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