Apache Solr open-source search software
SOLR-6175: DebugComponent throws NPE on shard exceptions when using shards.tolerant
Shalin Shekhar Mangar2fe64e65ac09
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 5ce100456ee..2568d616f2f 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -184,6 +184,9 @@ Bug Fixes* SOLR-5426: Fixed a bug in ReverseWildCardFilter that could causeInvalidTokenOffsetsException when highlighting. (Uwe Schindler, Arun Kumar, via hossman)+* SOLR-6175: DebugComponent throws NPE on shard exceptions when using shards.tolerant.+ (Tomás Fernández Löbbe via shalin)+Other Changes---------------------diff --git a/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java b/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.javaindex aa6ce962c50..6f5f44c1fea 100644--- a/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java+++ b/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java@@ -206,6 +206,11 @@ public class DebugComponent extends SearchComponentfor (ShardRequest sreq : rb.finished) {for (ShardResponse srsp : sreq.responses) {+ if (srsp.getException() != null) {+ // can't expect the debug content if there was an exception for this request+ // this should only happen when using shards.tolerant=true+ continue;+ }NamedList sdebug = (NamedList)srsp.getSolrResponse().getResponse().get("debug");info = (NamedList)merge(sdebug, info, EXCLUDE_SET);if ((sreq.purpose & ShardRequest.PURPOSE_GET_DEBUG) != 0) {@@ -257,6 +262,10 @@ public class DebugComponent extends SearchComponentprivate NamedList<String> getTrackResponse(ShardResponse shardResponse) {NamedList<String> namedList = new NamedList<>();+ if (shardResponse.getException() != null) {+ namedList.add("Exception", shardResponse.getException().getMessage());+ return namedList;+ }NamedList<Object> responseNL = shardResponse.getSolrResponse().getResponse();@SuppressWarnings("unchecked")NamedList<Object> responseHeader = (NamedList<Object>)responseNL.get("responseHeader");diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.javaindex 67fd8594f59..833eb6d4f07 100644--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java@@ -7,6 +7,7 @@ import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;+import java.util.Map.Entry;import java.util.Set;import org.apache.commons.io.FileUtils;@@ -18,7 +19,9 @@ import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.HttpSolrServer;import org.apache.solr.client.solrj.request.CoreAdminRequest;import org.apache.solr.client.solrj.response.QueryResponse;+import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrInputDocument;+import org.apache.solr.common.params.ShardParams;import org.apache.solr.common.util.NamedList;import org.junit.AfterClass;import org.junit.BeforeClass;@@ -96,6 +99,7 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {collection2 = null;jetty.stop();jetty=null;+ resetExceptionIgnores();}@Test@@ -367,6 +371,35 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {assertSameKeys((NamedList<?>)nonDistribResponse.getDebugMap().get("timing"), (NamedList<?>)distribResponse.getDebugMap().get("timing"));}+ public void testTolerantSearch() throws SolrServerException {+ String badShard = "[ff01::0083]:3334";+ SolrQuery query = new SolrQuery();+ query.setQuery("*:*");+ query.set("debug", "true");+ query.set("distrib", "true");+ query.setFields("id", "text");+ query.set("shards", shard1 + "," + shard2 + "," + badShard);+ try {+ ignoreException("Server refused connection");+ // verify that the request would fail if shards.tolerant=false+ collection1.query(query);+ fail("Expecting exception");+ } catch (SolrException e) {+ //expected+ }+ query.set(ShardParams.SHARDS_TOLERANT, "true");+ QueryResponse response = collection1.query(query);+ assertTrue((Boolean)response.getResponseHeader().get("partialResults"));+ @SuppressWarnings("unchecked")+ NamedList<String> badShardTrack = (NamedList<String>) ((NamedList<NamedList<String>>)+ ((NamedList<NamedList<NamedList<String>>>)response.getDebugMap().get("track")).get("EXECUTE_QUERY")).get(badShard);+ assertEquals("Unexpected response size for shard", 1, badShardTrack.size());+ Entry<String, String> exception = badShardTrack.iterator().next();+ assertEquals("Expected key 'Exception' not found", "Exception", exception.getKey());+ assertTrue("Unexpected exception message", exception.getValue().contains("Server refused connection"));+ unIgnoreException("Server refused connection");+ }+/*** Compares the same section on the two query responses*/