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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java:
##########
@@ -1001,38 +261,22 @@ public void removeDuplicateCompletedTxnComponents() 
throws MetaException {
   @RetrySemantics.SafeToRetry
   public void cleanEmptyAbortedAndCommittedTxns() throws MetaException {
     LOG.info("Start to clean empty aborted or committed TXNS");
-    try {
-      try (Connection dbConn = 
getDbConn(Connection.TRANSACTION_READ_COMMITTED, connPoolCompaction)) {
-        try (PreparedStatement stmt = 
dbConn.prepareStatement(DELETE_FAILED_TXNS_SQL)) {
-          //Aborted and committed are terminal states, so nothing about the 
txn can change
-          //after that, so READ COMMITTED is sufficient.
-          /*
-           * Only delete aborted / committed transaction in a way that 
guarantees two things:
-           * 1. never deletes anything that is inside the TXN_OPENTXN_TIMEOUT 
window
-           * 2. never deletes the maximum txnId even if it is before the 
TXN_OPENTXN_TIMEOUT window
-           */
-          long lowWaterMark = getOpenTxnTimeoutLowBoundaryTxnId(dbConn);
-          stmt.setLong(1, lowWaterMark);
-          LOG.debug("Going to execute query <{}>", DELETE_FAILED_TXNS_SQL);
-          int rc = stmt.executeUpdate();
-          LOG.debug("Removed {} empty Aborted and Committed transactions from 
TXNS", rc);
-          LOG.debug("Going to commit");
-          dbConn.commit();
-        } catch (SQLException e) {
-          LOG.error("Unable to delete from txns table " + e.getMessage());
-          LOG.debug("Going to rollback");
-          rollbackDBConn(dbConn);
-          checkRetryable(e, "cleanEmptyAbortedTxns");
-          throw new MetaException("Unable to delete from txns table " + 
e.getMessage());
-        }
-      } catch (SQLException e) {
-        LOG.error(DB_FAILED_TO_CONNECT + e.getMessage());
-        checkRetryable(e, "cleanEmptyAbortedTxns");
-        throw new MetaException(DB_FAILED_TO_CONNECT + e.getMessage());
-      }
-    } catch (RetryException e) {
-      cleanEmptyAbortedAndCommittedTxns();
-    }
+    //Aborted and committed are terminal states, so nothing about the txn can 
change
+    //after that, so READ COMMITTED is sufficient.
+    /*
+     * Only delete aborted / committed transaction in a way that guarantees 
two things:
+     * 1. never deletes anything that is inside the TXN_OPENTXN_TIMEOUT window
+     * 2. never deletes the maximum txnId even if it is before the 
TXN_OPENTXN_TIMEOUT window
+     */
+    long lowWaterMark = getOpenTxnTimeoutLowBoundaryTxnId();
+    String query = "DELETE FROM \"TXNS\" WHERE \"TXN_ID\" NOT IN (SELECT 
\"TC_TXNID\" FROM \"TXN_COMPONENTS\") " +

Review Comment:
   I tried to keep the queries inside the QueryHandler or inside the TxnHandler 
method if there is no separate QueryHandler implementation. Te reason is simply 
to keep the query as close as possible to the code where it is used. I think it 
improves readability. However, I'm not strictly tied to it. Should I revert 
this part and use constants instead?



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