deniskuzZ commented on a change in pull request #1592:
URL: https://github.com/apache/hive/pull/1592#discussion_r514992535



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java
##########
@@ -1122,43 +1129,18 @@ public void setHadoopJobId(String hadoopJobId, long id) 
{
   @RetrySemantics.Idempotent
   public long findMinOpenTxnIdForCleaner() throws MetaException{
     Connection dbConn = null;
-    Statement stmt = null;
-    ResultSet rs = null;
     try {
       try {
         dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
-        stmt = dbConn.createStatement();
-        String query = "SELECT COUNT(\"TXN_ID\") FROM \"TXNS\" WHERE 
\"TXN_STATE\" = " + TxnStatus.OPEN;
-        LOG.debug("Going to execute query <" + query + ">");
-        rs = stmt.executeQuery(query);
-        if (!rs.next()) {
-          throw new MetaException("Transaction tables not properly 
initialized.");
-        }
-        long numOpenTxns = rs.getLong(1);
-        if (numOpenTxns > 0) {
-          query = "SELECT MIN(\"RES\".\"ID\") FROM (" +
-              "SELECT MIN(\"TXN_ID\") AS \"ID\" FROM \"TXNS\" WHERE 
\"TXN_STATE\" = " + TxnStatus.OPEN +
-              " UNION " +
-              "SELECT MAX(\"CQ_NEXT_TXN_ID\") AS \"ID\" FROM 
\"COMPACTION_QUEUE\" WHERE \"CQ_STATE\" = "
-              + quoteChar(READY_FOR_CLEANING) +
-              ") \"RES\"";
-        } else {
-          query = "SELECT MAX(\"TXN_ID\") + 1 FROM \"TXNS\"";
-        }
-        LOG.debug("Going to execute query <" + query + ">");
-        rs = stmt.executeQuery(query);
-        if (!rs.next()) {
-          throw new MetaException("Transaction tables not properly 
initialized, no record found in TXNS");
-        }
-        return rs.getLong(1);
+        return getMinOpenTxnIdWaterMark(dbConn);

Review comment:
       What happens if TXNS table is empty?




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

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