sigram commented on code in PR #2237:
URL: https://github.com/apache/solr/pull/2237#discussion_r1474181542


##########
solr/core/src/java/org/apache/solr/search/SolrQueryTimeLimit.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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 java.lang.System.nanoTime;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.lucene.index.QueryTimeout;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.request.SolrQueryRequest;
+
+public class SolrQueryTimeLimit implements QueryTimeout {
+
+  private final long timeoutAt;
+
+  /**
+   * Create an object to represent a time limit for the current request.
+   *
+   * @param req A sollr request that has a value for {@code timeAllowed}

Review Comment:
   typo `sollr`



##########
solr/core/src/java/org/apache/solr/search/QueryLimits.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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 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<>();

Review Comment:
   We could specify the size, we know how many entries there can be at most.



##########
solr/core/src/java/org/apache/solr/search/SolrQueryTimeLimit.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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 java.lang.System.nanoTime;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.lucene.index.QueryTimeout;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.request.SolrQueryRequest;
+
+public class SolrQueryTimeLimit implements QueryTimeout {
+
+  private final long timeoutAt;
+
+  /**
+   * Create an object to represent a time limit for the current request.
+   *
+   * @param req A sollr request that has a value for {@code timeAllowed}
+   * @throws IllegalArgumentException if the request does not contain 
timeAllowed parameter. This
+   *     should be validated with {@link #hasTimeLimit(SolrQueryRequest)} 
prior to constructing this
+   *     object
+   */
+  public SolrQueryTimeLimit(SolrQueryRequest req) {
+    // reduce by time already spent
+    long reqTimeAllowed = req.getParams().getLong(CommonParams.TIME_ALLOWED, 
-1L);
+
+    if (reqTimeAllowed == -1L) {
+      throw new IllegalArgumentException(
+          "Check for limit with hasTimeLimit(req) before creating a 
SolrQuerTimeLimit");

Review Comment:
   typo



##########
solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java:
##########
@@ -725,7 +730,7 @@ protected void search(List<LeafReaderContext> leaves, 
Weight weight, Collector c
       // So we need to make a new IndexSearcher instead of using "this".
       new IndexSearcher(reader) { // cheap, actually!
         void searchWithTimeout() throws IOException {
-          setTimeout(queryTimeout.makeLocalImpl());
+          setTimeout(requestInfo.getLimits());
           super.search(leaves, weight, collector); // FYI protected access
           if (timedOut()) {
             throw new TimeAllowedExceededFromScorerException("timeAllowed 
exceeded");

Review Comment:
   Hmm, perhaps we should change this message to "allowed limit exceeded". 
Which suggests that we should be able to tell user what limit has been exceeded 
if multiple limits have been specified... We could add a utility method to 
`QueryLimits` to format a string telling what kind of limit has been tripped, 
based on the current values of `shouldExit` of each impl.



##########
solr/core/src/java/org/apache/solr/search/QueryLimits.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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 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,

Review Comment:
   missing comma.



##########
solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java:
##########
@@ -210,6 +212,10 @@ public void addCloseHook(Closeable hook) {
     }
   }
 
+  public QueryLimits getLimits() {
+    return (QueryLimits) req.getContext().computeIfAbsent(LIMITS_KEY, (k) -> 
new QueryLimits(req));

Review Comment:
   This may throw NPE if used in a wrong place - HttpSolrCall.sendRemoteQuery() 
uses the other constructor for SolrRequestInfo, where req is null.



-- 
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]

Reply via email to