psalagnac commented on code in PR #1871: URL: https://github.com/apache/solr/pull/1871#discussion_r1315124617
########## solr/core/src/java/org/apache/solr/util/circuitbreaker/RequestType.java: ########## @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.util.circuitbreaker; + +/** Request types that can be registered for a {@link CircuitBreaker} */ Review Comment: Adding this classification for request types is great and probably could have plenty of usages, not only for circuit breaker. I suggest this is moved to a more generic package. ########## solr/solr-ref-guide/modules/deployment-guide/pages/circuit-breakers.adoc: ########## @@ -72,6 +73,30 @@ To enable and configure the CPU utilization based circuit breaker: The `threshold` is defined in units of CPU utilization. +== Advanced example + +In this example we will prevent update requests above 80% CPU load, and prevent search requests above 95% CPU load. +This would prevent expensive bulk updates from impacting search. Note also the support for short-form class name. + +[source,xml] +---- +<config> + <circuitBreaker class="solr.CPUCircuitBreaker"> + <double name="threshold">80</double> + <arr name="requestTypes"> + <str>update</str> Review Comment: I would add in the doc that possible values for `requestsTypes `are defined in enum `RequestType`. ########## solr/core/src/java/org/apache/solr/handler/ContentStreamHandlerBase.java: ########## @@ -101,6 +112,30 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw } } + /** + * Check if UPDATE 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) { + CircuitBreakerRegistry circuitBreakerRegistry = req.getCore().getCircuitBreakerRegistry(); + if (circuitBreakerRegistry.isEnabled(RequestType.UPDATE)) { + List<CircuitBreaker> trippedCircuitBreakers = + circuitBreakerRegistry.checkTripped(RequestType.UPDATE); + if (trippedCircuitBreakers != null) { + String errorMessage = CircuitBreakerRegistry.toErrorMessage(trippedCircuitBreakers); + rsp.add(STATUS, FAILURE); + rsp.setException( + new SolrException( + SolrException.ErrorCode.SERVICE_UNAVAILABLE, Review Comment: Have you considered using a different error code for circuit breakers? HTTP `429 Too Many Requests` could be appropriate here. Mostly, if we want the Solr caller to slow down, it is required to somehow expose that we're not just facing a generic failure but some self protection mechanisms. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
