Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAI-4737: System prop solr.MaxBasicQueriesOverride for surround query #172

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@
public class SurroundQParserPlugin extends QParserPlugin {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String NAME = "surround";
private static final String MAX_BASIC_QUERIES_SYSTEM_PROP = "solr.absoluteMaxBasicQueries";
private static final int ABSOLUTE_MAX_BASIC_QUERIES = readAbsolutionMaxBasicQueries();

private static int readAbsolutionMaxBasicQueries() {
String maxBasicQueriesSystemProp = System.getProperty(MAX_BASIC_QUERIES_SYSTEM_PROP);
if (maxBasicQueriesSystemProp != null) {
try {
int absoluteMaxBasicQueries = Integer.parseInt(maxBasicQueriesSystemProp);
if (absoluteMaxBasicQueries > 0) {
log.info(
"maxBasicQueries with system property {} with value {}",
MAX_BASIC_QUERIES_SYSTEM_PROP,
maxBasicQueriesSystemProp);
return absoluteMaxBasicQueries;
} else {
log.info(
"Ignoring system property {} value {} since it is non-positive",
MAX_BASIC_QUERIES_SYSTEM_PROP,
maxBasicQueriesSystemProp);
}
} catch (NumberFormatException e) {
hiteshk25 marked this conversation as resolved.
Show resolved Hide resolved
log.warn(
"Invalid system property {} value {}",
MAX_BASIC_QUERIES_SYSTEM_PROP,
maxBasicQueriesSystemProp);
}
}
return -1; // -1 indicates no absolute max basic queries
}

@Override
public QParser createParser(
Expand Down Expand Up @@ -77,6 +106,16 @@ public Query parse() throws SyntaxError {
this.maxBasicQueries = DEFMAXBASICQUERIES;
}
}

if (ABSOLUTE_MAX_BASIC_QUERIES > 0 && this.maxBasicQueries > ABSOLUTE_MAX_BASIC_QUERIES) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just setting value, if that is positive. Probably we don't need to log here.

Copy link
Collaborator Author

@patsonluk patsonluk Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This current logic basically only considers "solr.absoluteMaxBasicQueries" if it was provided and positive. Pretty similar to what your are suggesting?

Are you suggesting "solr.absoluteMaxBasicQueries" will just override maxBasicQueries in all cases? Currently "solr.absoluteMaxBasicQueries" acts as a absolute safeguard, maxBasicQueries is still effective as far as it stays below "solr.absoluteMaxBasicQueries".

The log was mostly to avoid the case that user is confused which a higher maxBasicQueries seems to have no impact (because of the solr.absoluteMaxBasicQueries). I have some concern that this could be noisy, though once per surround query is probably not too bad imo :) ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log would be per query, per shard ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was per query on core I believe.

Since now it's a temporary override (the dev should be well aware of it, unlike the proposal before which could be long living), I have removed the logging :)

log.info(
"Overriding maxBasicQueries from query {} with system property {} value {}",
this.maxBasicQueries,
MAX_BASIC_QUERIES_SYSTEM_PROP,
ABSOLUTE_MAX_BASIC_QUERIES);
this.maxBasicQueries = ABSOLUTE_MAX_BASIC_QUERIES;
}

// ugh .. colliding ParseExceptions
try {
sq = org.apache.lucene.queryparser.surround.parser.QueryParser.parse(qstr);
Expand Down
Loading