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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java:
##########
@@ -873,61 +878,35 @@ public void removeDuplicateCompletedTxnComponents() 
throws MetaException {
   public void cleanEmptyAbortedAndCommittedTxns() throws MetaException {
     LOG.info("Start to clean empty aborted or committed TXNS");
     try {
-      Connection dbConn = null;
-      Statement stmt = null;
-      ResultSet rs = null;
-      try {
-        //Aborted and committed are terminal states, so nothing about the txn 
can change
-        //after that, so READ COMMITTED is sufficient.
-        dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED, 
connPoolCompaction);
-        stmt = dbConn.createStatement();
-        /*
-         * 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);
-
-        String s = "SELECT \"TXN_ID\" FROM \"TXNS\" WHERE " +
-            "\"TXN_ID\" NOT IN (SELECT \"TC_TXNID\" FROM \"TXN_COMPONENTS\") 
AND " +
-            " (\"TXN_STATE\" = " + TxnStatus.ABORTED + " OR \"TXN_STATE\" = " 
+ TxnStatus.COMMITTED + ")  AND "
-            + " \"TXN_ID\" < " + lowWaterMark;
-        LOG.debug("Going to execute query <{}>", s);
-        rs = stmt.executeQuery(s);
-        List<Long> txnids = new ArrayList<>();
-        while (rs.next()) txnids.add(rs.getLong(1));
-        close(rs);
-        if(txnids.size() <= 0) {
-          return;
-        }
-        Collections.sort(txnids);//easier to read logs
-
-        List<String> queries = new ArrayList<>();
-        StringBuilder prefix = new StringBuilder();
-        StringBuilder suffix = new StringBuilder();
-
-        // Delete from TXNS.
-        prefix.append("DELETE FROM \"TXNS\" WHERE ");
-
-        TxnUtils.buildQueryWithINClause(conf, queries, prefix, suffix, txnids, 
"\"TXN_ID\"", false, false);
-
-        for (String query : queries) {
-          LOG.debug("Going to execute update <{}>", query);
-          int rc = stmt.executeUpdate(query);
+      try (Connection dbConn = 
getDbConn(Connection.TRANSACTION_READ_COMMITTED, connPoolCompaction)) {
+        try (PreparedStatement stmt = 
dbConn.prepareStatement(DELETE_FAILED_TXNS_DIRECTLY_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_DIRECTLY_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");

Review Comment:
   what's the purpose of this log?



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