hive git commit: HIVE-19050 : DBNotificationListener does not catch exceptions in the cleaner thread (Vihang Karajgaonkar reviewed by Peter Vary)

2018-04-06 Thread vihangk1
Repository: hive
Updated Branches:
  refs/heads/branch-2 7c6467126 -> 8b3ce4688


HIVE-19050 : DBNotificationListener does not catch exceptions in the cleaner 
thread (Vihang Karajgaonkar reviewed by Peter Vary)


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

Branch: refs/heads/branch-2
Commit: 8b3ce4688807ae448794c23fe5094f73205912f3
Parents: 7c646712
Author: Vihang Karajgaonkar 
Authored: Fri Apr 6 10:02:33 2018 -0700
Committer: Vihang Karajgaonkar 
Committed: Fri Apr 6 10:18:43 2018 -0700

--
 .../listener/DbNotificationListener.java| 19 ++---
 .../listener/DummyRawStoreFailEvent.java|  4 +++
 .../listener/TestDbNotificationListener.java| 28 
 3 files changed, 47 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hive/blob/8b3ce468/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
--
diff --git 
a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
 
b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
index 0cf51fb..c4e1675 100644
--- 
a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
+++ 
b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
@@ -105,7 +105,8 @@ public class DbNotificationListener extends 
MetaStoreEventListener {
   private HiveConf hiveConf;
   private MessageFactory msgFactory;
 
-  private synchronized void init(HiveConf conf) throws MetaException {
+  //cleaner is a static object, use static synchronized to make sure its 
thread-safe
+  private static synchronized void init(Configuration conf) throws 
MetaException {
 if (cleaner == null) {
   cleaner =
   new CleanerThread(conf, RawStoreProxy.getProxy(conf, conf,
@@ -120,7 +121,7 @@ public class DbNotificationListener extends 
MetaStoreEventListener {
 // with a Configuration parameter, so we have to declare config as 
Configuration.  But it
 // actually passes a HiveConf, which we need.  So we'll do this ugly down 
cast.
 hiveConf = (HiveConf)config;
-init(hiveConf);
+DbNotificationListener.init(conf);
 msgFactory = MessageFactory.getInstance();
   }
 
@@ -512,7 +513,7 @@ public class DbNotificationListener extends 
MetaStoreEventListener {
 static private long sleepTime = 6;
 
 CleanerThread(HiveConf conf, RawStore rs) {
-  super("CleanerThread");
+  super("DB-Notification-Cleaner");
   this.rs = rs;
   
setTimeToLive(conf.getTimeVar(HiveConf.ConfVars.METASTORE_EVENT_DB_LISTENER_TTL,
   TimeUnit.SECONDS));
@@ -522,7 +523,17 @@ public class DbNotificationListener extends 
MetaStoreEventListener {
 @Override
 public void run() {
   while (true) {
-rs.cleanNotificationEvents(ttl);
+try {
+  rs.cleanNotificationEvents(ttl);
+} catch (Exception ex) {
+  //catching exceptions here makes sure that the thread doesn't die in 
case of unexpected
+  //exceptions
+  LOG.warn(
+  "Exception received while cleaning notifications. More details 
can be found in debug mode"
+  + ex.getMessage());
+  LOG.debug(ex.getMessage(), ex);
+}
+
 LOG.debug("Cleaner thread done");
 try {
   Thread.sleep(sleepTime);

http://git-wip-us.apache.org/repos/asf/hive/blob/8b3ce468/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
--
diff --git 
a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
 
b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
index 9871083..1099480 100644
--- 
a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
+++ 
b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
@@ -836,6 +836,10 @@ public class DummyRawStoreFailEvent implements RawStore, 
Configurable {
 
   @Override
   public void cleanNotificationEvents(int olderThan) {
+if (!shouldEventSucceed) {
+  //throw exception to simulate an issue with cleaner thread
+  throw new RuntimeException("Dummy exception while cleaning 
notifications");
+}
 

hive git commit: HIVE-19050 : DBNotificationListener does not catch exceptions in the cleaner thread (Vihang Karajgaonkar reviewed by Peter Vary)

2018-04-06 Thread vihangk1
Repository: hive
Updated Branches:
  refs/heads/master 0a81e1ec3 -> d81aed31d


HIVE-19050 : DBNotificationListener does not catch exceptions in the cleaner 
thread (Vihang Karajgaonkar reviewed by Peter Vary)


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

Branch: refs/heads/master
Commit: d81aed31dec95d54711084264c7a3222a20e5530
Parents: 0a81e1e
Author: Vihang Karajgaonkar 
Authored: Fri Apr 6 10:02:33 2018 -0700
Committer: Vihang Karajgaonkar 
Committed: Fri Apr 6 10:02:33 2018 -0700

--
 .../listener/DbNotificationListener.java| 19 ++---
 .../listener/DummyRawStoreFailEvent.java|  4 +++
 .../listener/TestDbNotificationListener.java| 30 +++-
 3 files changed, 48 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hive/blob/d81aed31/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
--
diff --git 
a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
 
b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
index 9480145..7f21573 100644
--- 
a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
+++ 
b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
@@ -104,7 +104,8 @@ public class DbNotificationListener extends 
TransactionalMetaStoreEventListener
   private Configuration conf;
   private MessageFactory msgFactory;
 
-  private synchronized void init(Configuration conf) throws MetaException {
+  //cleaner is a static object, use static synchronized to make sure its 
thread-safe
+  private static synchronized void init(Configuration conf) throws 
MetaException {
 if (cleaner == null) {
   cleaner =
   new CleanerThread(conf, RawStoreProxy.getProxy(conf, conf,
@@ -116,7 +117,7 @@ public class DbNotificationListener extends 
TransactionalMetaStoreEventListener
   public DbNotificationListener(Configuration config) throws MetaException {
 super(config);
 conf = config;
-init(conf);
+DbNotificationListener.init(conf);
 msgFactory = MessageFactory.getInstance();
   }
 
@@ -724,7 +725,7 @@ public class DbNotificationListener extends 
TransactionalMetaStoreEventListener
 static private long sleepTime = 6;
 
 CleanerThread(Configuration conf, RawStore rs) {
-  super("CleanerThread");
+  super("DB-Notification-Cleaner");
   this.rs = rs;
   setTimeToLive(MetastoreConf.getTimeVar(conf, 
ConfVars.EVENT_DB_LISTENER_TTL,
   TimeUnit.SECONDS));
@@ -734,7 +735,17 @@ public class DbNotificationListener extends 
TransactionalMetaStoreEventListener
 @Override
 public void run() {
   while (true) {
-rs.cleanNotificationEvents(ttl);
+try {
+  rs.cleanNotificationEvents(ttl);
+} catch (Exception ex) {
+  //catching exceptions here makes sure that the thread doesn't die in 
case of unexpected
+  //exceptions
+  LOG.warn(
+  "Exception received while cleaning notifications. More details 
can be found in debug mode"
+  + ex.getMessage());
+  LOG.debug(ex.getMessage(), ex);
+}
+
 LOG.debug("Cleaner thread done");
 try {
   Thread.sleep(sleepTime);

http://git-wip-us.apache.org/repos/asf/hive/blob/d81aed31/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
--
diff --git 
a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
 
b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
index 4697f60..801de7a 100644
--- 
a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
+++ 
b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java
@@ -853,6 +853,10 @@ public class DummyRawStoreFailEvent implements RawStore, 
Configurable {
 
   @Override
   public void cleanNotificationEvents(int olderThan) {
+if (!shouldEventSucceed) {
+  //throw exception to simulate an issue with cleaner thread
+  throw new RuntimeException("Dummy exception while cleaning 
notifications");
+}
 objectStore.cleanNotificationEvents(olderThan);
   }