Skip to content

Commit

Permalink
Handling BAD_REQUEST exceptions as failures even with shard.tolerant …
Browse files Browse the repository at this point in the history
…as true (#139)

* Handling BAD_REQUEST exceptions as failures even with shard.tolerant as true

* Fixing forbiddenapi use

* Updating the set of error codes to just be a Set
  • Loading branch information
Justin Sweeney committed Sep 7, 2023
1 parent c64d985 commit 8353f01
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public class SearchHandler extends RequestHandlerBase

protected static final String SHARD_HANDLER_SUFFIX = "[shard]";

private static final Set<SolrException.ErrorCode> NONTOLERANT_ERROR_CODES =
Set.of(SolrException.ErrorCode.BAD_REQUEST);

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

/** A counter to ensure that no RID is equal, even if they fall in the same millisecond */
Expand Down Expand Up @@ -577,7 +580,9 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
if (srsp.getException() != null) {
log.warn("Shard request failed : {}", srsp);
// If things are not tolerant, abort everything and rethrow
if (!tolerant) {
if (!tolerant
|| NONTOLERANT_ERROR_CODES.contains(
SolrException.ErrorCode.getErrorCode(srsp.getRspCode()))) {
shardHandler1.cancelAll();
if (srsp.getException() instanceof SolrException) {
throw (SolrException) srsp.getException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ void setResponseCode(int rspCode) {
this.rspCode = rspCode;
}

public int getRspCode() {
return rspCode;
}

void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ public void testLuceneIOExceptionHandling() throws Exception {
assertTrue(
e.getMessage()
.contains("Query contains too many nested clauses; maxClauseCount is set to 1"));

solrQuery = new SolrQuery("{!surround maxBasicQueries=1000 df=title}10W(tes*,test*)");
solrQuery.add(ShardParams.SHARDS_TOLERANT, "true");
final QueryRequest req4 = new QueryRequest(solrQuery);
req4.setMethod(SolrRequest.METHOD.POST);
e =
assertThrows(
BaseHttpSolrClient.RemoteSolrException.class,
() -> req4.process(cloudSolrClient, collectionName));
assertEquals(400, e.code());
assertTrue(
e.getMessage()
.contains("Query contains too many nested clauses; maxClauseCount is set to 1"));
} finally {
if (initialMaxBooleanClauses != null) {
System.setProperty("solr.max.booleanClauses", initialMaxBooleanClauses);
Expand Down

0 comments on commit 8353f01

Please sign in to comment.