dsmiley commented on code in PR #2237: URL: https://github.com/apache/solr/pull/2237#discussion_r1484949203
########## solr/core/src/java/org/apache/solr/search/QueryLimits.java: ########## @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.search; + +import static org.apache.solr.search.SolrQueryTimeLimit.hasTimeLimit; + +import java.util.ArrayList; +import java.util.List; +import org.apache.lucene.index.QueryTimeout; +import org.apache.solr.request.SolrQueryRequest; + +/** + * Represents the limitations on the query. These limits might be wall clock time, cpu time, memory, + * or other resource limits. Exceeding any specified limit will cause {@link #shouldExit()} to + * return true the next time it is checked (it may be checked in either Lucene code or Solr code) + */ +public class QueryLimits implements QueryTimeout { + private final List<QueryTimeout> limits = + new ArrayList<>(3); // timeAllowed, cpu, and memory anticipated + + public static QueryLimits NONE = new QueryLimits(); + + private QueryLimits() {} + + /** + * Implementors of a Query Limit should add an if block here to activate it, and typically this if + * statement will hinge on hasXXXLimit() static method attached to the implementation class. + * + * @param req the current SolrQueryRequest. + */ + public QueryLimits(SolrQueryRequest req) { + if (hasTimeLimit(req)) { + limits.add(new SolrQueryTimeLimit(req)); + } + } + + @Override + public boolean shouldExit() { + return limits.stream().anyMatch(QueryTimeout::shouldExit); Review Comment: or support a chain implementation similar to URPs -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
