Apache Solr open-source search software
SOLR-5727: LBHttpSolrServer should only retry on Connection exceptions when sending updates. Affects CloudSolrServer.
Mark Robert Millerc95e1f4969e0
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex e654b46ada9..26820d88c47 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -337,6 +337,9 @@ Bug Fixes* SOLR-5718: Make LBHttpSolrServer zombie checks non-distrib and non-scoring.(Christine Poerschke via Mark Miller)+* SOLR-5727: LBHttpSolrServer should only retry on Connection exceptions when+ sending updates. Affects CloudSolrServer. (Mark Miller)+Optimizations----------------------diff --git a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.javaindex 23bc9cb6379..3f46dece6ec 100644--- a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java@@ -204,7 +204,7 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase// we expect full throttle fails, but cloud client should not easily failfor (StopableThread indexThread : threads) {if (indexThread instanceof StopableIndexingThread && !(indexThread instanceof FullThrottleStopableIndexingThread)) {- assertFalse("There were too many update fails - we expect it can happen, but shouldn't easily", ((StopableIndexingThread) indexThread).getFails() > 1);+ assertFalse("There were too many update fails - we expect it can happen, but shouldn't easily", ((StopableIndexingThread) indexThread).getFails() > 10);}}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.javaindex b0055339347..3687c97b19e 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java@@ -18,6 +18,7 @@ package org.apache.solr.client.solrj.impl;import org.apache.http.client.HttpClient;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.ModifiableSolrParams;@@ -27,6 +28,7 @@ import org.apache.solr.common.SolrException;import java.io.IOException;import java.lang.ref.WeakReference;+import java.net.ConnectException;import java.net.MalformedURLException;import java.net.SocketException;import java.net.SocketTimeoutException;@@ -74,7 +76,14 @@ import java.util.*;* @since solr 1.4*/public class LBHttpSolrServer extends SolrServer {+ private static Set<Integer> RETRY_CODES = new HashSet<Integer>(4);+ static {+ RETRY_CODES.add(404);+ RETRY_CODES.add(403);+ RETRY_CODES.add(503);+ RETRY_CODES.add(500);+ }// keys to the maps are currently of the form "http://localhost:8983/solr"// which should be equivalent to CommonsHttpSolrServer.getBaseURL()@@ -273,7 +282,7 @@ public class LBHttpSolrServer extends SolrServer {public Rsp request(Req req) throws SolrServerException, IOException {Rsp rsp = new Rsp();Exception ex = null;-+ boolean isUpdate = req.request instanceof IsUpdateRequest;List<ServerWrapper> skipped = new ArrayList<ServerWrapper>(req.getNumDeadServersToTry());for (String serverStr : req.getServers()) {@@ -293,25 +302,31 @@ public class LBHttpSolrServer extends SolrServer {rsp.rsp = server.request(req.getRequest());return rsp; // SUCCESS} catch (SolrException e) {- // we retry on 404 or 403 or 503 - you can see this on solr shutdown- if (e.code() == 404 || e.code() == 403 || e.code() == 503 || e.code() == 500) {+ // we retry on 404 or 403 or 503 or 500+ // unless it's an update - then we only retry on connect exceptions+ if (!isUpdate && RETRY_CODES.contains(e.code())) {ex = addZombie(server, e);} else {// Server is alive but the request was likely malformed or invalidthrow e;}-- // TODO: consider using below above - currently does cause a problem with distrib updates:- // seems to match up against a failed forward to leader exception as well...- // || e.getMessage().contains("java.net.SocketException")- // || e.getMessage().contains("java.net.ConnectException")} catch (SocketException e) {- ex = addZombie(server, e);+ if (!isUpdate || e instanceof ConnectException) {+ ex = addZombie(server, e);+ } else {+ throw e;+ }} catch (SocketTimeoutException e) {- ex = addZombie(server, e);+ if (!isUpdate) {+ ex = addZombie(server, e);+ } else {+ throw e;+ }} catch (SolrServerException e) {Throwable rootCause = e.getRootCause();- if (rootCause instanceof IOException) {+ if (!isUpdate && rootCause instanceof IOException) {+ ex = addZombie(server, e);+ } else if (isUpdate && rootCause instanceof ConnectException) {ex = addZombie(server, e);} else {throw e;@@ -328,8 +343,9 @@ public class LBHttpSolrServer extends SolrServer {zombieServers.remove(wrapper.getKey());return rsp; // SUCCESS} catch (SolrException e) {- // we retry on 404 or 403 or 503 - you can see this on solr shutdown- if (e.code() == 404 || e.code() == 403 || e.code() == 503 || e.code() == 500) {+ // we retry on 404 or 403 or 503 or 500+ // unless it's an update - then we only retry on connect exceptions+ if (!isUpdate && RETRY_CODES.contains(e.code())) {ex = e;// already a zombie, no need to re-add} else {@@ -339,14 +355,23 @@ public class LBHttpSolrServer extends SolrServer {}} catch (SocketException e) {- ex = e;+ if (!isUpdate || e instanceof ConnectException) {+ ex = e;+ } else {+ throw e;+ }} catch (SocketTimeoutException e) {- ex = e;+ if (!isUpdate) {+ ex = e;+ } else {+ throw e;+ }} catch (SolrServerException e) {Throwable rootCause = e.getRootCause();- if (rootCause instanceof IOException) {+ if (!isUpdate && rootCause instanceof IOException) {+ ex = e;+ } else if (isUpdate && rootCause instanceof ConnectException) {ex = e;- // already a zombie, no need to re-add} else {throw e;}