Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 244AB1070F for ; Mon, 12 Jan 2015 23:52:10 +0000 (UTC) Received: (qmail 480 invoked by uid 500); 12 Jan 2015 23:52:11 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 469 invoked by uid 99); 12 Jan 2015 23:52:11 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Jan 2015 23:52:11 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 86B30AC0163; Mon, 12 Jan 2015 23:52:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@lucene.apache.org From: anshum@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150112235211.86B30AC0163@hades.apache.org> 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 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 justFailed = null; + long timeAllowedNano = getTimeAllowedInNanos(request); + long timeOutTime = System.nanoTime() + timeAllowedNano; for (int attempts=0; attempts 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 *