You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2017/01/10 10:35:47 UTC
lucene-solr:master: * SOLR-9886: Add a 'enable' flag to caches to
enable/disable them
Repository: lucene-solr
Updated Branches:
refs/heads/master 2b4e3dd94 -> 2048b8244
* SOLR-9886: Add a 'enable' flag to caches to enable/disable them
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2048b824
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2048b824
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2048b824
Branch: refs/heads/master
Commit: 2048b82443db548f76d584f9a95b5628c407edde
Parents: 2b4e3dd
Author: Noble Paul <no...@apache.org>
Authored: Tue Jan 10 21:05:38 2017 +1030
Committer: Noble Paul <no...@apache.org>
Committed: Tue Jan 10 21:05:38 2017 +1030
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../org/apache/solr/search/CacheConfig.java | 2 +-
.../org/apache/solr/search/FastLRUCache.java | 2 +-
.../src/java/org/apache/solr/util/DOMUtil.java | 5 ++
.../resources/EditableSolrConfigAttributes.json | 16 +++-
.../conf/solrconfig-cache-enable-disable.xml | 80 ++++++++++++++++++++
.../test/org/apache/solr/core/TestConfig.java | 32 ++++++++
7 files changed, 136 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2048b824/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 2b79f04..2a5d5bb 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 have
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2048b824/solr/core/src/java/org/apache/solr/search/CacheConfig.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/CacheConfig.java b/solr/core/src/java/org/apache/solr/search/CacheConfig.java
index d3565a6..648fe38 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, '/');
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2048b824/solr/core/src/java/org/apache/solr/search/FastLRUCache.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/FastLRUCache.java b/solr/core/src/java/org/apache/solr/search/FastLRUCache.java
index 6c2e4d5..9c4b892 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;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2048b824/solr/core/src/java/org/apache/solr/util/DOMUtil.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/DOMUtil.java b/solr/core/src/java/org/apache/solr/util/DOMUtil.java
index 773d08c..29dab93 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) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2048b824/solr/core/src/resources/EditableSolrConfigAttributes.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/EditableSolrConfigAttributes.json b/solr/core/src/resources/EditableSolrConfigAttributes.json
index b0d6c2f..ce9d1ad 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
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2048b824/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml
----------------------------------------------------------------------
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.xml
new file mode 100644
index 0000000..4053ebe
--- /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>
+
+
+
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2048b824/solr/core/src/test/org/apache/solr/core/TestConfig.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/core/TestConfig.java b/solr/core/src/test/org/apache/solr/core/TestConfig.java
index 8244b32..094f013 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