diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 72009ddcfee..17cc4fc0dec 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -97,6 +97,9 @@ Bug Fixes * SOLR-7616: Faceting on a numeric field with a unique() subfacet function on another numeric field can result in incorrect results or an exception. (yonik) +* SOLR-7518: New Facet Module should respect shards.tolerant and process all non-failing shards + instead of throwing an exception. (yonik) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetModule.java b/solr/core/src/java/org/apache/solr/search/facet/FacetModule.java index efeb654eab3..cf81b64c6c1 100644 --- a/solr/core/src/java/org/apache/solr/search/facet/FacetModule.java +++ b/solr/core/src/java/org/apache/solr/search/facet/FacetModule.java @@ -169,6 +169,7 @@ public class FacetModule extends SearchComponent { for (ShardResponse shardRsp : sreq.responses) { SolrResponse rsp = shardRsp.getSolrResponse(); NamedList top = rsp.getResponse(); + if (top == null) continue; // shards.tolerant=true will cause this to happen on exceptions/errors Object facet = top.get("facets"); if (facet == null) continue; if (facetState.merger == null) { diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java index 2ca1b0adf17..9df7453a779 100644 --- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java +++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java @@ -174,18 +174,23 @@ public class TestJsonFacets extends SolrTestCaseHS { } + public void indexSimple(Client client) throws Exception { + client.deleteByQuery("*:*", null); + client.add(sdoc("id", "1", "cat_s", "A", "where_s", "NY", "num_d", "4", "num_i", "2", "val_b", "true", "sparse_s", "one"), null); + client.add(sdoc("id", "2", "cat_s", "B", "where_s", "NJ", "num_d", "-9", "num_i", "-5", "val_b", "false"), null); + client.add(sdoc("id", "3"), null); + client.commit(); + client.add(sdoc("id", "4", "cat_s", "A", "where_s", "NJ", "num_d", "2", "num_i", "3"), null); + client.add(sdoc("id", "5", "cat_s", "B", "where_s", "NJ", "num_d", "11", "num_i", "7", "sparse_s", "two"),null); + client.commit(); + client.add(sdoc("id", "6", "cat_s", "B", "where_s", "NY", "num_d", "-5", "num_i", "-5"),null); + client.commit(); + } + public void testStatsSimple() throws Exception { - assertU(delQ("*:*")); - assertU(add(doc("id", "1", "cat_s", "A", "where_s", "NY", "num_d", "4", "num_i", "2", "val_b", "true", "sparse_s","one"))); - assertU(add(doc("id", "2", "cat_s", "B", "where_s", "NJ", "num_d", "-9", "num_i", "-5", "val_b", "false"))); - assertU(add(doc("id", "3"))); - assertU(commit()); - assertU(add(doc("id", "4", "cat_s", "A", "where_s", "NJ", "num_d", "2", "num_i", "3"))); - assertU(add(doc("id", "5", "cat_s", "B", "where_s", "NJ", "num_d", "11", "num_i", "7", "sparse_s","two"))); - assertU(commit()); - assertU(add(doc("id", "6", "cat_s", "B", "where_s", "NY", "num_d", "-5", "num_i", "-5"))); - assertU(commit()); + Client client = Client.localClient(); + indexSimple(client); // test multiple json.facet commands assertJQ(req("q", "*:*", "rows", "0" @@ -1039,7 +1044,33 @@ public class TestJsonFacets extends SolrTestCaseHS { } + public void testTolerant() throws Exception { + initServers(); + Client client = servers.getClient(random().nextInt()); + client.queryDefaults().set("shards", servers.getShards() + ",[ff01::114]:33332:/ignore_exception"); + indexSimple(client); + try { + client.testJQ(params("ignore_exception", "true", "shards.tolerant", "false", "q", "*:*" + , "json.facet", "{f:{type:terms, field:cat_s}}" + ) + , "facets=={ count:6," + + "f:{ buckets:[{val:B,count:3},{val:A,count:2}] }" + + "}" + ); + fail("we should have failed"); + } catch (Exception e) { + // ok + } + + client.testJQ(params("ignore_exception", "true", "shards.tolerant", "true", "q", "*:*" + , "json.facet", "{f:{type:terms, field:cat_s}}" + ) + , "facets=={ count:6," + + "f:{ buckets:[{val:B,count:3},{val:A,count:2}] }" + + "}" + ); + } public void XtestPercentiles() { AVLTreeDigest catA = new AVLTreeDigest(100);