Skip to content

Commit a7f5502

Browse files
authored
SOLR-17859: Restore the use of TimeLimitingBulkScorer. (#3634)
1 parent d1b373d commit a7f5502

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private Collector buildAndRunCollectorChain(
326326

327327
try {
328328
try {
329-
super.search(query, collector);
329+
search(query, collector);
330330
} finally {
331331
// The complete() method can use the collectors, so this needs to be surrounded by the same
332332
// catch logic that limit collecting
@@ -782,32 +782,33 @@ public QueryResult search(QueryResult qr, QueryCommand cmd) throws IOException {
782782
return qr;
783783
}
784784

785-
/*@Override
786-
TBD . This is overridden to exit the query when limits are reached
787-
protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector)
788-
throws IOException {
785+
@Override
786+
public void search(Query query, Collector collector) throws IOException {
789787
QueryLimits queryLimits = QueryLimits.getCurrentLimits();
790-
if (EnvUtils.getPropertyAsBool(EXITABLE_READER_PROPERTY, Boolean.FALSE)
791-
|| !queryLimits.isLimitsEnabled()) {
788+
if (!queryLimits.isLimitsEnabled()) {
792789
// no timeout. Pass through to super class
793-
super.search(leaves, weight, collector);
790+
super.search(query, collector);
794791
} else {
795792
// Timeout enabled! This impl is maybe a hack. Use Lucene's IndexSearcher timeout.
796793
// But only some queries have it so don't use on "this" (SolrIndexSearcher), not to mention
797794
// that timedOut() might race with concurrent queries (dubious design).
798795
// So we need to make a new IndexSearcher instead of using "this".
799-
new IndexSearcher(reader) { // cheap, actually!
796+
// Make sure to reuse the existing executor.
797+
new IndexSearcher(
798+
reader, core.getCoreContainer().getIndexSearcherExecutor()) { // cheap, actually!
800799
void searchWithTimeout() throws IOException {
801800
setTimeout(queryLimits); // Lucene's method name is less than ideal here...
802-
super.search(leaves, weight, collector); // FYI protected access
801+
// XXX Deprecated in Lucene 10, we should probably use search(Query, CollectorManager)
802+
// instead
803+
super.search(query, collector);
803804
if (timedOut()) {
804805
throw new QueryLimitsExceededException(
805806
"Limits exceeded! (search): " + queryLimits.limitStatusMessage());
806807
}
807808
}
808809
}.searchWithTimeout();
809810
}
810-
}*/
811+
}
811812

812813
/**
813814
* Retrieve the {@link Document} instance corresponding to the document id.

solr/core/src/test/org/apache/solr/search/TestQueryLimits.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void testQueryLimits() throws Exception {
6767
"SearchHandler.handleRequestBody",
6868
"QueryComponent",
6969
"QueryComponent.process",
70+
"TimeLimitingBulkScorer.score",
7071
"FacetComponent.process:2"
7172
};
7273
for (String matchingExpr : matchingExprTests) {

solr/test-framework/src/java/org/apache/solr/search/CallerSpecificQueryLimit.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import java.util.Collection;
2222
import java.util.HashMap;
2323
import java.util.HashSet;
24-
import java.util.LinkedHashSet;
2524
import java.util.List;
2625
import java.util.Map;
2726
import java.util.Optional;
2827
import java.util.Set;
28+
import java.util.concurrent.ConcurrentHashMap;
2929
import java.util.concurrent.atomic.AtomicInteger;
3030
import java.util.stream.Collectors;
3131
import org.slf4j.Logger;
@@ -53,10 +53,10 @@ public class CallerSpecificQueryLimit implements QueryLimit {
5353
// className -> set of method names
5454
private final Map<String, Set<String>> interestingCallers = new HashMap<>();
5555
// expr -> initial count
56-
private final Map<String, Integer> maxCounts = new HashMap<>();
56+
private final Map<String, Integer> maxCounts = new ConcurrentHashMap<>();
5757
// expr -> current count
58-
private final Map<String, AtomicInteger> callCounts = new HashMap<>();
59-
private Set<String> trippedBy = new LinkedHashSet<>();
58+
private final Map<String, AtomicInteger> callCounts = new ConcurrentHashMap<>();
59+
private Set<String> trippedBy = ConcurrentHashMap.newKeySet();
6060

6161
/**
6262
* Signal a timeout in places that match the calling classes (and methods).

0 commit comments

Comments
 (0)