Skip to content

Commit 3912cf6

Browse files
authored
SOLR-17173: throw exception on attempting enable distrib IDF with LocalStatsCache (#2332)
follow up SOLR-17058 (#2046)
1 parent 6697e8a commit 3912cf6

File tree

8 files changed

+56
-26
lines changed

8 files changed

+56
-26
lines changed

solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
import org.apache.solr.search.grouping.endresulttransformer.GroupedEndResultTransformer;
116116
import org.apache.solr.search.grouping.endresulttransformer.MainEndResultTransformer;
117117
import org.apache.solr.search.grouping.endresulttransformer.SimpleEndResultTransformer;
118+
import org.apache.solr.search.stats.LocalStatsCache;
118119
import org.apache.solr.search.stats.StatsCache;
119120
import org.apache.solr.util.SolrPluginUtils;
120121
import org.apache.solr.util.SolrResponseUtil;
@@ -146,6 +147,18 @@ public void prepare(ResponseBuilder rb) throws IOException {
146147
// Generate Query ID
147148
rb.queryID = generateQueryID(req);
148149
}
150+
// set the flag for distributed stats
151+
if (req.getSearcher().getStatsCache().getClass().equals(LocalStatsCache.class)) {
152+
if (params.getPrimitiveBool(CommonParams.DISTRIB_STATS_CACHE)) {
153+
throw new SolrException(
154+
SolrException.ErrorCode.BAD_REQUEST,
155+
"Explicitly set "
156+
+ CommonParams.DISTRIB_STATS_CACHE
157+
+ "=true is not supported with "
158+
+ LocalStatsCache.class.getSimpleName());
159+
}
160+
}
161+
rb.setDistribStatsDisabled(!params.getBool(CommonParams.DISTRIB_STATS_CACHE, true));
149162
}
150163

151164
// Set field flags
@@ -168,9 +181,6 @@ public void prepare(ResponseBuilder rb) throws IOException {
168181
rb.setQueryString(queryString);
169182
}
170183

171-
// set the flag for distributed stats
172-
rb.setEnableDistribStats(params.getBool(CommonParams.DISTRIB_STATS_CACHE, true));
173-
174184
try {
175185
QParser parser = QParser.getParser(rb.getQueryString(), defType, req);
176186
Query q = parser.getQuery();
@@ -368,7 +378,7 @@ public void process(ResponseBuilder rb) throws IOException {
368378
QueryCommand cmd = rb.createQueryCommand();
369379
cmd.setTimeAllowed(timeAllowed);
370380
cmd.setMinExactCount(getMinExactCount(params));
371-
cmd.setEnableDistribStats(rb.isEnableDistribStats());
381+
cmd.setDistribStatsDisabled(rb.isDistribStatsDisabled());
372382

373383
boolean isCancellableQuery = params.getBool(CommonParams.IS_QUERY_CANCELLABLE, false);
374384

@@ -740,7 +750,7 @@ protected void regularFinishStage(ResponseBuilder rb) {
740750

741751
protected void createDistributedStats(ResponseBuilder rb) {
742752
StatsCache cache = rb.req.getSearcher().getStatsCache();
743-
if (rb.isEnableDistribStats()
753+
if (!rb.isDistribStatsDisabled()
744754
&& ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0
745755
|| rb.getSortSpec().includesScore())) {
746756
ShardRequest sreq = cache.retrieveStatsRequest(rb);

solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class ResponseBuilder {
7474
private String cancellationUUID;
7575
private String taskStatusCheckUUID;
7676
private boolean isTaskListRequest;
77-
private boolean isEnableDistribStats = true;
77+
private boolean isDistribStatsDisabled;
7878

7979
private QParser qparser = null;
8080
private String queryString = null;
@@ -519,11 +519,11 @@ public String getTaskStatusCheckUUID() {
519519
return taskStatusCheckUUID;
520520
}
521521

522-
public void setEnableDistribStats(boolean isEnableDistribStats) {
523-
this.isEnableDistribStats = isEnableDistribStats;
522+
public void setDistribStatsDisabled(boolean isEnableDistribStats) {
523+
this.isDistribStatsDisabled = isEnableDistribStats;
524524
}
525525

526-
public boolean isEnableDistribStats() {
527-
return isEnableDistribStats;
526+
public boolean isDistribStatsDisabled() {
527+
return isDistribStatsDisabled;
528528
}
529529
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class QueryCommand {
3939
private long timeAllowed = -1;
4040
private int minExactCount = Integer.MAX_VALUE;
4141
private CursorMark cursorMark;
42-
private boolean enableDistribStats = true;
42+
private boolean distribStatsDisabled;
4343

4444
public CursorMark getCursorMark() {
4545
return cursorMark;
@@ -222,11 +222,11 @@ public boolean isQueryCancellable() {
222222
return isQueryCancellable;
223223
}
224224

225-
public void setEnableDistribStats(boolean enableDistribStats) {
226-
this.enableDistribStats = enableDistribStats;
225+
public void setDistribStatsDisabled(boolean distribStatsDisabled) {
226+
this.distribStatsDisabled = distribStatsDisabled;
227227
}
228228

229-
public boolean isEnableDistribStats() {
230-
return enableDistribStats;
229+
public boolean isDistribStatsDisabled() {
230+
return distribStatsDisabled;
231231
}
232232
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ public final class QueryResultKey implements Accountable {
4040
final List<Query> filters;
4141
final int nc_flags; // non-comparable flags... ignored by hashCode and equals
4242
final int minExactCount;
43-
final boolean enableDistribStats;
43+
final boolean distribStatsDisabled;
4444
private final int hc; // cached hashCode
4545
private final long ramBytesUsed; // cached
4646

4747
public QueryResultKey(Query query, List<Query> filters, Sort sort, int nc_flags) {
48-
this(query, filters, sort, nc_flags, Integer.MAX_VALUE, true);
48+
this(query, filters, sort, nc_flags, Integer.MAX_VALUE, false);
4949
}
5050

5151
public QueryResultKey(
5252
Query query, List<Query> filters, Sort sort, int nc_flags, int minExactCount) {
53-
this(query, filters, sort, nc_flags, minExactCount, true);
53+
this(query, filters, sort, nc_flags, minExactCount, false);
5454
}
5555

5656
public QueryResultKey(
@@ -59,12 +59,12 @@ public QueryResultKey(
5959
Sort sort,
6060
int nc_flags,
6161
int minExactCount,
62-
boolean enableDistribStats) {
62+
boolean distribStatsDisabled) {
6363
this.query = query;
6464
this.sort = sort;
6565
this.nc_flags = nc_flags;
6666
this.minExactCount = minExactCount;
67-
this.enableDistribStats = enableDistribStats;
67+
this.distribStatsDisabled = distribStatsDisabled;
6868

6969
int h = query.hashCode();
7070

@@ -124,7 +124,7 @@ public boolean equals(Object o) {
124124
if (!this.query.equals(other.query)) return false;
125125
if (!unorderedCompare(this.filters, other.filters)) return false;
126126
if (this.minExactCount != other.minExactCount) return false;
127-
if (this.enableDistribStats != other.enableDistribStats) return false;
127+
if (this.distribStatsDisabled != other.distribStatsDisabled) return false;
128128

129129
for (int i = 0; i < sfields.size(); i++) {
130130
SortField sf1 = this.sfields.get(i);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ private void getDocListC(QueryResult qr, QueryCommand cmd) throws IOException {
15671567
cmd.getSort(),
15681568
flags,
15691569
cmd.getMinExactCount(),
1570-
cmd.isEnableDistribStats());
1570+
cmd.isDistribStatsDisabled());
15711571
if ((flags & NO_CHECK_QCACHE) == 0) {
15721572
superset = queryResultCache.get(key);
15731573

solr/core/src/test/org/apache/solr/core/QueryResultKeyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,16 @@ public void testDisableDistribStats() {
214214
int[] nums = smallArrayOfRandomNumbers();
215215
final Query base = new FlatHashTermQuery("base");
216216
assertKeyEquals(
217-
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, Integer.MAX_VALUE, true),
217+
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, Integer.MAX_VALUE, false),
218218
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0));
219219
assertKeyEquals(
220-
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, 10, true),
220+
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, 10, false),
221221
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, 10));
222222
assertKeyNotEquals(
223-
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, Integer.MAX_VALUE, false),
223+
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, Integer.MAX_VALUE, true),
224224
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0));
225225
assertKeyNotEquals(
226-
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, 20, false),
226+
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, 20, true),
227227
new QueryResultKey(base, buildFiltersFromNumbers(nums), null, 0, 20));
228228
}
229229

solr/core/src/test/org/apache/solr/search/stats/TestBaseStatsCache.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,9 @@ protected void checkResponse(QueryResponse controlRsp, QueryResponse shardRsp) {
6464
assertEquals(controlDoc.getFieldValue("score"), shardDoc.getFieldValue("score"));
6565
}
6666
}
67+
68+
@Override
69+
protected void checkDistribStatsException() {
70+
// doing nothing on distrib stats
71+
}
6772
}

solr/core/src/test/org/apache/solr/search/stats/TestDefaultStatsCache.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.solr.client.solrj.SolrClient;
2121
import org.apache.solr.client.solrj.response.QueryResponse;
2222
import org.apache.solr.common.SolrDocumentList;
23+
import org.apache.solr.common.SolrException;
2324
import org.apache.solr.common.params.ModifiableSolrParams;
2425
import org.junit.Test;
2526

@@ -79,6 +80,8 @@ public void test() throws Exception {
7980
dfQuery("q", "{!cache=false}id:" + aDocId, "debugQuery", "true", "fl", "*,score");
8081
}
8182
dfQuery("q", "a_t:one a_t:four", "debugQuery", "true", "fl", "*,score");
83+
84+
checkDistribStatsException();
8285
}
8386

8487
// in this case, as the number of shards increases, per-shard scores begin to
@@ -111,4 +114,16 @@ protected void dfQuery(Object... q) throws Exception {
111114
QueryResponse rsp = client.query(params);
112115
checkResponse(controlRsp, rsp);
113116
}
117+
118+
protected void checkDistribStatsException() throws Exception {
119+
final ModifiableSolrParams params = new ModifiableSolrParams();
120+
params.set("shards", shards);
121+
params.set("distrib.statsCache", "true");
122+
int which = r.nextInt(clients.size());
123+
SolrClient client = clients.get(which);
124+
SolrException e = assertThrows(SolrException.class, () -> client.query(params));
125+
assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, e.code());
126+
assertTrue(e.getMessage().contains("distrib.statsCache"));
127+
assertTrue(e.getMessage().contains(LocalStatsCache.class.getSimpleName()));
128+
}
114129
}

0 commit comments

Comments
 (0)