From c5363f6dabb0a36cc41f174023eafdd443ed106f Mon Sep 17 00:00:00 2001 From: Pushkar Raste Date: Fri, 23 Dec 2016 16:41:28 +0000 Subject: [PATCH 1/4] Allow enable/disable cache --- solr/core/src/java/org/apache/solr/search/CacheConfig.java | 2 +- solr/core/src/java/org/apache/solr/search/FastLRUCache.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 d3565a691ae3..83ad638fc3a4 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 static Map getMultipleConfigs(SolrConfig solrConfig, public static CacheConfig getConfig(SolrConfig solrConfig, String xpath) { Node node = solrConfig.getNode(xpath, false); - if(node == null) { + if(node == null || !Boolean.parseBoolean(DOMUtil.toMap(node.getAttributes()).compute("enabled", (k,v) -> v == null? "true" : "false"))) { Map m = solrConfig.getOverlay().getEditableSubProperties(xpath); if(m==null) return null; List parts = StrUtils.splitSmart(xpath, '/'); 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 6c2e4d55c87f..103a2d431718 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 Object init(Map args, Object persistence, CacheRegenerator regenerator) { } else { minLimit = Integer.parseInt(str); } - if (minLimit==0) minLimit=1; + if (minLimit<=0) minLimit=1; if (limit <= minLimit) limit=minLimit+1; int acceptableLimit; From e394b405b9e6fb0024c4b3a8747ec500dd5ba3d4 Mon Sep 17 00:00:00 2001 From: Pushkar Raste Date: Thu, 29 Dec 2016 22:46:42 +0000 Subject: [PATCH 2/4] Test case, bug fix, updated EdittableCofing.json --- .../conf/solrconfig-cache-enable-disable.xml | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 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 000000000000..86d9c6ea0016 --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml @@ -0,0 +1,82 @@ + + + + + + + ${tests.luceneMatchVersion:LATEST} + ${solr.data.dir:} + + + + + + + + 1024 + + + + + + + + + + + true + + 10 + + + + + + + + + + + + + From 59484c080fc3e3e97bb5a443588c409e381e1340 Mon Sep 17 00:00:00 2001 From: Pushkar Raste Date: Thu, 29 Dec 2016 22:47:37 +0000 Subject: [PATCH 3/4] Adding missing files --- .../org/apache/solr/search/CacheConfig.java | 2 +- .../EditableSolrConfigAttributes.json | 14 ++++++++ .../test/org/apache/solr/core/TestConfig.java | 32 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) 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 83ad638fc3a4..667e73b153f8 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 static Map getMultipleConfigs(SolrConfig solrConfig, public static CacheConfig getConfig(SolrConfig solrConfig, String xpath) { Node node = solrConfig.getNode(xpath, false); - if(node == null || !Boolean.parseBoolean(DOMUtil.toMap(node.getAttributes()).compute("enabled", (k,v) -> v == null? "true" : "false"))) { + if(node == null || !Boolean.parseBoolean(DOMUtil.toMap(node.getAttributes()).compute("enabled", (k,v) -> v == null? "true" : v))) { Map m = solrConfig.getOverlay().getEditableSubProperties(xpath); if(m==null) return null; List parts = StrUtils.splitSmart(xpath, '/'); diff --git a/solr/core/src/resources/EditableSolrConfigAttributes.json b/solr/core/src/resources/EditableSolrConfigAttributes.json index b0d6c2fee018..7eee9f115159 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, 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 55e1e1765764..38136a9f69ef 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 void testAutomaticDeprecationSupport() { 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 From 585bf9301aa13cc19ce794a762d6438b1e622ad4 Mon Sep 17 00:00:00 2001 From: Pushkar Raste Date: Thu, 29 Dec 2016 17:51:00 -0500 Subject: [PATCH 4/4] Fix minor issue --- .../solr/collection1/conf/solrconfig-cache-enable-disable.xml | 2 -- 1 file changed, 2 deletions(-) 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 index 86d9c6ea0016..4053ebe7f387 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 @@ -17,8 +17,6 @@ limitations under the License. --> - ${tests.luceneMatchVersion:LATEST} ${solr.data.dir:}