Repository: hive
Updated Branches:
  refs/heads/branch-2.3 d3fa8e0c5 -> f78128a71


HIVE-18783: ALTER TABLE post-commit listener does not include the transactional 
listener responses (Sergio Pena, reviewed by Vihang Karajgaonkar)


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

Branch: refs/heads/branch-2.3
Commit: f78128a719772c1157ce6f0b9bce52a0cac0893c
Parents: d3fa8e0
Author: Sergio Pena <sergio.p...@cloudera.com>
Authored: Mon Apr 9 10:26:10 2018 -0500
Committer: Sergio Pena <sergio.p...@cloudera.com>
Committed: Mon Apr 9 11:05:50 2018 -0500

----------------------------------------------------------------------
 .../hcatalog/listener/TestDbNotificationListener.java |  1 +
 .../hadoop/hive/metastore/HiveAlterHandler.java       | 14 +++++++++++++-
 .../apache/hadoop/hive/metastore/HiveMetaStore.java   | 10 ++++------
 3 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/f78128a7/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java
----------------------------------------------------------------------
diff --git 
a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java
 
b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java
index 976c3c5..786c4c2 100644
--- 
a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java
+++ 
b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java
@@ -444,6 +444,7 @@ public class TestDbNotificationListener {
     assertEquals(table, alterTableMessage.getTableObjAfter());
 
     // Verify the eventID was passed to the non-transactional listener
+    MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.ALTER_TABLE, 
firstEventId + 2);
     MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_TABLE, 
firstEventId + 1);
 
     // When hive.metastore.transactional.event.listeners is set,

http://git-wip-us.apache.org/repos/asf/hive/blob/f78128a7/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
index 15f2597..7730a24 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
@@ -54,8 +54,10 @@ import org.apache.hive.common.util.HiveStringUtils;
 import java.io.IOException;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Hive specific implementation of alter
@@ -115,8 +117,12 @@ public class HiveAlterHandler implements AlterHandler {
     boolean rename = false;
     Table oldt = null;
     List<MetaStoreEventListener> transactionalListeners = null;
+    List<MetaStoreEventListener> listeners = null;
+    Map<String, String> txnAlterTableEventResponses = Collections.emptyMap();
+
     if (handler != null) {
       transactionalListeners = handler.getTransactionalListeners();
+      listeners = handler.getListeners();
     }
 
     try {
@@ -270,7 +276,7 @@ public class HiveAlterHandler implements AlterHandler {
 
       alterTableUpdateTableColumnStats(msdb, oldt, newt);
       if (transactionalListeners != null && !transactionalListeners.isEmpty()) 
{
-        MetaStoreListenerNotifier.notifyEvent(transactionalListeners,
+        txnAlterTableEventResponses = 
MetaStoreListenerNotifier.notifyEvent(transactionalListeners,
                                               
EventMessage.EventType.ALTER_TABLE,
                                               new AlterTableEvent(oldt, newt, 
true, handler),
                                               environmentContext);
@@ -305,6 +311,12 @@ public class HiveAlterHandler implements AlterHandler {
           }
         }
       }
+
+      if (!listeners.isEmpty()) {
+        MetaStoreListenerNotifier.notifyEvent(listeners, 
EventMessage.EventType.ALTER_TABLE,
+            new AlterTableEvent(oldt, newt, success, handler),
+            environmentContext, txnAlterTableEventResponses, msdb);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/f78128a7/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 befd15e..d799acf 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -406,6 +406,10 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       return transactionalListeners;
     }
 
+    public List<MetaStoreEventListener> getListeners() {
+      return listeners;
+    }
+
     @Override
     public void init() throws MetaException {
       initListeners = MetaStoreUtils.getMetaStoreListeners(
@@ -3998,12 +4002,6 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         alterHandler.alterTable(getMS(), wh, dbname, name, newTable,
                 envContext, this);
         success = true;
-        if (!listeners.isEmpty()) {
-          MetaStoreListenerNotifier.notifyEvent(listeners,
-                                                EventType.ALTER_TABLE,
-                                                new AlterTableEvent(oldt, 
newTable, true, this),
-                                                envContext);
-        }
       } catch (NoSuchObjectException e) {
         // thrown when the table to be altered does not exist
         ex = e;

Reply via email to