HIVE-12926 : Another synchronization issue with tez/llap session pool in hs2 
(Sergey Shelukhin, reviewed by Siddharth Seth and Vikram Dixit K)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/d9cb3e46
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/d9cb3e46
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/d9cb3e46

Branch: refs/heads/branch-2.0
Commit: d9cb3e467e7818c25db7c6bfc7f69da20badbe56
Parents: c09cc1d
Author: Sergey Shelukhin <[email protected]>
Authored: Wed Jan 27 14:41:42 2016 -0800
Committer: Sergey Shelukhin <[email protected]>
Committed: Wed Jan 27 14:42:22 2016 -0800

----------------------------------------------------------------------
 .../hive/ql/exec/tez/TezSessionPoolManager.java | 34 +++++++++-----------
 1 file changed, 16 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/d9cb3e46/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPoolManager.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPoolManager.java 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPoolManager.java
index 891d2a8..3d20a54 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPoolManager.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPoolManager.java
@@ -31,6 +31,7 @@ import java.util.concurrent.PriorityBlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -93,7 +94,8 @@ public class TezSessionPoolManager {
 
   private static TezSessionPoolManager sessionPool = null;
 
-  private static List<TezSessionState> openSessions = new 
LinkedList<TezSessionState>();
+  private static final List<TezSessionPoolSession> openSessions
+    = new LinkedList<TezSessionPoolSession>();
 
   public static TezSessionPoolManager getInstance()
       throws Exception {
@@ -299,15 +301,14 @@ public class TezSessionPoolManager {
       return;
     }
 
+    List<TezSessionPoolSession> sessionsToClose = null;
     synchronized (openSessions) {
-      // we can just stop all the sessions
-      Iterator<TezSessionState> iter = openSessions.iterator();
-      while (iter.hasNext()) {
-        TezSessionState sessionState = iter.next();
-        if (sessionState.isDefault()) {
-          sessionState.close(false);
-          iter.remove();
-        }
+      sessionsToClose = new ArrayList<TezSessionPoolSession>(openSessions);
+    }
+    // we can just stop all the sessions
+    for (TezSessionState sessionState : sessionsToClose) {
+      if (sessionState.isDefault()) {
+        sessionState.close(false);
       }
     }
 
@@ -425,16 +426,13 @@ public class TezSessionPoolManager {
   }
 
   public void closeNonDefaultSessions(boolean keepTmpDir) throws Exception {
+    List<TezSessionPoolSession> sessionsToClose = null;
     synchronized (openSessions) {
-      Iterator<TezSessionState> iter = openSessions.iterator();
-      while (iter.hasNext()) {
-        System.err.println("Shutting down tez session.");
-        TezSessionState sessionState = iter.next();
-        closeIfNotDefault(sessionState, keepTmpDir);
-        if (sessionState.isDefault() == false) {
-          iter.remove();
-        }
-      }
+      sessionsToClose = new ArrayList<TezSessionPoolSession>(openSessions);
+    }
+    for (TezSessionPoolSession sessionState : sessionsToClose) {
+      System.err.println("Shutting down tez session.");
+      closeIfNotDefault(sessionState, keepTmpDir);
     }
   }
 

Reply via email to