Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17897: CloudSolrClient: treat UnknownHostException as retry-able (#3791)

David Smileyd52761aa9793
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 89b32709d77..99b9bd84db4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -367,6 +367,9 @@ Improvements
* SOLR-17921: SolrJ CloudSolrClient configured with a Solr URL (not ZK) now refreshes liveNodes in the background.
This will reduce spikes in request latency when the cached liveNodes have expired. (Houston Putman, David Smiley)
+* SOLR-17897: CloudSolrClient now recognizes UnknownHostException as a case to refetch the cluster
+ state and retry. (David Smiley)
+
Optimizations
---------------------
(No changes)
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
index 4b3ac046ac2..0bb4d3eb67a 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
@@ -182,11 +182,6 @@ public class CloudHttp2SolrClient extends CloudSolrClient {
return myClient;
}
- @Override
- protected boolean wasCommError(Throwable rootCause) {
- return false;
- }
-
/** Constructs {@link CloudHttp2SolrClient} instances from provided configuration. */
public static class Builder {
protected Collection<String> zkHosts = new ArrayList<>();
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudLegacySolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudLegacySolrClient.java
index e8aecc8a88b..2c660c63228 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudLegacySolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudLegacySolrClient.java
@@ -140,7 +140,8 @@ public class CloudLegacySolrClient extends CloudSolrClient {
@Override
protected boolean wasCommError(Throwable rootCause) {
- return rootCause instanceof ConnectTimeoutException
+ return super.wasCommError(rootCause)
+ || rootCause instanceof ConnectTimeoutException
|| rootCause instanceof NoHttpResponseException;
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index ebe1fddf0ee..ac12e5b5722 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -21,8 +21,8 @@ import static org.apache.solr.common.params.CommonParams.ID;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
-import java.net.ConnectException;
import java.net.SocketException;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -221,7 +221,10 @@ public abstract class CloudSolrClient extends SolrClient {
return getClusterStateProvider().getClusterState();
}
- protected abstract boolean wasCommError(Throwable t);
+ /** Is this a communication error? We will retry if so. */
+ protected boolean wasCommError(Throwable t) {
+ return t instanceof SocketException || t instanceof UnknownHostException;
+ }
@Override
public void close() throws IOException {
@@ -813,10 +816,7 @@ public abstract class CloudSolrClient extends SolrClient {
? ((SolrException) rootCause).code()
: SolrException.ErrorCode.UNKNOWN.code;
- boolean wasCommError =
- (rootCause instanceof ConnectException
- || rootCause instanceof SocketException
- || wasCommError(rootCause));
+ final boolean wasCommError = wasCommError(rootCause);
if (wasCommError
|| (exc instanceof RouteException