Skip to content

Commit

Permalink
NO JIRA: factor out protected SearchHandler.checkCircuitBreakers meth…
Browse files Browse the repository at this point in the history
…od (apache#1882)
  • Loading branch information
cpoerschke authored Sep 1, 2023
1 parent 8c0d1a0 commit 199d51f
Showing 1 changed file with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,29 +329,14 @@ protected ResponseBuilder newResponseBuilder(
return new ResponseBuilder(req, rsp, components);
}

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
if (req.getParams().getBool(ShardParams.IS_SHARD, false)) {
int purpose = req.getParams().getInt(ShardParams.SHARDS_PURPOSE, 0);
SolrPluginUtils.forEachRequestPurpose(
purpose, n -> shardPurposes.computeIfAbsent(n, name -> new Counter()).inc());
}

List<SearchComponent> components = getComponents();
ResponseBuilder rb = newResponseBuilder(req, rsp, components);
if (rb.requestInfo != null) {
rb.requestInfo.setResponseBuilder(rb);
}

rb.isDistrib = isDistrib(req);
tagRequestWithRequestId(rb);

boolean dbg = req.getParams().getBool(CommonParams.DEBUG_QUERY, false);
rb.setDebug(dbg);
if (dbg == false) { // if it's true, we are doing everything anyway.
SolrPluginUtils.getDebugInterests(req.getParams().getParams(CommonParams.DEBUG), rb);
}

/**
* Check if circuit breakers are tripped. Override this method in sub classes that do not want to
* check circuit breakers.
*
* @return true if circuit breakers are tripped, false otherwise.
*/
protected boolean checkCircuitBreakers(
SolrQueryRequest req, SolrQueryResponse rsp, ResponseBuilder rb) {
final RTimerTree timer = rb.isDebug() ? req.getRequestTimer() : null;

final CircuitBreakerRegistry circuitBreakerRegistry = req.getCore().getCircuitBreakerRegistry();
Expand All @@ -376,9 +361,40 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
new SolrException(
SolrException.ErrorCode.SERVICE_UNAVAILABLE,
"Circuit Breakers tripped " + errorMessage));
return;
return true;
}
}
return false;
}

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
if (req.getParams().getBool(ShardParams.IS_SHARD, false)) {
int purpose = req.getParams().getInt(ShardParams.SHARDS_PURPOSE, 0);
SolrPluginUtils.forEachRequestPurpose(
purpose, n -> shardPurposes.computeIfAbsent(n, name -> new Counter()).inc());
}

List<SearchComponent> components = getComponents();
ResponseBuilder rb = newResponseBuilder(req, rsp, components);
if (rb.requestInfo != null) {
rb.requestInfo.setResponseBuilder(rb);
}

rb.isDistrib = isDistrib(req);
tagRequestWithRequestId(rb);

boolean dbg = req.getParams().getBool(CommonParams.DEBUG_QUERY, false);
rb.setDebug(dbg);
if (dbg == false) { // if it's true, we are doing everything anyway.
SolrPluginUtils.getDebugInterests(req.getParams().getParams(CommonParams.DEBUG), rb);
}

final RTimerTree timer = rb.isDebug() ? req.getRequestTimer() : null;

if (checkCircuitBreakers(req, rsp, rb)) {
return; // Circuit breaker tripped, return immediately
}

// creates a ShardHandler object only if it's needed
final ShardHandler shardHandler1 = getAndPrepShardHandler(req, rb);
Expand Down

0 comments on commit 199d51f

Please sign in to comment.