hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject [04/34] hive git commit: HIVE-14739: Replace runnables directly added to runtime shutdown hooks to avoid deadlock (Prasanth Jayachandran reviewed by Chris Nauroth, Siddharth Seth)
Date Mon, 19 Sep 2016 22:41:50 GMT
HIVE-14739: Replace runnables directly added to runtime shutdown hooks to avoid deadlock (Prasanth
Jayachandran reviewed by Chris Nauroth, Siddharth Seth)


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

Branch: refs/heads/hive-14535
Commit: f80d260250440719301c4c1e95759854598854a4
Parents: 0a6d30b
Author: Prasanth Jayachandran <prasanthj@apache.org>
Authored: Tue Sep 13 14:49:28 2016 -0700
Committer: Prasanth Jayachandran <prasanthj@apache.org>
Committed: Tue Sep 13 14:49:28 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/hive/beeline/BeeLine.java   |   5 +-
 .../org/apache/hadoop/hive/cli/CliDriver.java   |   5 +-
 .../hive/common/util/ShutdownHookManager.java   | 171 +++----------------
 .../common/util/TestShutdownHookManager.java    |  35 ----
 .../hive/hcatalog/common/HiveClientCache.java   |   3 +-
 .../hadoop/hive/metastore/HiveMetaStore.java    |   3 +-
 .../hive/ql/exec/mr/HadoopJobExecHelper.java    |   3 +-
 .../spark/session/SparkSessionManagerImpl.java  |   3 +-
 .../hadoop/hive/ql/exec/tez/TezJobMonitor.java  |   3 +-
 .../apache/hadoop/hive/ql/hooks/ATSHook.java    |   3 +-
 .../zookeeper/CuratorFrameworkSingleton.java    |   3 +-
 .../apache/hive/service/server/HiveServer2.java |   3 +-
 .../ptest/api/server/ExecutionController.java   |   2 +-
 13 files changed, 44 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/beeline/src/java/org/apache/hive/beeline/BeeLine.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
index ecd60f6..5322ca6 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -92,6 +92,7 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hive.beeline.cli.CliOptionsProcessor;
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.thrift.transport.TTransportException;
 
 import org.apache.hive.jdbc.Utils;
@@ -1076,7 +1077,7 @@ public class BeeLine implements Closeable {
     }
 
     // add shutdown hook to flush the history to history file
-    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+    ShutdownHookManager.addShutdownHook(new Runnable() {
         @Override
         public void run() {
             History h = consoleReader.getHistory();
@@ -1088,7 +1089,7 @@ public class BeeLine implements Closeable {
                 }
             }
         }
-    }));
+    });
 
     consoleReader.addCompleter(new BeeLineCompleter(this));
     return consoleReader;

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
----------------------------------------------------------------------
diff --git a/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java b/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
index 874e5aa..5364ca6 100644
--- a/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
+++ b/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
@@ -79,6 +79,7 @@ import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
 import org.apache.hadoop.io.IOUtils;
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -808,7 +809,7 @@ public class CliDriver {
     }
 
     // add shutdown hook to flush the history to history file
-    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+    ShutdownHookManager.addShutdownHook(new Runnable() {
       @Override
       public void run() {
         History h = reader.getHistory();
@@ -820,7 +821,7 @@ public class CliDriver {
           }
         }
       }
-    }));
+    });
   }
 
   protected void setupConsoleReader() throws IOException {

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java
----------------------------------------------------------------------
diff --git a/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java b/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java
index 5efeda9..6585e3b 100644
--- a/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java
+++ b/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java
@@ -18,131 +18,37 @@
 
 package org.apache.hive.common.util;
 
-import com.google.common.annotations.VisibleForTesting;
-
 import java.io.File;
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.hadoop.fs.FileSystem;
+
+import com.google.common.annotations.VisibleForTesting;
 
 /**
- * The <code>ShutdownHookManager</code> enables running shutdownHook
- * in a deterministic order, higher priority first.
- * <p/>
- * The JVM runs ShutdownHooks in a non-deterministic order or in parallel.
- * This class registers a single JVM shutdownHook and run all the
- * shutdownHooks registered to it (to this class) in order based on their
- * priority.
- *
- * Originally taken from o.a.hadoop.util.ShutdownHookManager
+ * This is just a wrapper around hadoop's ShutdownHookManager but also manages delete on
exit hook for temp files.
  */
 public class ShutdownHookManager {
 
-  private static final ShutdownHookManager MGR = new ShutdownHookManager();
+  private static final org.apache.hadoop.util.ShutdownHookManager MGR = org.apache.hadoop.util.ShutdownHookManager.get();
 
   private static final DeleteOnExitHook DELETE_ON_EXIT_HOOK = new DeleteOnExitHook();
 
-  private static final Logger LOG = LoggerFactory.getLogger(ShutdownHookManager.class);
-
   static {
-    MGR.addShutdownHookInternal(DELETE_ON_EXIT_HOOK, -1);
-    Runtime.getRuntime().addShutdownHook(
-      new Thread() {
-        @Override
-        public void run() {
-          MGR.shutdownInProgress.set(true);
-          for (Runnable hook : getShutdownHooksInOrder()) {
-            try {
-              hook.run();
-            } catch (Throwable ex) {
-              LOG.warn("ShutdownHook '" + hook.getClass().getSimpleName() +
-                       "' failed, " + ex.toString(), ex);
-            }
-          }
-        }
-      }
-    );
+    MGR.addShutdownHook(DELETE_ON_EXIT_HOOK, -1);
   }
 
-
   /**
-   * Private structure to store ShutdownHook and its priority.
+   * Adds shutdown hook with default priority (10)
+   * @param shutdownHook - shutdown hook
    */
-  private static class HookEntry {
-    Runnable hook;
-    int priority;
-
-    public HookEntry(Runnable hook, int priority) {
-      this.hook = hook;
-      this.priority = priority;
-    }
-
-    @Override
-    public int hashCode() {
-      return hook.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-      boolean eq = false;
-      if (obj != null) {
-        if (obj instanceof HookEntry) {
-          eq = (hook == ((HookEntry)obj).hook);
-        }
-      }
-      return eq;
-    }
-
-  }
-
-  private final Set<HookEntry> hooks =
-    Collections.synchronizedSet(new HashSet<HookEntry>());
-
-  private final AtomicBoolean shutdownInProgress = new AtomicBoolean(false);
-
-  //private to constructor to ensure singularity
-  private ShutdownHookManager() {
+  public static void addShutdownHook(Runnable shutdownHook) {
+    addShutdownHook(shutdownHook, FileSystem.SHUTDOWN_HOOK_PRIORITY);
   }
 
   /**
-   * Returns the list of shutdownHooks in order of execution,
-   * Highest priority first.
-   *
-   * @return the list of shutdownHooks in order of execution.
-   */
-  static List<Runnable> getShutdownHooksInOrder() {
-    return MGR.getShutdownHooksInOrderInternal();
-  }
-
-  private List<Runnable> getShutdownHooksInOrderInternal() {
-    List<HookEntry> list;
-    synchronized (MGR.hooks) {
-      list = new ArrayList<HookEntry>(MGR.hooks);
-    }
-    Collections.sort(list, new Comparator<HookEntry>() {
-
-      //reversing comparison so highest priority hooks are first
-      @Override
-      public int compare(HookEntry o1, HookEntry o2) {
-        return o2.priority - o1.priority;
-      }
-    });
-    List<Runnable> ordered = new ArrayList<Runnable>();
-    for (HookEntry entry: list) {
-      ordered.add(entry.hook);
-    }
-    return ordered;
-  }
-
-
-  /**
    * Adds a shutdownHook with a priority, the higher the priority
    * the earlier will run. ShutdownHooks with same priority run
    * in a non-deterministic order.
@@ -154,17 +60,16 @@ public class ShutdownHookManager {
     if (priority < 0) {
       throw new IllegalArgumentException("Priority should be greater than or equal to zero");
     }
-    MGR.addShutdownHookInternal(shutdownHook, priority);
+    MGR.addShutdownHook(shutdownHook, priority);
   }
 
-  private void addShutdownHookInternal(Runnable shutdownHook, int priority) {
-    if (shutdownHook == null) {
-      throw new IllegalArgumentException("shutdownHook cannot be NULL");
-    }
-    if (shutdownInProgress.get()) {
-      throw new IllegalStateException("Shutdown in progress, cannot add a shutdownHook");
-    }
-    hooks.add(new HookEntry(shutdownHook, priority));
+  /**
+   * Indicates if shutdown is in progress or not.
+   *
+   * @return TRUE if the shutdown is in progress, otherwise FALSE.
+   */
+  public static boolean isShutdownInProgress() {
+    return MGR.isShutdownInProgress();
   }
 
   /**
@@ -178,41 +83,7 @@ public class ShutdownHookManager {
     if (shutdownHook == null) {
       return false;
     }
-    return MGR.removeShutdownHookInternal(shutdownHook);
-  }
-
-  private boolean removeShutdownHookInternal(Runnable shutdownHook) {
-    if (shutdownInProgress.get()) {
-      throw new IllegalStateException("Shutdown in progress, cannot remove a shutdownHook");
-    }
-    return hooks.remove(new HookEntry(shutdownHook, 0));
-  }
-
-  /**
-   * Indicates if a shutdownHook is registered or not.
-   *
-   * @param shutdownHook shutdownHook to check if registered.
-   * @return TRUE/FALSE depending if the shutdownHook is is registered.
-   */
-  public static boolean hasShutdownHook(Runnable shutdownHook) {
-    return MGR.hasShutdownHookInternal(shutdownHook);
-  }
-
-  public boolean hasShutdownHookInternal(Runnable shutdownHook) {
-    return hooks.contains(new HookEntry(shutdownHook, 0));
-  }
-
-  /**
-   * Indicates if shutdown is in progress or not.
-   *
-   * @return TRUE if the shutdown is in progress, otherwise FALSE.
-   */
-  public static boolean isShutdownInProgress() {
-    return MGR.isShutdownInProgressInternal();
-  }
-
-  private boolean isShutdownInProgressInternal() {
-    return shutdownInProgress.get();
+    return MGR.removeShutdownHook(shutdownHook);
   }
 
   /**
@@ -221,7 +92,7 @@ public class ShutdownHookManager {
    * @see {@link org.apache.hadoop.hive.common.FileUtils#createTempFile}
    */
   public static void deleteOnExit(File file) {
-    if (isShutdownInProgress()) {
+    if (MGR.isShutdownInProgress()) {
       throw new IllegalStateException("Shutdown in progress, cannot add a deleteOnExit");
     }
     DELETE_ON_EXIT_HOOK.deleteTargets.add(file);
@@ -231,7 +102,7 @@ public class ShutdownHookManager {
    * deregister file from delete-on-exit hook
    */
   public static void cancelDeleteOnExit(File file) {
-    if (isShutdownInProgress()) {
+    if (MGR.isShutdownInProgress()) {
       throw new IllegalStateException("Shutdown in progress, cannot cancel a deleteOnExit");
     }
     DELETE_ON_EXIT_HOOK.deleteTargets.remove(file);

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java
----------------------------------------------------------------------
diff --git a/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java b/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java
index 66f6073..d740670 100644
--- a/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java
+++ b/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java
@@ -34,41 +34,6 @@ import org.apache.hadoop.hive.common.FileUtils;
 public class TestShutdownHookManager {
 
   @Test
-  public void shutdownHookManager() {
-    Assert.assertEquals(1, ShutdownHookManager.getShutdownHooksInOrder().size());
-    Runnable hook1 = new Runnable() {
-      @Override
-      public void run() {
-      }
-    };
-    Runnable hook2 = new Runnable() {
-      @Override
-      public void run() {
-      }
-    };
-
-    ShutdownHookManager.addShutdownHook(hook1, 0);
-    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook1));
-    Assert.assertEquals(2, ShutdownHookManager.getShutdownHooksInOrder().size());
-    Assert.assertEquals(hook1, ShutdownHookManager.getShutdownHooksInOrder().get(0));
-    ShutdownHookManager.removeShutdownHook(hook1);
-    Assert.assertFalse(ShutdownHookManager.hasShutdownHook(hook1));
-
-    ShutdownHookManager.addShutdownHook(hook1, 0);
-    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook1));
-    Assert.assertEquals(2, ShutdownHookManager.getShutdownHooksInOrder().size());
-    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook1));
-    Assert.assertEquals(2, ShutdownHookManager.getShutdownHooksInOrder().size());
-
-    ShutdownHookManager.addShutdownHook(hook2, 1);
-    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook1));
-    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook2));
-    Assert.assertEquals(3, ShutdownHookManager.getShutdownHooksInOrder().size());
-    Assert.assertEquals(hook2, ShutdownHookManager.getShutdownHooksInOrder().get(0));
-    Assert.assertEquals(hook1, ShutdownHookManager.getShutdownHooksInOrder().get(1));
-  }
-
-  @Test
   public void deleteOnExit() throws IOException {
     File file = FileUtils.createTempFile(null, "tmp", null);
     Assert.assertTrue(ShutdownHookManager.isRegisteredToDeleteOnExit(file));

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
----------------------------------------------------------------------
diff --git a/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
b/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
index 51f516e..c1b63d9 100644
--- a/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
+++ b/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
@@ -42,6 +42,7 @@ import org.apache.hadoop.hive.metastore.annotation.NoReconnect;
 import org.apache.hadoop.hive.shims.ShimLoader;
 import org.apache.hadoop.hive.shims.Utils;
 import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -217,7 +218,7 @@ class HiveClientCache {
       }
     };
 
-    Runtime.getRuntime().addShutdownHook(cleanupHiveClientShutdownThread);
+    ShutdownHookManager.addShutdownHook(cleanupHiveClientShutdownThread);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
index 3f85ca6..f0b8476 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -97,6 +97,7 @@ import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.util.ReflectionUtils;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hive.common.util.HiveStringUtils;
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.thrift.TException;
 import org.apache.thrift.TProcessor;
 import org.apache.thrift.protocol.TBinaryProtocol;
@@ -6641,7 +6642,7 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       }
 
       // Add shutdown hook.
-      Runtime.getRuntime().addShutdownHook(new Thread() {
+      ShutdownHookManager.addShutdownHook(new Runnable() {
         @Override
         public void run() {
           String shutdownMsg = "Shutting down hive metastore.";

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java
index bb6ed84..41887d7 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java
@@ -54,6 +54,7 @@ import org.apache.hadoop.mapred.JobStatus;
 import org.apache.hadoop.mapred.RunningJob;
 import org.apache.hadoop.mapred.TaskCompletionEvent;
 import org.apache.hadoop.mapred.TaskReport;
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Logger;
@@ -172,7 +173,7 @@ public class HadoopJobExecHelper {
    *
    */
   static {
-      Runtime.getRuntime().addShutdownHook(new Thread() {
+    ShutdownHookManager.addShutdownHook(new Runnable() {
         @Override
         public void run() {
           killRunningJobs();

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
b/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
index 75e5913..3c2f0e6 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.hadoop.hive.conf.HiveConf;
@@ -46,7 +47,7 @@ public class SparkSessionManagerImpl implements SparkSessionManager {
   private static SparkSessionManagerImpl instance;
 
   static {
-    Runtime.getRuntime().addShutdownHook(new Thread() {
+    ShutdownHookManager.addShutdownHook(new Runnable() {
       @Override
       public void run() {
         try {

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java
index d617879..211a281 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java
@@ -48,6 +48,7 @@ import org.apache.hadoop.hive.ql.log.PerfLogger;
 import org.apache.hadoop.hive.ql.plan.BaseWork;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.tez.common.counters.FileSystemCounter;
 import org.apache.tez.common.counters.TaskCounter;
 import org.apache.tez.common.counters.TezCounter;
@@ -140,7 +141,7 @@ public class TezJobMonitor {
 
   static {
     shutdownList = new LinkedList<DAGClient>();
-    Runtime.getRuntime().addShutdownHook(new Thread() {
+    ShutdownHookManager.addShutdownHook(new Runnable() {
       @Override
       public void run() {
         TezJobMonitor.killRunningJobs();

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java b/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java
index e593945..7438570 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java
@@ -37,6 +37,7 @@ import org.apache.hadoop.yarn.api.records.timeline.TimelineEntity;
 import org.apache.hadoop.yarn.api.records.timeline.TimelineEvent;
 import org.apache.hadoop.yarn.client.api.TimelineClient;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -75,7 +76,7 @@ public class ATSHook implements ExecuteWithHookContext {
         timelineClient.init(yarnConf);
         timelineClient.start();
 
-        Runtime.getRuntime().addShutdownHook(new Thread() {
+        ShutdownHookManager.addShutdownHook(new Runnable() {
           @Override
           public void run() {
             try {

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
b/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
index 6482f3b..b55b6ca 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.hive.ql.lockmgr.zookeeper;
 
 import java.util.concurrent.TimeUnit;
 
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.curator.framework.CuratorFramework;
@@ -34,7 +35,7 @@ public class CuratorFrameworkSingleton {
   static final Logger LOG = LoggerFactory.getLogger("CuratorFrameworkSingleton");
   static {
     // Add shutdown hook.
-    Runtime.getRuntime().addShutdownHook(new Thread() {
+    ShutdownHookManager.addShutdownHook(new Runnable() {
       @Override
       public void run() {
         closeAndReleaseInstance();

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/service/src/java/org/apache/hive/service/server/HiveServer2.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/server/HiveServer2.java b/service/src/java/org/apache/hive/service/server/HiveServer2.java
index 9822a85..58e9aeb 100644
--- a/service/src/java/org/apache/hive/service/server/HiveServer2.java
+++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java
@@ -60,6 +60,7 @@ import org.apache.hadoop.hive.shims.Utils;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hive.common.util.HiveStringUtils;
 import org.apache.hive.common.util.HiveVersionInfo;
+import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.hive.http.HttpServer;
 import org.apache.hive.http.LlapServlet;
 import org.apache.hive.service.CompositeService;
@@ -206,7 +207,7 @@ public class HiveServer2 extends CompositeService {
       throw new ServiceException(ie);
     }
     // Add a shutdown hook for catching SIGTERM & SIGINT
-    Runtime.getRuntime().addShutdownHook(new Thread() {
+    ShutdownHookManager.addShutdownHook(new Runnable() {
       @Override
       public void run() {
         hiveServer2.stop();

http://git-wip-us.apache.org/repos/asf/hive/blob/f80d2602/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
b/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
index 2f96ad0..dd8957d 100644
--- a/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
+++ b/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
@@ -101,7 +101,7 @@ public class ExecutionController {
     mTestExecutor.setName("TestExecutor");
     mTestExecutor.setDaemon(true);
     mTestExecutor.start();
-    Runtime.getRuntime().addShutdownHook(new Thread() {
+    ShutdownHookManager.addShutdownHook(new Runnable() {
       @Override
       public void run() {
         LOG.info("Shutdown hook called");


Mime
View raw message