veghlaci05 commented on code in PR #4384:
URL: https://github.com/apache/hive/pull/4384#discussion_r1310118399


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java:
##########
@@ -6397,51 +6458,44 @@ private AbortCompactionResponseElement 
getAbortCompactionResponseElement(long co
 
   @RetrySemantics.SafeToRetry
   public AbortCompactionResponseElement abortCompaction(CompactionInfo 
compactionInfo) throws MetaException {
-    try {
-      try (Connection dbConn = 
getDbConn(Connection.TRANSACTION_READ_COMMITTED, connPoolMutex);
-           PreparedStatement pStmt = 
dbConn.prepareStatement(TxnQueries.INSERT_INTO_COMPLETED_COMPACTION)) {
-        compactionInfo.state = TxnStore.ABORTED_STATE;
-        compactionInfo.errorMessage = "Comapction Aborted by Abort Comapction 
request.";
-        CompactionInfo.insertIntoCompletedCompactions(pStmt, compactionInfo, 
getDbTime(dbConn));
-        int updCount = pStmt.executeUpdate();
-        if (updCount != 1) {
-          LOG.error("Unable to update compaction record: {}. updCnt={}", 
compactionInfo, updCount);
-          dbConn.rollback();
-          return getAbortCompactionResponseElement(compactionInfo.id, "Error",
-                  "Error while aborting compaction:Unable to update compaction 
record in COMPLETED_COMPACTIONS");
-        } else {
+    return retryHandler.executeWithRetry(new RetryCallProperties()
+            .withCallerId("abortCompaction(" + compactionInfo + ")")
+            .withDataSource(POOL_TX),
+        (DataSourceWrapper dataSourceWrapper) -> {
+          compactionInfo.state = TxnStore.ABORTED_STATE;
+          compactionInfo.errorMessage = "Comapction Aborted by Abort 
Comapction request.";
+          int updCount;
+          try {
+            updCount = dataSourceWrapper.execute(new 
InsertCompactionInfoCommand(compactionInfo, getDbTime().getTime()));
+          } catch (Exception e) {
+            LOG.error("Unable to update compaction record: {}.", 
compactionInfo);
+            return getAbortCompactionResponseElement(compactionInfo.id, 
"Error",
+                "Error while aborting compaction:Unable to update compaction 
record in COMPLETED_COMPACTIONS");
+          }
+          TransactionStatus status = dataSourceWrapper.getTransactionStatus();
           LOG.debug("Inserted {} entries into COMPLETED_COMPACTIONS", 
updCount);
-          try (PreparedStatement stmt = dbConn.prepareStatement("DELETE FROM 
\"COMPACTION_QUEUE\" WHERE \"CQ_ID\" = ?")) {
-            stmt.setLong(1, compactionInfo.id);
-            LOG.debug("Going to execute update on COMPACTION_QUEUE ");
-            updCount = stmt.executeUpdate();
+          try {
+            updCount = dataSourceWrapper.getJdbcTemplate().update("DELETE FROM 
\"COMPACTION_QUEUE\" WHERE \"CQ_ID\" = :id",
+                new MapSqlParameterSource().addValue("id", compactionInfo.id));
+
             if (updCount != 1) {
               LOG.error("Unable to update compaction record: {}. updCnt={}", 
compactionInfo, updCount);
-              dbConn.rollback();
+              status.setRollbackOnly();

Review Comment:
   Valid point, replaced with jdbcTemplate.rollback() to be consistent with 
others



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to