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/ae535fec
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/ae535fec
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/ae535fec

Branch: refs/heads/master
Commit: ae535fec13a4d3d40c11397ff97f1c6e94c929b4
Parents: d3af821
Author: Sergey Shelukhin <[email protected]>
Authored: Wed Jan 27 14:41:42 2016 -0800
Committer: Sergey Shelukhin <[email protected]>
Committed: Wed Jan 27 14:41:42 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/ae535fec/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 73f3766..f8f3cad 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
@@ -33,6 +33,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;
@@ -95,7 +96,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 {
@@ -342,15 +344,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);
       }
     }
 
@@ -468,16 +469,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