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
|
* SOLR-9254: GraphTermsQueryQParserPlugin throws NPE when field being searched is not present in segment
|
||||||
(Joel Bernstein)
|
(Joel Bernstein)
|
||||||
|
|
||||||
|
* SOLR-8657: Fix SolrRequestInfo error logs if QuerySenderListener is being used (Pascal Chollet,
|
||||||
|
Tomás Fernández Löbbe)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
|
|
|
@ -48,9 +48,9 @@ public class QuerySenderListener extends AbstractSolrEventListener {
|
||||||
log.info("QuerySenderListener sending requests to " + newSearcher);
|
log.info("QuerySenderListener sending requests to " + newSearcher);
|
||||||
List<NamedList> allLists = (List<NamedList>)getArgs().get("queries");
|
List<NamedList> allLists = (List<NamedList>)getArgs().get("queries");
|
||||||
if (allLists == null) return;
|
if (allLists == null) return;
|
||||||
|
boolean createNewReqInfo = SolrRequestInfo.getRequestInfo() == null;
|
||||||
for (NamedList nlst : allLists) {
|
for (NamedList nlst : allLists) {
|
||||||
SolrQueryRequest req = null;
|
SolrQueryRequest req = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// bind the request to a particular searcher (the newSearcher)
|
// bind the request to a particular searcher (the newSearcher)
|
||||||
NamedList params = addEventParms(currentSearcher, nlst);
|
NamedList params = addEventParms(currentSearcher, nlst);
|
||||||
|
@ -64,7 +64,11 @@ public class QuerySenderListener extends AbstractSolrEventListener {
|
||||||
};
|
};
|
||||||
|
|
||||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
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);
|
getCore().execute(getCore().getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
|
||||||
|
|
||||||
// Retrieve the Document instances (not just the ids) to warm
|
// 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.
|
// the failure should have already been logged.
|
||||||
} finally {
|
} finally {
|
||||||
if (req != null) req.close();
|
if (req != null) req.close();
|
||||||
SolrRequestInfo.clearRequestInfo();
|
if (createNewReqInfo) SolrRequestInfo.clearRequestInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("QuerySenderListener done.");
|
log.info("QuerySenderListener done.");
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class SolrRequestInfo {
|
||||||
return new ExecutorUtil.InheritableThreadLocalProvider() {
|
return new ExecutorUtil.InheritableThreadLocalProvider() {
|
||||||
@Override
|
@Override
|
||||||
public void store(AtomicReference ctx) {
|
public void store(AtomicReference ctx) {
|
||||||
SolrRequestInfo me = threadLocal.get();
|
SolrRequestInfo me = SolrRequestInfo.getRequestInfo();
|
||||||
if (me != null) ctx.set(me);
|
if (me != null) ctx.set(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,13 +156,13 @@ public class SolrRequestInfo {
|
||||||
SolrRequestInfo me = (SolrRequestInfo) ctx.get();
|
SolrRequestInfo me = (SolrRequestInfo) ctx.get();
|
||||||
if (me != null) {
|
if (me != null) {
|
||||||
ctx.set(null);
|
ctx.set(null);
|
||||||
threadLocal.set(me);
|
SolrRequestInfo.setRequestInfo(me);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clean(AtomicReference ctx) {
|
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.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.params.EventParams;
|
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.search.SolrIndexSearcher;
|
||||||
import org.apache.solr.util.RefCounted;
|
import org.apache.solr.util.RefCounted;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -38,11 +40,16 @@ public class TestQuerySenderListener extends SolrTestCaseJ4 {
|
||||||
// in the same VM
|
// in the same VM
|
||||||
preInitMockListenerCount = MockEventListener.getCreateCount();
|
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");
|
initCore("solrconfig-querysender.xml","schema.xml");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListenerCreationCounts() {
|
public void testListenerCreationCounts() {
|
||||||
SolrCore core = h.getCore();
|
h.getCore();
|
||||||
|
|
||||||
assertEquals("Unexpected number of listeners created",
|
assertEquals("Unexpected number of listeners created",
|
||||||
EXPECTED_MOCK_LISTENER_INSTANCES,
|
EXPECTED_MOCK_LISTENER_INSTANCES,
|
||||||
|
@ -73,14 +80,15 @@ public class TestQuerySenderListener extends SolrTestCaseJ4 {
|
||||||
String evt = mock.req.getParams().get(EventParams.EVENT);
|
String evt = mock.req.getParams().get(EventParams.EVENT);
|
||||||
assertNotNull("Event is null", evt);
|
assertNotNull("Event is null", evt);
|
||||||
assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER) == true);
|
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());
|
RefCounted<SolrIndexSearcher> newSearcherRef = core.getSearcher();
|
||||||
|
|
||||||
qsl.newSearcher(newSearcher, currentSearcher);
|
|
||||||
evt = mock.req.getParams().get(EventParams.EVENT);
|
evt = mock.req.getParams().get(EventParams.EVENT);
|
||||||
assertNotNull("Event is null", evt);
|
assertNotNull("Event is null", evt);
|
||||||
assertTrue(evt + " is not equal to " + EventParams.NEW_SEARCHER, evt.equals(EventParams.NEW_SEARCHER) == true);
|
assertTrue(evt + " is not equal to " + EventParams.NEW_SEARCHER, evt.equals(EventParams.NEW_SEARCHER) == true);
|
||||||
newSearcher.close();
|
newSearcherRef.decref();
|
||||||
currentSearcherRef.decref();
|
currentSearcherRef.decref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue