You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2015/08/06 23:29:14 UTC

svn commit: r1694575 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/CHANGES.txt solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java

Author: tflobbe
Date: Thu Aug  6 21:29:14 2015
New Revision: 1694575

URL: http://svn.apache.org/r1694575
Log:
SOLR-7875: Speedup SolrQueryTimeoutImpl

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1694575&r1=1694574&r2=1694575&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Thu Aug  6 21:29:14 2015
@@ -261,6 +261,9 @@ Optimizations
 
 * SOLR-7840: ZkStateReader.updateClusterState fetches watched collections twice from ZK. (shalin)
 
+* SOLR-7875: Speedup SolrQueryTimeoutImpl. Avoid setting a timeout time when timeAllowed
+  parameter is not set. (Tomás Fernández Löbbe)
+
 Other Changes
 ----------------------
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java?rev=1694575&r1=1694574&r2=1694575&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java Thu Aug  6 21:29:14 2015
@@ -17,11 +17,11 @@ package org.apache.solr.search;
  * limitations under the License.
  */
 
-import org.apache.lucene.index.QueryTimeout;
+import static java.lang.System.nanoTime;
 
 import java.util.concurrent.TimeUnit;
 
-import static java.lang.System.nanoTime;
+import org.apache.lucene.index.QueryTimeout;
 
 /**
  * Implementation of {@link QueryTimeout} that is used by Solr. 
@@ -32,29 +32,7 @@ public class SolrQueryTimeoutImpl implem
   /**
    * The ThreadLocal variable to store the time beyond which, the processing should exit.
    */
-  public static ThreadLocal<Long> timeoutAt = new ThreadLocal<Long>() {
-    /**
-     * {@inheritDoc}
-     * <p>
-     * By default, timeoutAt is set as far in the future as possible, 
-     * so that it effectively never happens.
-     * <p>
-     * Since nanoTime() values can be anything from Long.MIN_VALUE to
-     * Long.MAX_VALUE, adding Long.MAX_VALUE can cause overflow.  That's
-     * expected and works fine, since in that case the subtraction of a
-     * future nanoTime() value from timeoutAt (in 
-     * {@link SolrQueryTimeoutImpl#shouldExit}) will result in underflow,
-     * and checking the sign of the result of that subtraction (via
-     * comparison to zero) will correctly indicate whether the future
-     * nanoTime() value has exceeded the timeoutAt value.
-     * <p> 
-     * See {@link System#nanoTime}
-     */
-    @Override
-    protected Long initialValue() {
-      return nanoTime() + Long.MAX_VALUE;
-    }
-  };
+  public static ThreadLocal<Long> timeoutAt = new ThreadLocal<Long>();
 
   private SolrQueryTimeoutImpl() { }
   private static SolrQueryTimeoutImpl instance = new SolrQueryTimeoutImpl();
@@ -76,7 +54,12 @@ public class SolrQueryTimeoutImpl implem
    */
   @Override
   public boolean shouldExit() {
-    return get() - nanoTime() < 0L;
+    Long timeoutAt = get();
+    if (timeoutAt == null) {
+      // timeout unset
+      return false;
+    }
+    return timeoutAt - nanoTime() < 0L;
   }
 
   /**