Repository: hive
Updated Branches:
  refs/heads/branch-2 941f037c2 -> 7cea4d0da


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

Branch: refs/heads/branch-2
Commit: 7cea4d0da85b6f4a23fefb1ebb43c442b989c58d
Parents: 941f037
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 10:26:10 2018 -0500

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


http://git-wip-us.apache.org/repos/asf/hive/blob/7cea4d0d/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 5a40780..8e9eb3d 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
@@ -447,6 +447,7 @@ public class TestDbNotificationListener {
     assertEquals(TableType.MANAGED_TABLE.toString(), 
alterTableMessage.getTableType());
 
     // 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/7cea4d0d/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 3e7c59b..83c68a2 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
@@ -54,6 +54,7 @@ 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.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -126,8 +127,12 @@ public class HiveAlterHandler implements AlterHandler {
     boolean dataWasMoved = 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 {
@@ -309,7 +314,7 @@ public class HiveAlterHandler implements AlterHandler {
       }
 
       if (transactionalListeners != null && !transactionalListeners.isEmpty()) 
{
-        MetaStoreListenerNotifier.notifyEvent(transactionalListeners,
+        txnAlterTableEventResponses = 
MetaStoreListenerNotifier.notifyEvent(transactionalListeners,
                                               
EventMessage.EventType.ALTER_TABLE,
                                               new AlterTableEvent(oldt, newt, 
true, handler),
                                               environmentContext);
@@ -349,6 +354,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/7cea4d0d/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 d32e89c..aa233dd 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -407,6 +407,10 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       return transactionalListeners;
     }
 
+    public List<MetaStoreEventListener> getListeners() {
+      return listeners;
+    }
+
     @Override
     public void init() throws MetaException {
       initListeners = MetaStoreUtils.getMetaStoreListeners(
@@ -4021,12 +4025,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