AmatyaAvadhanula commented on a change in pull request #12298:
URL: https://github.com/apache/druid/pull/12298#discussion_r820672154



##########
File path: 
core/src/main/java/org/apache/druid/java/util/http/client/pool/ResourcePool.java
##########
@@ -212,15 +259,21 @@ V get()
         if (closed) {
           log.info(StringUtils.format("get() called even though I'm closed. 
key[%s]", key));
           return null;
-        } else if (!resourceHolderList.isEmpty()) {
-          ResourceHolder<V> holder = resourceHolderList.removeFirst();
-          if (System.currentTimeMillis() - holder.getLastAccessedTime() > 
unusedResourceTimeoutMillis) {
-            factory.close(holder.getResource());
+        } else if (numLentResources + deficit < maxSize) {
+          // Attempt to take an existing resource or create one if list is 
empty
+          if (resourceHolderList.isEmpty()) {
             poolVal = factory.generate(key);
           } else {
-            poolVal = holder.getResource();
+            ResourceHolder<V> holder = resourceHolderList.removeFirst();
+            if (System.currentTimeMillis() - holder.getLastAccessedTime() > 
unusedResourceTimeoutMillis) {
+              factory.close(holder.getResource());
+              poolVal = factory.generate(key);
+            } else {
+              poolVal = holder.getResource();
+            }
           }
         } else if (deficit > 0) {
+          // We are allowed to generate to fill the deficit objects

Review comment:
       While maxNum is the limit for number of resources that can be allocated 
at any point in time, it is done with the aid of both numLentResources and 
deficit.
   
   As long as numLentResources + deficit < maxNum:
    __Try to take a resource from the existing pool or create one
   Else if deficit > 0:
   __Decrement deficit and attempt to create a new resource which will be then 
returned to resourceHolderList




-- 
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]

Reply via email to