From bc94ec4dc1414ba60e7b903bdc24f15042d4f5db Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 22 Aug 2013 22:52:27 +0000 Subject: [PATCH] SOLR-5182: add regenerator for blockjoin cache git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1516653 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 + .../apache/solr/search/NoOpRegenerator.java | 38 +++++++++++ .../collection1/conf/solrconfig-noopregen.xml | 36 ++++++++++ .../solr/search/TestNoOpRegenerator.java | 67 +++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java create mode 100644 solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml create mode 100644 solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index c9154b27283..239344dc1b2 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -100,6 +100,9 @@ New Features Additionally they work with sortMissingFirst, sortMissingLast, facet.missing, exists() in function queries, etc. (Robert Muir) +* SOLR-5182: Add NoOpRegenerator, a regenerator for custom per-segment caches + where items are preserved across commits. (Robert Muir) + Bug Fixes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java b/solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java new file mode 100644 index 00000000000..4dc5a54c64e --- /dev/null +++ b/solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java @@ -0,0 +1,38 @@ +package org.apache.solr.search; + +/* + * 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. + */ + +import java.io.IOException; + +/** + * Cache regenerator that just populates the new cache + * with the old items. + *

+ * This is useful for e.g. CachingWrapperFilters that are not + * invalidated by the creation of a new searcher. + */ +public class NoOpRegenerator implements CacheRegenerator { + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException { + newCache.put(oldKey, oldVal); + return true; + } + +} diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml new file mode 100644 index 00000000000..4537724b433 --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml @@ -0,0 +1,36 @@ + + + + + + + ${tests.luceneMatchVersion:LUCENE_CURRENT} + ${solr.data.dir:} + + + + + + + + diff --git a/solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java b/solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java new file mode 100644 index 00000000000..4b7b45b7489 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java @@ -0,0 +1,67 @@ +package org.apache.solr.search; + +/* + * 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. + */ + +import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.util.RefCounted; +import org.junit.BeforeClass; + +/** Tests that NoOpRegenerator does what it should */ +public class TestNoOpRegenerator extends SolrTestCaseJ4 { + + @BeforeClass + public static void beforeClass() throws Exception { + initCore("solrconfig-noopregen.xml", "schema-minimal.xml"); + } + + @SuppressWarnings("unchecked") + public void testRegeneration() throws Exception { + assertU(adoc("id", "1")); + assertU(adoc("id", "2")); + assertU(commit()); + + // add some items + RefCounted ref = h.getCore().getSearcher(); + try { + SolrIndexSearcher searcher = ref.get(); + assertEquals(2, searcher.maxDoc()); + SolrCache cache = searcher.getCache("myPerSegmentCache"); + assertEquals(0, cache.size()); + cache.put("key1", "value1"); + cache.put("key2", "value2"); + assertEquals(2, cache.size()); + } finally { + ref.decref(); + } + + // add a doc and commit: we should see our cached items still there + assertU(adoc("id", "3")); + assertU(commit()); + ref = h.getCore().getSearcher(); + try { + SolrIndexSearcher searcher = ref.get(); + assertEquals(3, searcher.maxDoc()); + SolrCache cache = searcher.getCache("myPerSegmentCache"); + assertEquals(2, cache.size()); + assertEquals("value1", cache.get("key1")); + assertEquals("value2", cache.get("key2")); + } finally { + ref.decref(); + } + } +}