You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2012/01/19 07:25:31 UTC
svn commit: r1233196 - in /lucene/dev/branches/branch_3x: ./ lucene/ solr/
solr/core/ solr/core/src/java/org/apache/solr/core/
solr/core/src/test-files/solr/ solr/core/src/test-files/solr/conf/
solr/core/src/test/org/apache/solr/ solr/example/solr/conf...
Author: sarowe
Date: Thu Jan 19 06:25:31 2012
New Revision: 1233196
URL: http://svn.apache.org/viewvc?rev=1233196&view=rev
Log:
SOLR-2718: Lazy load response writers: backport to branch_3x
Added:
lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-lazywriter.xml
- copied unchanged from r1189958, lucene/dev/trunk/solr/core/src/test-files/solr/conf/solrconfig-lazywriter.xml
Modified:
lucene/dev/branches/branch_3x/ (props changed)
lucene/dev/branches/branch_3x/lucene/ (props changed)
lucene/dev/branches/branch_3x/solr/ (props changed)
lucene/dev/branches/branch_3x/solr/CHANGES.txt
lucene/dev/branches/branch_3x/solr/core/ (props changed)
lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java
lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/crazy-path-to-config.xml
lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/OutputWriterTest.java
lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml
lucene/dev/branches/branch_3x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1233196&r1=1233195&r2=1233196&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Thu Jan 19 06:25:31 2012
@@ -124,6 +124,9 @@ Other Changes
structure will disappear in 4.0. Errors should be caught and logged at the
top-most level or logged and NOT propagated up the chain. (Erick Erickson)
+* SOLR-2718: Add ability to lazy load response writers, defined with startup="lazy".
+ (ehatcher)
+
Build
----------------------
* SOLR-2487: Add build target to package war without slf4j jars (janhoy)
Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java?rev=1233196&r1=1233195&r2=1233196&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java Thu Jan 19 06:25:31 2012
@@ -64,10 +64,7 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -325,8 +322,8 @@ public final class SolrCore implements S
*
* @see SolrCoreAware
*/
- public void registerResponseWriter( String name, QueryResponseWriter responseWriter ){
- responseWriters.put(name, responseWriter);
+ public QueryResponseWriter registerResponseWriter( String name, QueryResponseWriter responseWriter ){
+ return responseWriters.put(name, responseWriter);
}
@@ -488,6 +485,10 @@ public final class SolrCore implements S
}
return instance;
}
+
+ private QueryResponseWriter createQueryResponseWriter(String className) {
+ return createInstance(className, QueryResponseWriter.class, "Query Response Writer");
+ }
/**
*
@@ -1466,7 +1467,54 @@ public final class SolrCore implements S
/** Configure the query response writers. There will always be a default writer; additional
* writers may also be configured. */
private void initWriters() {
- defaultResponseWriter = initPlugins(responseWriters, QueryResponseWriter.class);
+ // use link map so we iterate in the same order
+ Map<PluginInfo,QueryResponseWriter> writers = new LinkedHashMap<PluginInfo,QueryResponseWriter>();
+ for (PluginInfo info : solrConfig.getPluginInfos(QueryResponseWriter.class.getName())) {
+ try {
+ QueryResponseWriter writer;
+ String startup = info.attributes.get("startup") ;
+ if( startup != null ) {
+ if( "lazy".equals(startup) ) {
+ log.info("adding lazy queryResponseWriter: " + info.className);
+ writer = new LazyQueryResponseWriterWrapper(this, info.className, info.initArgs );
+ } else {
+ throw new Exception( "Unknown startup value: '"+startup+"' for: "+info.className );
+ }
+ } else {
+ writer = createQueryResponseWriter(info.className);
+ }
+ writers.put(info,writer);
+ QueryResponseWriter old = registerResponseWriter(info.name, writer);
+ if(old != null) {
+ log.warn("Multiple queryResponseWriter registered to the same name: " + info.name + " ignoring: " + old.getClass().getName());
+ }
+ if(info.isDefault()){
+ defaultResponseWriter = writer;
+ if(defaultResponseWriter != null)
+ log.warn("Multiple default queryResponseWriter registered ignoring: " + old.getClass().getName());
+ }
+ log.info("created "+info.name+": " + info.className);
+ } catch (Exception ex) {
+ SolrConfig.severeErrors.add( ex );
+ SolrException e = new SolrException
+ (SolrException.ErrorCode.SERVER_ERROR, "QueryResponseWriter init failure", ex);
+ SolrException.logOnce(log,null,e);
+ throw e;
+ }
+ }
+
+ // we've now registered all handlers, time to init them in the same order
+ for (Map.Entry<PluginInfo,QueryResponseWriter> entry : writers.entrySet()) {
+ PluginInfo info = entry.getKey();
+ QueryResponseWriter writer = entry.getValue();
+ responseWriters.put(info.name, writer);
+ if (writer instanceof PluginInfoInitialized) {
+ ((PluginInfoInitialized) writer).init(info);
+ } else{
+ writer.init(info.initArgs);
+ }
+ }
+
for (Map.Entry<String, QueryResponseWriter> entry : DEFAULT_RESPONSE_WRITERS.entrySet()) {
if(responseWriters.get(entry.getKey()) == null) responseWriters.put(entry.getKey(), entry.getValue());
}
@@ -1685,6 +1733,46 @@ public final class SolrCore implements S
return lst;
}
+ public final class LazyQueryResponseWriterWrapper implements QueryResponseWriter {
+ private SolrCore _core;
+ private String _className;
+ private NamedList _args;
+ private QueryResponseWriter _writer;
+
+ public LazyQueryResponseWriterWrapper(SolrCore core, String className, NamedList args) {
+ _core = core;
+ _className = className;
+ _args = args;
+ _writer = null;
+ }
+
+ public synchronized QueryResponseWriter getWrappedWriter()
+ {
+ if( _writer == null ) {
+ try {
+ QueryResponseWriter writer = createQueryResponseWriter(_className);
+ writer.init( _args );
+ _writer = writer;
+ }
+ catch( Exception ex ) {
+ throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "lazy loading error", ex );
+ }
+ }
+ return _writer;
+ }
+
+ public void init(NamedList args) {
+ // do nothing
+ }
+
+ public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException {
+ getWrappedWriter().write(writer, request, response);
+ }
+
+ public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
+ return getWrappedWriter().getContentType(request, response);
+ }
+ }
}
Modified: lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/crazy-path-to-config.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/crazy-path-to-config.xml?rev=1233196&r1=1233195&r2=1233196&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/crazy-path-to-config.xml (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/crazy-path-to-config.xml Thu Jan 19 06:25:31 2012
@@ -66,7 +66,7 @@
<queryResponseWriter name="standard" class="solr.XMLResponseWriter"/>
- <queryResponseWriter name="useless" class="org.apache.solr.OutputWriterTest$UselessOutputWriter"/>
+ <queryResponseWriter name="useless" class="org.apache.solr.OutputWriterTest$UselessOutputWriter" startup="lazy"/>
<queryResponseWriter name="xslt" class="solr.XSLTResponseWriter"/>
Modified: lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/OutputWriterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/OutputWriterTest.java?rev=1233196&r1=1233195&r2=1233196&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/OutputWriterTest.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/OutputWriterTest.java Thu Jan 19 06:25:31 2012
@@ -21,9 +21,11 @@ import java.io.IOException;
import java.io.Writer;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.QueryResponseWriter;
import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.response.XMLResponseWriter;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -91,7 +93,15 @@ public class OutputWriterTest extends So
// System.out.println(out);
assertTrue(out.contains("DUMMY"));
}
-
+
+ public void testLazy() {
+ QueryResponseWriter qrw = h.getCore().getQueryResponseWriter("useless");
+ assertTrue("Should be a lazy class", qrw instanceof SolrCore.LazyQueryResponseWriterWrapper);
+
+ qrw = h.getCore().getQueryResponseWriter("xml");
+ assertTrue("Should not be a lazy class", qrw instanceof XMLResponseWriter);
+
+ }
////////////////////////////////////////////////////////////////////////////
/** An output writer that doesn't do anything useful. */
Modified: lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml?rev=1233196&r1=1233195&r2=1233196&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml (original)
+++ lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml Thu Jan 19 06:25:31 2012
@@ -1549,9 +1549,7 @@
<!--
Custom response writers can be declared as needed...
-->
- <!-- The solr.velocity.enabled flag is used by Solr's test cases so that this response writer is not
- loaded (causing an error if contrib/velocity has not been built fully) -->
- <queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" enable="${solr.velocity.enabled:true}"/>
+ <queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" startup="lazy"/>
<!-- XSLT response writer transforms the XML output by any xslt file found
Modified: lucene/dev/branches/branch_3x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java?rev=1233196&r1=1233195&r2=1233196&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java (original)
+++ lucene/dev/branches/branch_3x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java Thu Jan 19 06:25:31 2012
@@ -55,9 +55,6 @@ public class JettyWebappTest extends Luc
System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
String path = ExternalPaths.WEBAPP_HOME;
- // disable VelocityResponseWriter from example configuration
- System.setProperty("solr.velocity.enabled", "false");
-
server = new Server(port);
// insecure: only use for tests!!!!
server.setSessionIdManager(new HashSessionIdManager(new Random(random.nextLong())));
Modified: lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java?rev=1233196&r1=1233195&r2=1233196&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java (original)
+++ lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java Thu Jan 19 06:25:31 2012
@@ -47,9 +47,6 @@ abstract public class SolrJettyTestBase
System.setProperty( "solr.solr.home", solrHome);
System.setProperty( "solr.data.dir", dataDir.getCanonicalPath() );
- // disable VelocityResponseWriter from example configuration
- System.setProperty("solr.velocity.enabled", "false");
-
context = context==null ? "/solr" : context;
SolrJettyTestBase.context = context;
jetty = new JettySolrRunner( context, 0, configFile );
Modified: lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1233196&r1=1233195&r2=1233196&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/branches/branch_3x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Thu Jan 19 06:25:31 2012
@@ -110,7 +110,6 @@ public abstract class SolrTestCaseJ4 ext
if (solrHome != null) {
System.setProperty("solr.solr.home", solrHome);
}
- System.setProperty("solr.velocity.enabled", "false");
initCore();
}