You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/08/23 00:52:27 UTC
svn commit: r1516653 - in /lucene/dev/trunk/solr: CHANGES.txt
core/src/java/org/apache/solr/search/NoOpRegenerator.java
core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml
core/src/test/org/apache/solr/search/TestNoOpRegenerator.java
Author: rmuir
Date: Thu Aug 22 22:52:27 2013
New Revision: 1516653
URL: http://svn.apache.org/r1516653
Log:
SOLR-5182: add regenerator for blockjoin cache
Added:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java (with props)
lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml (with props)
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java (with props)
Modified:
lucene/dev/trunk/solr/CHANGES.txt
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1516653&r1=1516652&r2=1516653&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu Aug 22 22:52:27 2013
@@ -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
----------------------
Added: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java?rev=1516653&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java (added)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/NoOpRegenerator.java Thu Aug 22 22:52:27 2013
@@ -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.
+ * <p>
+ * 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;
+ }
+
+}
Added: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml?rev=1516653&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-noopregen.xml Thu Aug 22 22:52:27 2013
@@ -0,0 +1,36 @@
+<?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.
+-->
+
+<!-- a basic solrconfig that tests NoOpRegenerator -->
+<config>
+ <luceneMatchVersion>${tests.luceneMatchVersion:LUCENE_CURRENT}</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}"/>
+ <requestHandler name="standard" class="solr.StandardRequestHandler" />
+ <requestHandler name="/update" class="solr.UpdateRequestHandler" />
+ <query>
+ <cache name="myPerSegmentCache"
+ class="solr.LRUCache"
+ size="3"
+ initialSize="0"
+ autowarmCount="100%"
+ regenerator="solr.NoOpRegenerator"/>
+ </query>
+</config>
Added: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java?rev=1516653&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java (added)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestNoOpRegenerator.java Thu Aug 22 22:52:27 2013
@@ -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<SolrIndexSearcher> ref = h.getCore().getSearcher();
+ try {
+ SolrIndexSearcher searcher = ref.get();
+ assertEquals(2, searcher.maxDoc());
+ SolrCache<Object,Object> 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<Object,Object> cache = searcher.getCache("myPerSegmentCache");
+ assertEquals(2, cache.size());
+ assertEquals("value1", cache.get("key1"));
+ assertEquals("value2", cache.get("key2"));
+ } finally {
+ ref.decref();
+ }
+ }
+}