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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java:
##########
@@ -4797,6 +4800,84 @@ private void heartbeatTxn(Connection dbConn, long txnid)
     }
   }
 
+  private boolean foundCommittedTransaction(Connection dbConn, long txnId, 
FindStatStatusByWriteIdRequest rqst,
+                                           String condition) throws 
SQLException, MetaException {
+    String s = sqlGenerator.addLimitClause(1,
+            "1 FROM \"COMPLETED_TXN_COMPONENTS\" WHERE \"CTC_TXNID\" " + 
condition + " " + txnId +
+                    " AND \"CTC_DATABASE\" = ? AND \"CTC_TABLE\" = ?");
+    if (rqst.getPartName() != null) {
+      s += " AND \"CTC_PARTITION\" = ?";
+    }
+
+    try (PreparedStatement pStmt =
+           sqlGenerator.prepareStmtWithParameters(dbConn, s,  
Arrays.asList(rqst.getDbName(), rqst.getTblName()))) {
+      if (rqst.getPartName() != null) {
+        pStmt.setString(3, rqst.getPartName());
+      }
+      LOG.debug("Going to execute query <" + s + ">");
+      try (ResultSet rs2 = pStmt.executeQuery()) {
+        if (rs2.next()) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
+  @Override
+  @RetrySemantics.Idempotent
+  public FindStatStatusByWriteIdResponse 
findStatStatusByWriteId(FindStatStatusByWriteIdRequest rqst)
+          throws SQLException, MetaException {
+    try {
+      Connection dbConn = null;
+      Statement stmt = null;
+      try {
+        lockInternal();
+        dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
+        stmt = dbConn.createStatement();
+        TxnState state;
+        long txnId = getTxnIdForWriteId(rqst.getDbName(), rqst.getTblName(), 
rqst.getWriteId());
+        TxnStatus txnStatus = findTxnState(txnId, stmt);
+        if (txnStatus == TxnStatus.ABORTED) {
+          state = TxnState.ABORTED;
+        } else if (txnStatus == TxnStatus.OPEN) {
+          state = TxnState.OPEN;
+        } else if (foundCommittedTransaction(dbConn, txnId, rqst, ">")) {

Review Comment:
   That's not entirely correct. Txn with higher txnId might be commited before 
txn with lower id. See how WRITE_SET table works. It has 2 properties WS_TXNID 
and WS_COMMIT_ID. This table only tracks update/delete operations, that are 
conflicting, insert doesn't belong to this category, so you cannot rely on it 
as well.



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