deniskuzZ commented on code in PR #4566:
URL: https://github.com/apache/hive/pull/4566#discussion_r1418834695


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TransactionalRetryProxy.java:
##########
@@ -108,23 +110,36 @@ public Object invoke(Object proxy, Method method, 
Object[] args) throws Throwabl
         TransactionContext context = null;
         try {
           jdbcResource.bindDataSource(transactional);
-          context = 
jdbcResource.getTransactionManager().getTransaction(transactional.propagation().value());
+          context = 
jdbcResource.getTransactionManager().getNewTransaction(transactional.propagation().value());
           Object result = toCall.execute();
           LOG.debug("Successfull method invocation within transactional 
context: {}, going to commit.", callerId);
-          jdbcResource.getTransactionManager().commit(context);
+          if (context.isRollbackOnly()) {
+            jdbcResource.getTransactionManager().rollback(context);
+          } else if (!context.isCompleted()) {
+            jdbcResource.getTransactionManager().commit(context);
+          }
           return result;
+        } catch (ProgrammaticRollbackException e) {
+          if (context != null && !context.isCompleted()) {
+            jdbcResource.getTransactionManager().rollback(context);
+          }          
+          return e.getResult();
         } catch (Exception e) {
-          if (Arrays.stream(transactional.noRollbackFor()).anyMatch(ex -> 
ex.isInstance(e)) ||
-              
Arrays.stream(transactional.noRollbackForClassName()).anyMatch(exName -> 
exName.equals(e.getClass().getName()))) {
-            throw e;
-          }
           if (context != null) {
-            if (transactional.rollbackFor().length > 0 || 
transactional.rollbackForClassName().length > 0) {
+            if (transactional.noRollbackFor().length > 0 || 
transactional.noRollbackForClassName().length > 0) {
+              if (Arrays.stream(transactional.noRollbackFor()).anyMatch(ex -> 
ex.isInstance(e)) ||
+                  
Arrays.stream(transactional.noRollbackForClassName()).anyMatch(exName -> 
exName.equals(e.getClass().getName()))) {
+                jdbcResource.getTransactionManager().commit(context);
+              } else {
+                jdbcResource.getTransactionManager().rollback(context);
+              }
+            } else if (transactional.rollbackFor().length > 0 || 
transactional.rollbackForClassName().length > 0) {

Review Comment:
   !! it's the same if predicate as above



-- 
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