SOLR-8657: Fix SolrRequestInfo error logs if QuerySenderListener is being used

This commit is contained in:
Tomas Fernandez Lobbe 2016-06-28 13:11:40 -07:00
parent 3f7acb5cf9
commit 4070bdd8d8
4 changed files with 25 additions and 11 deletions

View File

@ -89,6 +89,8 @@ Bug Fixes
* SOLR-9254: GraphTermsQueryQParserPlugin throws NPE when field being searched is not present in segment
(Joel Bernstein)
* SOLR-8657: Fix SolrRequestInfo error logs if QuerySenderListener is being used (Pascal Chollet,
Tomás Fernández Löbbe)
Optimizations
----------------------

View File

@ -48,9 +48,9 @@ public class QuerySenderListener extends AbstractSolrEventListener {
log.info("QuerySenderListener sending requests to " + newSearcher);
List<NamedList> allLists = (List<NamedList>)getArgs().get("queries");
if (allLists == null) return;
boolean createNewReqInfo = SolrRequestInfo.getRequestInfo() == null;
for (NamedList nlst : allLists) {
SolrQueryRequest req = null;
try {
// bind the request to a particular searcher (the newSearcher)
NamedList params = addEventParms(currentSearcher, nlst);
@ -64,7 +64,11 @@ public class QuerySenderListener extends AbstractSolrEventListener {
};
SolrQueryResponse rsp = new SolrQueryResponse();
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
if (createNewReqInfo) {
// SolrRequerstInfo for this thread could have been transferred from the parent
// thread.
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
}
getCore().execute(getCore().getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
// Retrieve the Document instances (not just the ids) to warm
@ -89,7 +93,7 @@ public class QuerySenderListener extends AbstractSolrEventListener {
// the failure should have already been logged.
} finally {
if (req != null) req.close();
SolrRequestInfo.clearRequestInfo();
if (createNewReqInfo) SolrRequestInfo.clearRequestInfo();
}
}
log.info("QuerySenderListener done.");

View File

@ -147,7 +147,7 @@ public class SolrRequestInfo {
return new ExecutorUtil.InheritableThreadLocalProvider() {
@Override
public void store(AtomicReference ctx) {
SolrRequestInfo me = threadLocal.get();
SolrRequestInfo me = SolrRequestInfo.getRequestInfo();
if (me != null) ctx.set(me);
}
@ -156,13 +156,13 @@ public class SolrRequestInfo {
SolrRequestInfo me = (SolrRequestInfo) ctx.get();
if (me != null) {
ctx.set(null);
threadLocal.set(me);
SolrRequestInfo.setRequestInfo(me);
}
}
@Override
public void clean(AtomicReference ctx) {
threadLocal.remove();
SolrRequestInfo.clearRequestInfo();
}
};
}

View File

@ -18,6 +18,8 @@ package org.apache.solr.core;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.EventParams;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.util.RefCounted;
import org.junit.BeforeClass;
@ -38,11 +40,16 @@ public class TestQuerySenderListener extends SolrTestCaseJ4 {
// in the same VM
preInitMockListenerCount = MockEventListener.getCreateCount();
if (usually()) {
// This is set by the SolrDispatchFilter, used in Http calls but not Embedded
ExecutorUtil.addThreadLocalProvider(SolrRequestInfo.getInheritableThreadLocalProvider());
}
initCore("solrconfig-querysender.xml","schema.xml");
}
public void testListenerCreationCounts() {
SolrCore core = h.getCore();
h.getCore();
assertEquals("Unexpected number of listeners created",
EXPECTED_MOCK_LISTENER_INSTANCES,
@ -73,14 +80,15 @@ public class TestQuerySenderListener extends SolrTestCaseJ4 {
String evt = mock.req.getParams().get(EventParams.EVENT);
assertNotNull("Event is null", evt);
assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER) == true);
assertU(adoc("id", "1"));
assertU(commit());
SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getNewIndexDir(), core.getLatestSchema(), core.getSolrConfig().indexConfig, "testQuerySenderListener", false, core.getDirectoryFactory());
qsl.newSearcher(newSearcher, currentSearcher);
RefCounted<SolrIndexSearcher> newSearcherRef = core.getSearcher();
evt = mock.req.getParams().get(EventParams.EVENT);
assertNotNull("Event is null", evt);
assertTrue(evt + " is not equal to " + EventParams.NEW_SEARCHER, evt.equals(EventParams.NEW_SEARCHER) == true);
newSearcher.close();
newSearcherRef.decref();
currentSearcherRef.decref();
}