Skip to content

Apache Lucene open-source search software

SOLR-7243: Return more informative error from CloudSolrServer when available.

Shawn Heiseyb75b54611024
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f05e3407891..d9ffa5a06c4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -348,6 +348,11 @@ Other Changes
* SOLR-7500: Remove pathPrefix from SolrDispatchFilter as Solr no longer runs as a part
of a bigger webapp. (Anshum Gupta)
+* SOLR-7243: CloudSolrClient was always returning SERVER_ERROR for exceptions,
+ even when a more relevant ErrorCode was available, via SolrException. Now
+ the actual ErrorCode is used when available.
+ (Hrishikesh Gadre via Shawn Heisey)
+
================== 5.1.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release
diff --git a/solr/core/src/test/org/apache/solr/schema/TestCloudSchemaless.java b/solr/core/src/test/org/apache/solr/schema/TestCloudSchemaless.java
index 1df5640cadc..abfff36b023 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestCloudSchemaless.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestCloudSchemaless.java
@@ -18,6 +18,7 @@ package org.apache.solr.schema;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
import org.apache.solr.common.SolrException;
@@ -187,6 +188,15 @@ public class TestCloudSchemaless extends AbstractFullDistribZkTestBase {
} catch (SolrException se) {
assertEquals(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode(se.code()));
}
+
+ try {
+ CloudSolrClient cloudSolrClient = getCommonCloudSolrClient();
+ cloudSolrClient.add(docs);
+ cloudSolrClient.commit();
+ fail("Expected Bad Request Exception");
+ } catch (SolrException ex) {
+ assertEquals(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode((ex).code()));
+ }
}
}
}
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 b0e8e10d646..f03640785ae 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
@@ -619,7 +619,13 @@ public class CloudSolrClient extends SolrClient {
}
if (exceptions.size() > 0) {
- throw new RouteException(ErrorCode.SERVER_ERROR, exceptions, routes);
+ Throwable firstException = exceptions.getVal(0);
+ if(firstException instanceof SolrException) {
+ SolrException e = (SolrException) firstException;
+ throw new RouteException(ErrorCode.getErrorCode(e.code()), exceptions, routes);
+ } else {
+ throw new RouteException(ErrorCode.SERVER_ERROR, exceptions, routes);
+ }
}
} else {
for (Map.Entry<String, LBHttpSolrClient.Req> entry : routes.entrySet()) {
@@ -629,7 +635,11 @@ public class CloudSolrClient extends SolrClient {
NamedList<Object> rsp = lbClient.request(lbRequest).getResponse();
shardResponses.add(url, rsp);
} catch (Exception e) {
- throw new SolrServerException(e);
+ if(e instanceof SolrException) {
+ throw (SolrException) e;
+ } else {
+ throw new SolrServerException(e);
+ }
}
}
}
@@ -928,7 +938,9 @@ public class CloudSolrClient extends SolrClient {
log.warn("Re-trying request to collection(s) "+collection+" after stale state error from server.");
resp = requestWithRetryOnStaleState(request, retryCount+1, collection);
} else {
- if (exc instanceof SolrServerException) {
+ if(exc instanceof SolrException) {
+ throw exc;
+ } if (exc instanceof SolrServerException) {
throw (SolrServerException)exc;
} else if (exc instanceof IOException) {
throw (IOException)exc;