From 199d51f1a3fe6188b405ef99f8f75ddd54729f6a Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Fri, 1 Sep 2023 15:37:39 +0100 Subject: [PATCH] NO JIRA: factor out protected SearchHandler.checkCircuitBreakers method (#1882) --- .../solr/handler/component/SearchHandler.java | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) 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);