You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Steve Rowe (JIRA)" <ji...@apache.org> on 2015/04/20 16:31:59 UTC

[jira] [Resolved] (SOLR-7419) Initial value of thread local in SolrQueryTimeoutImpl overflows a long

     [ https://issues.apache.org/jira/browse/SOLR-7419?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Steve Rowe resolved SOLR-7419.
------------------------------
    Resolution: Not A Problem
      Assignee: Steve Rowe

Here's the comment I added to explain the intentional overflow:

{code:java}
Index: solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java
===================================================================
--- solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java	(revision 1674843)
+++ solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java	(working copy)
@@ -33,6 +33,23 @@
    * 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;
{code}

> Initial value of thread local in SolrQueryTimeoutImpl overflows a long
> ----------------------------------------------------------------------
>
>                 Key: SOLR-7419
>                 URL: https://issues.apache.org/jira/browse/SOLR-7419
>             Project: Solr
>          Issue Type: Bug
>          Components: search
>    Affects Versions: 4.10.4, 5.1
>            Reporter: Shalin Shekhar Mangar
>            Assignee: Steve Rowe
>            Priority: Trivial
>             Fix For: Trunk, 5.2
>
>
> Same as the title.
> {code}
>  /**
>    * The ThreadLocal variable to store the time beyond which, the processing should exit.
>    */
>   public static ThreadLocal<Long> timeoutAt = new ThreadLocal<Long>() {
>     @Override
>     protected Long initialValue() {
>       return nanoTime() + Long.MAX_VALUE;
>     }
>   };
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org