diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetMerger.java b/solr/core/src/java/org/apache/solr/search/facet/FacetMerger.java index 8d485cbd04b..128228c077a 100644 --- a/solr/core/src/java/org/apache/solr/search/facet/FacetMerger.java +++ b/solr/core/src/java/org/apache/solr/search/facet/FacetMerger.java @@ -67,8 +67,11 @@ public void newShard(String shard) { this.bucketWasMissing = false; } - public void setShard(String shard) { - this.shardNum = shardmap.get(shard); + public boolean setShard(String shard) { + Integer shardNum = shardmap.get(shard); + boolean hasShard = shardNum != null; + this.shardNum = hasShard ? shardNum : -1; + return hasShard; } public int getNewBucketNumber() { 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 c912ebd5e0a..4ddb970be09 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 @@ -193,7 +193,13 @@ public int distributedProcess(ResponseBuilder rb) throws IOException { assert rb.shards.length == facetState.mcontext.numShards; for (String shard : rb.shards) { - facetState.mcontext.setShard(shard); + if (!facetState.mcontext.setShard(shard)) { + // for some reason or another (most likely a failed shard request), + // we do not know about this shard + // there is no need to make a refinement request + // as we didn't even complete the initial request + continue; + } // shard-specific refinement Map refinement = facetState.merger.getRefinement(facetState.mcontext); @@ -319,7 +325,12 @@ public void handleResponses(ResponseBuilder rb, ShardRequest sreq) { // System.err.println("REFINE FACET RESULT FROM SHARD = " + facet); // call merge again with a diff flag set on the context??? facetState.mcontext.root = facet; - facetState.mcontext.setShard(shardRsp.getShard()); // TODO: roll newShard into setShard? + if (!facetState.mcontext.setShard( + shardRsp.getShard())) { // TODO: roll newShard into setShard? + throw new SolrException( + SolrException.ErrorCode.SERVER_ERROR, + "received refinement results for unknown shard: " + shardRsp.getShard()); + } facetState.merger.merge(facet, facetState.mcontext); return; }