harshal-16 commented on code in PR #5841:
URL: https://github.com/apache/hive/pull/5841#discussion_r2189120955


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java:
##########
@@ -513,23 +516,53 @@ public long getTargetTxnId(String replPolicy, long 
sourceTxnId) throws MetaExcep
 
   @Override
   public void abortTxn(AbortTxnRequest rqst) throws NoSuchTxnException, 
MetaException, TxnAbortedException {
+    List<TxnWriteDetails> txnWriteDetails = new ArrayList<>();
+    if (transactionalListeners != null) {
+      //Find the write details for this transaction.
+      //Doing it here before the metadata tables are updated below.
+      txnWriteDetails = getWriteIdsForTxnID(rqst.getTxnid());
+    }
     TxnType txnType = new AbortTxnFunction(rqst).execute(jdbcResource); 
     if (txnType != null) {
       if (transactionalListeners != null && (!rqst.isSetReplPolicy() || 
!TxnType.DEFAULT.equals(rqst.getTxn_type()))) {
-        List<String> dbsUpdated = getTxnDbsUpdated(rqst.getTxnid());
-        
MetaStoreListenerNotifier.notifyEventWithDirectSql(transactionalListeners, 
EventMessage.EventType.ABORT_TXN,
-            new AbortTxnEvent(rqst.getTxnid(), txnType, null, dbsUpdated), 
jdbcResource.getConnection(), sqlGenerator);
+        
notifyCommitOrAbortEvent(rqst.getTxnid(),EventMessage.EventType.ABORT_TXN, 
txnType, jdbcResource.getConnection(), txnWriteDetails, transactionalListeners);
       }
     }
   }
 
+  public static void notifyCommitOrAbortEvent(long txnId, 
EventMessage.EventType eventType, TxnType txnType, Connection dbConn,
+                                       List<TxnWriteDetails> txnWriteDetails, 
List<TransactionalMetaStoreEventListener> transactionalListeners) throws 
MetaException {
+    List<Long> writeIds = txnWriteDetails.stream()
+            .map(TxnWriteDetails::getWriteId)
+            .collect(Collectors.toList());
+    List<String> databases = txnWriteDetails.stream()
+            .map(TxnWriteDetails::getDbName)
+            .collect(Collectors.toList());
+    ListenerEvent txnEvent;
+    if (eventType.equals(EventMessage.EventType.ABORT_TXN)) {
+      txnEvent = new AbortTxnEvent(txnId, txnType, null, databases, writeIds);
+    } else {
+      txnEvent = new CommitTxnEvent(txnId, txnType, null, databases, writeIds);
+    }
+    MetaStoreListenerNotifier.notifyEventWithDirectSql(transactionalListeners,
+            eventType, txnEvent, dbConn, sqlGenerator);
+  }
+
+
   @Override
   public void abortTxns(AbortTxnsRequest rqst) throws MetaException {
     List<Long> txnIds = rqst.getTxn_ids();
     TxnErrorMsg txnErrorMsg = TxnErrorMsg.NONE;
     if (rqst.isSetErrorCode()) {
       txnErrorMsg = TxnErrorMsg.getTxnErrorMsg(rqst.getErrorCode());
     }
+    HashMap<Long, List<TxnWriteDetails>> txnWriteDetailsMap = new HashMap<>();
+    if (transactionalListeners != null) {
+      //Find the write details for this transaction.
+      //Doing it here before the metadata tables are updated below.
+      for(Long txnId : txnIds)

Review Comment:
   ACK



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to