lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject svn commit: r1651236 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
Date Mon, 12 Jan 2015 23:52:11 GMT
Author: anshum
Date: Mon Jan 12 23:52:10 2015
New Revision: 1651236

URL: http://svn.apache.org/r1651236
Log:
SOLR-6496: LBHttpSolrClient stops retrying after the timeAllowed threshold is met

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1651236&r1=1651235&r2=1651236&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Jan 12 23:52:10 2015
@@ -681,6 +681,9 @@ Other Changes
   or collection depending on whether Solr is running in standalone or cloud mode
   (Timothy Potter)
 
+* SOLR-6496: LBHttpSolrClient stops server retries after the timeAllowed threshold is met.
+  (Steve Davids, Anshum Gupta)
+
 ==================  4.10.3 ==================
 
 Bug Fixes

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java?rev=1651236&r1=1651235&r2=1651236&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java
Mon Jan 12 23:52:10 2015
@@ -77,17 +77,18 @@ public class CloudExitableDirectoryReade
     time than this. Keeping it at 5 because the delaying search component delays all requests

     by at 1 second.
      */
-    long fiveSeconds = 5000L;
+    int fiveSeconds = 5000;
     
-    Long timeAllowed = TestUtil.nextLong(random(), fiveSeconds, Long.MAX_VALUE);
+    Integer timeAllowed = TestUtil.nextInt(random(), fiveSeconds, Integer.MAX_VALUE);
     assertSuccess(params("q", "name:a*", "timeAllowed",timeAllowed.toString()));
 
     assertPartialResults(params("q", "name:a*", "timeAllowed", "1"));
 
-    timeAllowed = TestUtil.nextLong(random(), fiveSeconds, Long.MAX_VALUE);
+    timeAllowed = TestUtil.nextInt(random(), fiveSeconds, Integer.MAX_VALUE);
     assertSuccess(params("q", "name:b*", "timeAllowed",timeAllowed.toString()));
 
-    timeAllowed = TestUtil.nextLong(random(), Long.MIN_VALUE, -1L);  // negative timeAllowed
should disable timeouts
+    // negative timeAllowed should disable timeouts
+    timeAllowed = TestUtil.nextInt(random(), Integer.MIN_VALUE, -1); 
     assertSuccess(params("q", "name:b*", "timeAllowed",timeAllowed.toString()));
 
     assertSuccess(params("q","name:b*")); // no time limitation

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java?rev=1651236&r1=1651235&r2=1651236&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
Mon Jan 12 23:52:10 2015
@@ -21,7 +21,9 @@ import org.apache.solr.client.solrj.*;
 import org.apache.solr.client.solrj.request.IsUpdateRequest;
 import org.apache.solr.client.solrj.request.RequestWriter;
 import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SolrjNamedThreadFactory;
 import org.apache.solr.common.SolrException;
@@ -288,7 +290,13 @@ public class LBHttpSolrClient extends So
     boolean isUpdate = req.request instanceof IsUpdateRequest;
     List<ServerWrapper> skipped = null;
 
+    long timeAllowedNano = getTimeAllowedInNanos(req.getRequest());
+    long timeOutTime = System.nanoTime() + timeAllowedNano;
     for (String serverStr : req.getServers()) {
+      if(isTimeExceeded(timeAllowedNano, timeOutTime)) {
+        break;
+      }
+      
       serverStr = normalize(serverStr);
       // if the server is currently a zombie, just skip to the next one
       ServerWrapper wrapper = zombieServers.get(serverStr);
@@ -318,6 +326,10 @@ public class LBHttpSolrClient extends So
     // try the servers we previously skipped
     if (skipped != null) {
       for (ServerWrapper wrapper : skipped) {
+        if(isTimeExceeded(timeAllowedNano, timeOutTime)) {
+          break;
+        }
+
         ex = doRequest(wrapper.client, req, rsp, isUpdate, true, wrapper.getKey());
         if (ex == null) {
           return rsp; // SUCCESS
@@ -482,7 +494,13 @@ public class LBHttpSolrClient extends So
     int maxTries = serverList.length;
     Map<String,ServerWrapper> justFailed = null;
 
+    long timeAllowedNano = getTimeAllowedInNanos(request);
+    long timeOutTime = System.nanoTime() + timeAllowedNano;
     for (int attempts=0; attempts<maxTries; attempts++) {
+      if(isTimeExceeded(timeAllowedNano, timeOutTime)) {
+        break;
+      }
+      
       int count = counter.incrementAndGet() & Integer.MAX_VALUE;
       ServerWrapper wrapper = serverList[count % serverList.length];
       wrapper.lastUsed = System.currentTimeMillis();
@@ -506,9 +524,12 @@ public class LBHttpSolrClient extends So
       }
     }
 
-
     // try other standard servers that we didn't try just now
     for (ServerWrapper wrapper : zombieServers.values()) {
+      if(isTimeExceeded(timeAllowedNano, timeOutTime)) {
+        break;
+      }
+      
       if (wrapper.standard==false || justFailed!=null && justFailed.containsKey(wrapper.getKey()))
continue;
       try {
         NamedList<Object> rsp = wrapper.client.request(request);
@@ -540,6 +561,19 @@ public class LBHttpSolrClient extends So
   }
   
   /**
+   * @return time allowed in nanos, returns -1 if no time_allowed is specified.
+   */
+  private long getTimeAllowedInNanos(final SolrRequest req) {
+    SolrParams reqParams = req.getParams();
+    return reqParams == null ? -1 : 
+      TimeUnit.NANOSECONDS.convert(reqParams.getInt(CommonParams.TIME_ALLOWED, -1), TimeUnit.MILLISECONDS);
+  }
+  
+  private boolean isTimeExceeded(long timeAllowedNano, long timeOutTime) {
+    return timeAllowedNano > 0 && System.nanoTime() > timeOutTime;
+  }
+  
+  /**
    * Takes up one dead server and check for aliveness. The check is done in a roundrobin.
Each server is checked for
    * aliveness once in 'x' millis where x is decided by the setAliveCheckinterval() or it
is defaulted to 1 minute
    *



Mime
View raw message