SOLR-2219: stop calling SolrRequestHandler.init twice per instance

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1045302 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2010-12-13 18:57:24 +00:00
parent 4aa908e6ad
commit 34a6968476
5 changed files with 41 additions and 7 deletions

View File

@ -566,6 +566,9 @@ Bug Fixes
* SOLR-2252: When a child entity in nested entities is rootEntity="true", delta-import doesn't work. * SOLR-2252: When a child entity in nested entities is rootEntity="true", delta-import doesn't work.
(koji) (koji)
* SOLR-2219: The init() method of every SolrRequestHandler was being
called twice. (ambikeshwar singh and hossman)
Other Changes Other Changes
---------------------- ----------------------

View File

@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -137,7 +138,8 @@ final class RequestHandlers {
*/ */
void initHandlersFromConfig(SolrConfig config ){ void initHandlersFromConfig(SolrConfig config ){
Map<PluginInfo,SolrRequestHandler> handlers = new HashMap<PluginInfo,SolrRequestHandler>(); // use link map so we iterate in the same order
Map<PluginInfo,SolrRequestHandler> handlers = new LinkedHashMap<PluginInfo,SolrRequestHandler>();
for (PluginInfo info : config.getPluginInfos(SolrRequestHandler.class.getName())) { for (PluginInfo info : config.getPluginInfos(SolrRequestHandler.class.getName())) {
try { try {
SolrRequestHandler requestHandler; SolrRequestHandler requestHandler;
@ -153,11 +155,6 @@ final class RequestHandlers {
requestHandler = core.createRequestHandler(info.className); requestHandler = core.createRequestHandler(info.className);
} }
handlers.put(info,requestHandler); handlers.put(info,requestHandler);
if (requestHandler instanceof PluginInfoInitialized) {
((PluginInfoInitialized) requestHandler).init(info);
} else{
requestHandler.init(info.initArgs);
}
SolrRequestHandler old = register(info.name, requestHandler); SolrRequestHandler old = register(info.name, requestHandler);
if(old != null) { if(old != null) {
log.warn("Multiple requestHandler registered to the same name: " + info.name + " ignoring: " + old.getClass().getName()); log.warn("Multiple requestHandler registered to the same name: " + info.name + " ignoring: " + old.getClass().getName());
@ -176,8 +173,16 @@ final class RequestHandlers {
throw e; throw e;
} }
} }
// we've now registered all handlers, time ot init them in the same order
for (Map.Entry<PluginInfo,SolrRequestHandler> entry : handlers.entrySet()) { for (Map.Entry<PluginInfo,SolrRequestHandler> entry : handlers.entrySet()) {
entry.getValue().init(entry.getKey().initArgs); PluginInfo info = entry.getKey();
SolrRequestHandler requestHandler = entry.getValue();
if (requestHandler instanceof PluginInfoInitialized) {
((PluginInfoInitialized) requestHandler).init(info);
} else{
requestHandler.init(info.initArgs);
}
} }
if(get("") == null) register("", get(DEFAULT_HANDLER_NAME)); if(get("") == null) register("", get(DEFAULT_HANDLER_NAME));

View File

@ -19,6 +19,9 @@ package org.apache.solr.core;
import org.apache.solr.handler.RequestHandlerBase; import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.common.util.NamedList;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
@ -29,6 +32,13 @@ public class MockQuerySenderListenerReqHandler extends RequestHandlerBase {
public SolrQueryRequest req; public SolrQueryRequest req;
public SolrQueryResponse rsp; public SolrQueryResponse rsp;
AtomicInteger initCounter = new AtomicInteger(0);
public void init(NamedList args) {
initCounter.incrementAndGet();
super.init(args);
}
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
this.req = req; this.req = req;
this.rsp = rsp; this.rsp = rsp;
@ -53,4 +63,11 @@ public class MockQuerySenderListenerReqHandler extends RequestHandlerBase {
String result = null; String result = null;
return result; return result;
} }
public NamedList<Object> getStatistics() {
NamedList<Object> lst = super.getStatistics();
lst.add("initCount", initCounter.intValue());
return lst;
}
} }

View File

@ -29,6 +29,14 @@ public class RequestHandlersTest extends SolrTestCaseJ4 {
initCore("solrconfig.xml", "schema.xml"); initCore("solrconfig.xml", "schema.xml");
} }
@Test
public void testInitCount() {
SolrCore core = h.getCore();
SolrRequestHandler handler = core.getRequestHandler( "mock" );
assertEquals("Incorrect init count",
1, handler.getStatistics().get("initCount"));
}
@Test @Test
public void testLazyLoading() { public void testLazyLoading() {
SolrCore core = h.getCore(); SolrCore core = h.getCore();

View File

@ -304,6 +304,7 @@
<lst name="lst1"> <str name="op">sqrt</str> <int name="val">2</int> </lst> <lst name="lst1"> <str name="op">sqrt</str> <int name="val">2</int> </lst>
<lst name="lst2"> <str name="op">log</str> <float name="val">10</float> </lst> <lst name="lst2"> <str name="op">log</str> <float name="val">10</float> </lst>
</requestHandler> </requestHandler>
<requestHandler name="mock" class="org.apache.solr.core.MockQuerySenderListenerReqHandler"/>
<requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" /> <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />