Skip to content

Commit

Permalink
Facet refine handle unknown shard. (#238)
Browse files Browse the repository at this point in the history
* Facet refine handle unknown shard.

Shards with failed requests may not be in the shard map.
We should handle those cleanly.

* tidy
  • Loading branch information
claygoddard authored Dec 9, 2024
1 parent d6a38cf commit 42847a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
15 changes: 13 additions & 2 deletions solr/core/src/java/org/apache/solr/search/facet/FacetModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> refinement = facetState.merger.getRefinement(facetState.mcontext);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 42847a6

Please sign in to comment.