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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/functions/CommitTxnFunction.java:
##########
@@ -581,23 +652,36 @@ private void 
updateWSCommitIdAndCleanUpMetadata(MultiDataSourceJdbcResource jdbc
     queryBatch.add("DELETE FROM \"HIVE_LOCKS\" WHERE \"HL_TXNID\" = " + txnid);
     // DO NOT remove the transaction from the TXN table, the cleaner will 
remove it when appropriate
     queryBatch.add("UPDATE \"TXNS\" SET \"TXN_STATE\" = " + 
TxnStatus.COMMITTED + " WHERE \"TXN_ID\" = " + txnid);
+
     if (txnType == TxnType.MATER_VIEW_REBUILD) {
       queryBatch.add("DELETE FROM \"MATERIALIZATION_REBUILD_LOCKS\" WHERE 
\"MRL_TXN_ID\" = " + txnid);
     }
+
     if (txnType == TxnType.SOFT_DELETE || 
MetaStoreServerUtils.isCompactionTxn(txnType)) {
-      queryBatch.add("UPDATE \"COMPACTION_QUEUE\" SET \"CQ_NEXT_TXN_ID\" = " + 
commitId + ", \"CQ_COMMIT_TIME\" = " +
-          getEpochFn(jdbcResource.getDatabaseProduct()) + " WHERE 
\"CQ_TXN_ID\" = " + txnid);
+      // For soft-delete and compaction transactions, we need to set the 
commit id
+      if (commitInfo.isEmpty() && !ConfVars.useMinHistoryWriteId()) {
+        // Take a global txn lock to synchronize the openTxn and commitTxn 
operations
+        new AcquireTxnLockFunction(false).execute(jdbcResource);
+      }
+      queryBatch.add("""
+          UPDATE "COMPACTION_QUEUE" SET "CQ_NEXT_TXN_ID" = %s, 
"CQ_COMMIT_TIME" = %s
+          WHERE "CQ_TXN_ID" = %d"""
+          .formatted(
+              defaultIfNull(commitInfo.commitId(), "(SELECT MAX(\"TXN_ID\") 
FROM \"TXNS\")"),

Review Comment:
   it was there before 
(https://github.com/apache/hive/pull/6290#discussion_r2841342870), we do it 
here to save on backend DB calls



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