Repository: hive Updated Branches: refs/heads/branch-2 32055ca4e -> 5842fd2f1
Revert "HIVE-18885 : DbNotificationListener has a deadlock between Java and DB locks" This reverts commit d32adf51603dd23fe5727b4f1799199bf0e78104. The change was merged by mistake without being reviewed. Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/5842fd2f Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/5842fd2f Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/5842fd2f Branch: refs/heads/branch-2 Commit: 5842fd2f19f76691f6762b23d2b1a34b430e572c Parents: 32055ca Author: Vihang Karajgaonkar <vih...@cloudera.com> Authored: Fri Mar 23 16:56:23 2018 -0700 Committer: Vihang Karajgaonkar <vih...@cloudera.com> Committed: Fri Mar 23 16:57:07 2018 -0700 ---------------------------------------------------------------------- .../listener/DbNotificationListener.java | 29 ++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/5842fd2f/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 1989a5e..41347c2 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 @@ -83,6 +83,8 @@ public class DbNotificationListener extends MetaStoreEventListener { private static final Logger LOG = LoggerFactory.getLogger(DbNotificationListener.class.getName()); private static CleanerThread cleaner = null; + private static final Object NOTIFICATION_TBL_LOCK = new Object(); + // This is the same object as super.conf, but it's convenient to keep a copy of it as a // HiveConf rather than a Configuration. private HiveConf hiveConf; @@ -477,14 +479,18 @@ public class DbNotificationListener extends MetaStoreEventListener { */ private void process(NotificationEvent event, ListenerEvent listenerEvent) throws MetaException { event.setMessageFormat(msgFactory.getMessageFormat()); - LOG.debug("DbNotificationListener: Processing : {}:{}", event.getEventId(), event.getMessage()); - HMSHandler.getMSForConf(hiveConf).addNotificationEvent(event); - - // Set the DB_NOTIFICATION_EVENT_ID for future reference by other listeners. - if (event.isSetEventId()) { - listenerEvent.putParameter(MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME, - Long.toString(event.getEventId())); + synchronized (NOTIFICATION_TBL_LOCK) { + LOG.debug("DbNotificationListener: Processing : {}:{}", event.getEventId(), + event.getMessage()); + HMSHandler.getMSForConf(hiveConf).addNotificationEvent(event); } + + // Set the DB_NOTIFICATION_EVENT_ID for future reference by other listeners. + if (event.isSetEventId()) { + listenerEvent.putParameter( + MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME, + Long.toString(event.getEventId())); + } } private static class CleanerThread extends Thread { @@ -503,13 +509,8 @@ public class DbNotificationListener extends MetaStoreEventListener { @Override public void run() { while (true) { - synchronized (this) { - try { - rs.cleanNotificationEvents(ttl); - } catch (Exception ex) { - //catch exceptions so that this thread doesn't die - LOG.debug("Exception caught while cleaning notifications", ex); - } + synchronized(NOTIFICATION_TBL_LOCK) { + rs.cleanNotificationEvents(ttl); } LOG.debug("Cleaner thread done"); try {