sijie commented on a change in pull request #1538: Add rate limit for client 
lookup requests
URL: https://github.com/apache/incubator-pulsar/pull/1538#discussion_r181184955
 
 

 ##########
 File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
 ##########
 @@ -508,8 +533,14 @@ protected boolean isHandshakeCompleted() {
             if (log.isDebugEnabled()) {
                 log.debug("{} Failed to add lookup-request into pending 
queue", requestId);
             }
-            future.completeExceptionally(new 
PulsarClientException.TooManyRequestsException(
-                    "Failed due to too many pending lookup requests"));
+            if (waitingLookupRequestSemaphore.tryAcquire()) {
 
 Review comment:
   nit:
   
   I think you can use a bounded queue instead of two variables - one queue + 
one semaphore.
   
   if you are using a bounded queue, the logic here can be simplified:
   
   ```
   if (!waitingLookupRequests.offer(..)) {
   
        fail(..)
   }
   ```
   
   
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ArrayBlockingQueue.html#offer(E)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to