mirror of https://github.com/apache/lucene.git
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:
parent
4aa908e6ad
commit
34a6968476
|
@ -566,6 +566,9 @@ Bug Fixes
|
|||
* SOLR-2252: When a child entity in nested entities is rootEntity="true", delta-import doesn't work.
|
||||
(koji)
|
||||
|
||||
* SOLR-2219: The init() method of every SolrRequestHandler was being
|
||||
called twice. (ambikeshwar singh and hossman)
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -137,7 +138,8 @@ final class RequestHandlers {
|
|||
*/
|
||||
|
||||
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())) {
|
||||
try {
|
||||
SolrRequestHandler requestHandler;
|
||||
|
@ -153,11 +155,6 @@ final class RequestHandlers {
|
|||
requestHandler = core.createRequestHandler(info.className);
|
||||
}
|
||||
handlers.put(info,requestHandler);
|
||||
if (requestHandler instanceof PluginInfoInitialized) {
|
||||
((PluginInfoInitialized) requestHandler).init(info);
|
||||
} else{
|
||||
requestHandler.init(info.initArgs);
|
||||
}
|
||||
SolrRequestHandler old = register(info.name, requestHandler);
|
||||
if(old != null) {
|
||||
log.warn("Multiple requestHandler registered to the same name: " + info.name + " ignoring: " + old.getClass().getName());
|
||||
|
@ -176,8 +173,16 @@ final class RequestHandlers {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// we've now registered all handlers, time ot init them in the same order
|
||||
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));
|
||||
|
|
|
@ -19,6 +19,9 @@ package org.apache.solr.core;
|
|||
import org.apache.solr.handler.RequestHandlerBase;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
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 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 {
|
||||
this.req = req;
|
||||
this.rsp = rsp;
|
||||
|
@ -53,4 +63,11 @@ public class MockQuerySenderListenerReqHandler extends RequestHandlerBase {
|
|||
String result = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public NamedList<Object> getStatistics() {
|
||||
NamedList<Object> lst = super.getStatistics();
|
||||
lst.add("initCount", initCounter.intValue());
|
||||
return lst;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,14 @@ public class RequestHandlersTest extends SolrTestCaseJ4 {
|
|||
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
|
||||
public void testLazyLoading() {
|
||||
SolrCore core = h.getCore();
|
||||
|
|
|
@ -304,6 +304,7 @@
|
|||
<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>
|
||||
</requestHandler>
|
||||
<requestHandler name="mock" class="org.apache.solr.core.MockQuerySenderListenerReqHandler"/>
|
||||
|
||||
<requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue