Apache Lucene open-source search software
SOLR-5204: StatsComponent and SpellCheckComponent do not support the shards.tolerant=true parameter
Shalin Shekhar Mangarf56bf5b9d06c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex d215aebecad..29b43f45b8a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -169,6 +169,9 @@ Bug Fixes* SOLR-5515: NPE when getting stats on date field with empty result onSolrCloud. (Alexander Sagen, shalin)+* SOLR-5204: StatsComponent and SpellCheckComponent do not support the+ shards.tolerant=true parameter. (Anca Kopetz, shalin)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.javaindex 35a6c66592f..a2c609e3a9f 100644--- a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java+++ b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java@@ -320,7 +320,16 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwarif (maxResultsForSuggest==null || !isCorrectlySpelled) {for (ShardRequest sreq : rb.finished) {for (ShardResponse srsp : sreq.responses) {- NamedList nl = (NamedList) srsp.getSolrResponse().getResponse().get("spellcheck");+ NamedList nl = null;+ try {+ nl = (NamedList) srsp.getSolrResponse().getResponse().get("spellcheck");+ } catch (Exception e) {+ if (rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false)) {+ continue; // looks like a shard did not return anything+ }+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,+ "Unable to read spelling info for shard: " + srsp.getShard(), e);+ }LOG.info(srsp.getShard() + " " + nl);if (nl != null) {mergeData.totalNumberShardResponses++;diff --git a/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java b/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.javaindex 3af0f62e5b8..34601804370 100644--- a/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java+++ b/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java@@ -102,7 +102,16 @@ public class StatsComponent extends SearchComponent {StatsInfo si = rb._statsInfo;for (ShardResponse srsp : sreq.responses) {- NamedList stats = (NamedList) srsp.getSolrResponse().getResponse().get("stats");+ NamedList stats = null;+ try {+ stats = (NamedList) srsp.getSolrResponse().getResponse().get("stats");+ } catch (Exception e) {+ if (rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false)) {+ continue; // looks like a shard did not return anything+ }+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,+ "Unable to read stats info for shard: " + srsp.getShard(), e);+ }NamedList stats_fields = (NamedList) stats.get("stats_fields");if (stats_fields != null) {diff --git a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java b/solr/core/src/test/org/apache/solr/TestDistributedSearch.javaindex 2c6f0232f46..d0887f4f7c8 100644--- a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java+++ b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java@@ -105,6 +105,8 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {t1,"no eggs on wall, lesson learned",oddField, "odd man out");+ indexr(id, "1001", "lowerfilt", "toyota"); // for spellcheck+indexr(id, 14, "SubjectTerms_mfacet", new String[] {"mathematical models", "mathematical analysis"});indexr(id, 15, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});indexr(id, 16, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});@@ -227,6 +229,9 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {query("q","*:*", "fl", "id", "fl",nint, "fl",tint,"sort",i1 + " desc");query("q","*:*", "fl",nint, "fl", "id", "fl",tint,"sort",i1 + " desc");+ // basic spellcheck testing+ query("q", "toyata", "fl", "id,lowerfilt", "spellcheck", true, "spellcheck.q", "toyata", "qt", "spellCheckCompRH_Direct", "shards.qt", "spellCheckCompRH_Direct");+stress=0; // turn off stress... we want to tex max combos in min timefor (int i=0; i<25*RANDOM_MULTIPLIER; i++) {String f = fieldNames[random().nextInt(fieldNames.length)];@@ -336,7 +341,7 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {assertNotNull("missing shard info", sinfo);assertEquals("should have an entry for each shard ["+sinfo+"] "+shards, cnt, sinfo.size());-+// test shards.tolerant=truefor(int numDownServers = 0; numDownServers < jettys.size()-1; numDownServers++){@@ -383,6 +388,22 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {ShardParams.SHARDS_INFO, "true",ShardParams.SHARDS_TOLERANT, "true");+ queryPartialResults(upShards, upClients,+ "q", "*:*",+ "stats", "true",+ "stats.field", i1,+ ShardParams.SHARDS_INFO, "true",+ ShardParams.SHARDS_TOLERANT, "true");++ queryPartialResults(upShards, upClients,+ "q", "toyata",+ "spellcheck", "true",+ "spellcheck.q", "toyata",+ "qt", "spellCheckCompRH_Direct",+ "shards.qt", "spellCheckCompRH_Direct",+ ShardParams.SHARDS_INFO, "true",+ ShardParams.SHARDS_TOLERANT, "true");+// restart the jettysfor (JettySolrRunner downJetty : downJettys) {downJetty.start();@@ -409,7 +430,7 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {}}- protected void queryPartialResults(final List<String> upShards,+ protected void queryPartialResults(final List<String> upShards,final List<SolrServer> upClients,Object... q) throws Exception {