jiajunwang commented on a change in pull request #367: Add transient cache for 
CustomRestClient implementation
URL: https://github.com/apache/helix/pull/367#discussion_r309566603
 
 

 ##########
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientImpl.java
 ##########
 @@ -97,7 +111,17 @@ public CustomRestClientImpl(HttpClient httpClient) {
           kv -> result.put(kv.getKey(), 
kv.getValue().get(IS_HEALTHY_FIELD).asBoolean()));
       return result;
     };
-    return handleResponse(post(url, payLoads), jsonConverter);
+    try {
+      // use semaphore to allow X threads to submit HttpRequests at a time
+      // without thread synchronization, duplicate http requests will still 
exist
+      _semaphore.acquire();
+      return handleResponse(post(url, payLoads), jsonConverter);
+    } catch (InterruptedException e) {
+      LOG.warn("Interrupted while acquiring the semaphore", e);
+    } finally {
+      _semaphore.release();
 
 Review comment:
   If any other exception happens before the semaphore acquired, we will have 
one extra release here.
   Although I'm not sure if it could be the case since _semaphore.acquire() is 
the first line in the try block. Could you please check?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to