diff --git a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java index 5b5672faf8d..0d5b6c27c00 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java @@ -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 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(); @@ -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 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);