From 8d6eb7c56471742da59c1ffa8e5b51fe85242d63 Mon Sep 17 00:00:00 2001 From: hitesh Date: Thu, 24 Oct 2024 12:16:57 -0700 Subject: [PATCH] tidy --- .../apache/solr/core/RateLimiterConfig.java | 1 + .../servlet/PriorityBasedRateLimiter.java | 8 +++-- .../solr/servlet/TestRequestRateLimiter.java | 32 ++++++++++--------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/RateLimiterConfig.java b/solr/core/src/java/org/apache/solr/core/RateLimiterConfig.java index c8f37a5eeb8..9bd24cf4113 100644 --- a/solr/core/src/java/org/apache/solr/core/RateLimiterConfig.java +++ b/solr/core/src/java/org/apache/solr/core/RateLimiterConfig.java @@ -33,6 +33,7 @@ public class RateLimiterConfig { public final boolean isSlotBorrowingEnabled; public final int guaranteedSlotsThreshold; public final Boolean priorityBasedEnabled; + /** * We store the config definition in order to determine whether anything has changed that would * call for re-initialization. diff --git a/solr/core/src/java/org/apache/solr/servlet/PriorityBasedRateLimiter.java b/solr/core/src/java/org/apache/solr/servlet/PriorityBasedRateLimiter.java index 6c9a4906580..d2985082f33 100644 --- a/solr/core/src/java/org/apache/solr/servlet/PriorityBasedRateLimiter.java +++ b/solr/core/src/java/org/apache/solr/servlet/PriorityBasedRateLimiter.java @@ -13,7 +13,8 @@ * priorities {@link SolrRequest.RequestPriorities} FOREGROUND and {@link * SolrRequest.RequestPriorities} BACKGROUND Requests. Client can pass the {@link * org.apache.solr.common.params.CommonParams} SOLR_REQUEST_TYPE_PARAM request header to indicate - * the foreground and background request. Foreground requests has high priority than background requests + * the foreground and background request. Foreground requests has high priority than background + * requests */ public class PriorityBasedRateLimiter extends RequestRateLimiter { private final AtomicInteger priorityOneRequests = new AtomicInteger(); @@ -44,7 +45,7 @@ public SlotReservation handleRequest(String requestPriority) { if (!acquire(requestPriority)) { return null; } - }catch (InterruptedException ie) { + } catch (InterruptedException ie) { return null; } return () -> PriorityBasedRateLimiter.this.release(requestPriority); @@ -66,7 +67,8 @@ private boolean acquire(String priority) throws InterruptedException { } private boolean nextInQueue() throws InterruptedException { - boolean acquired = this.numRequestsAllowed.tryAcquire(1, this.waitTimeoutInMillis, TimeUnit.MILLISECONDS); + boolean acquired = + this.numRequestsAllowed.tryAcquire(1, this.waitTimeoutInMillis, TimeUnit.MILLISECONDS); if (!acquired) { return false; } diff --git a/solr/core/src/test/org/apache/solr/servlet/TestRequestRateLimiter.java b/solr/core/src/test/org/apache/solr/servlet/TestRequestRateLimiter.java index bc87aa839a7..67ea40dfb56 100644 --- a/solr/core/src/test/org/apache/solr/servlet/TestRequestRateLimiter.java +++ b/solr/core/src/test/org/apache/solr/servlet/TestRequestRateLimiter.java @@ -665,36 +665,38 @@ public void testPriorityBasedRateLimiterTimeout() throws Exception { // PriorityBasedRateLimiter RateLimiterConfig rateLimiterConfig = - new RateLimiterConfig( - SolrRequest.SolrRequestType.QUERY, - true, - 1, - 10, - 1 /* allowedRequests */, - true /* isSlotBorrowing */, - true); + new RateLimiterConfig( + SolrRequest.SolrRequestType.QUERY, + true, + 1, + 10, + 1 /* allowedRequests */, + true /* isSlotBorrowing */, + true); PriorityBasedRateLimiter requestRateLimiter = new PriorityBasedRateLimiter(rateLimiterConfig); rateLimitManager.registerRequestRateLimiter( - requestRateLimiter, SolrRequest.SolrRequestType.PRIORITY_BASED); + requestRateLimiter, SolrRequest.SolrRequestType.PRIORITY_BASED); HttpServletRequest firstRequest = new DummyRequest(null, "FOREGROUND"); - RequestRateLimiter.SlotReservation firstRequestAllowed = rateLimitManager.handleRequest(firstRequest); + RequestRateLimiter.SlotReservation firstRequestAllowed = + rateLimitManager.handleRequest(firstRequest); assertNotNull(firstRequestAllowed); assertEquals(1, requestRateLimiter.getRequestsAllowed()); - HttpServletRequest secondRequest = new DummyRequest(null, "FOREGROUND"); - RequestRateLimiter.SlotReservation secondRequestNotAllowed = rateLimitManager.handleRequest(secondRequest); - assertNull(secondRequestNotAllowed); - assertEquals(1, requestRateLimiter.getRequestsAllowed()); + RequestRateLimiter.SlotReservation secondRequestNotAllowed = + rateLimitManager.handleRequest(secondRequest); + assertNull(secondRequestNotAllowed); + assertEquals(1, requestRateLimiter.getRequestsAllowed()); HttpServletRequest thirdRequest = new DummyRequest(null, "BACKGROUND"); - RequestRateLimiter.SlotReservation thirdRequestNotAllowed = rateLimitManager.handleRequest(thirdRequest); + RequestRateLimiter.SlotReservation thirdRequestNotAllowed = + rateLimitManager.handleRequest(thirdRequest); assertNull(thirdRequestNotAllowed); assertEquals(1, requestRateLimiter.getRequestsAllowed());