tanishq-chugh commented on code in PR #6528:
URL: https://github.com/apache/hive/pull/6528#discussion_r3387504534


##########
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/ZookeeperExternalSessionsRegistryClient.java:
##########
@@ -91,22 +110,47 @@ static String normalizeZkPath(String zkNamespace) {
 
   @Override
   public String getSession() throws Exception {
-    synchronized (lock) {
-      if (!isInitialized) {
-        init();
-      }
-      long endTimeNs = System.nanoTime() + (1000000000L * maxAttempts);
-      while (available.isEmpty() && ((endTimeNs - System.nanoTime()) > 0)) {
-        lock.wait(1000L);
+    if (!isInitialized) {
+      synchronized (lock) {
+        if (!isInitialized) {
+          init();
+        }
       }
-      Iterator<String> iter = available.iterator();
-      if (!iter.hasNext()) {
-        throw new IOException("Cannot get a session after " + maxAttempts + " 
attempts");
+    }
+    
+    long endTimeNs = System.nanoTime() + (1000000000L * maxAttempts);
+    long queueWaitTimeMs = Math.max(0, (endTimeNs - System.nanoTime()) / 
1000000L);
+    if (!globalQueue.acquire(queueWaitTimeMs, TimeUnit.MILLISECONDS)) {
+      throw new IOException("Cannot get a session (timed out in queue) after " 
+ maxAttempts + " seconds");
+    }
+
+    try {
+      synchronized (lock) {
+        while (System.nanoTime() < endTimeNs) {

Review Comment:
   Right, changed the code to fix this in commit : 
[fdead45](https://github.com/apache/hive/pull/6528/commits/fdead455bb27f246bda9f2ad3b455458f717988c)



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