mirror of https://github.com/apache/lucene.git
SOLR-8657: Fix SolrRequestInfo error logs if QuerySenderListener is being used
This commit is contained in:
parent
3f7acb5cf9
commit
4070bdd8d8
|
@ -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
|
||||
----------------------
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -74,13 +81,14 @@ public class TestQuerySenderListener extends SolrTestCaseJ4 {
|
|||
assertNotNull("Event is null", evt);
|
||||
assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER) == true);
|
||||
|
||||
SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getNewIndexDir(), core.getLatestSchema(), core.getSolrConfig().indexConfig, "testQuerySenderListener", false, core.getDirectoryFactory());
|
||||
assertU(adoc("id", "1"));
|
||||
assertU(commit());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue