This is an automated email from the ASF dual-hosted git repository.

zhangchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 14fe7644702 [fix](txn insert) fix txn_insert case (#42327)
14fe7644702 is described below

commit 14fe7644702297e7f04ba29f4c83ec9740403386
Author: meiyi <myime...@gmail.com>
AuthorDate: Thu Oct 24 17:36:32 2024 +0800

    [fix](txn insert) fix txn_insert case (#42327)
    
    when connect to observer, if the first load sql throw exception before
    execute(such as unpected label), the txn is not began
---
 .../apache/doris/transaction/TransactionEntry.java | 36 ++++++++++++++--------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/transaction/TransactionEntry.java 
b/fe/fe-core/src/main/java/org/apache/doris/transaction/TransactionEntry.java
index c9e2ff522ff..fcab55866ed 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/transaction/TransactionEntry.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/transaction/TransactionEntry.java
@@ -460,12 +460,14 @@ public class TransactionEntry {
             Preconditions.checkState(subTransactionStates.isEmpty(),
                     "subTxnStates is not empty: " + subTransactionStates);
             resetByTxnInfo(txnLoadInfo);
-            this.transactionState = 
Env.getCurrentGlobalTransactionMgr().getTransactionState(dbId, transactionId);
-            Preconditions.checkNotNull(this.transactionState,
-                    "db_id" + dbId + " txn_id=" + transactionId + " not 
found");
-            
Preconditions.checkState(this.label.equals(this.transactionState.getLabel()), 
"expected label="
-                    + this.label + ", real label=" + 
this.transactionState.getLabel());
-            this.isTransactionBegan = true;
+            if (this.transactionId > 0) {
+                this.transactionState = 
Env.getCurrentGlobalTransactionMgr().getTransactionState(dbId, transactionId);
+                Preconditions.checkNotNull(this.transactionState,
+                        "db_id=" + dbId + ", txn_id=" + transactionId + " not 
found");
+                
Preconditions.checkState(this.label.equals(this.transactionState.getLabel()), 
"expected label="
+                        + this.label + ", real label=" + 
this.transactionState.getLabel());
+                this.isTransactionBegan = true;
+            }
         }
         LOG.info("set txn info in master, label={}, txnId={}, dbId={}, 
timeoutTimestamp={}, allSubTxnNum={}, "
                 + "subTxnStates={}", label, transactionId, dbId, 
timeoutTimestamp, allSubTxnNum, subTransactionStates);
@@ -492,17 +494,27 @@ public class TransactionEntry {
                 "expected label=" + this.label + ", real label=" + 
txnLoadInfo.getLabel());
         subTransactionStates.clear();
         resetByTxnInfo(txnLoadInfo);
-        this.isTransactionBegan = true;
+        if (this.transactionId > 0) {
+            this.isTransactionBegan = true;
+        }
         LOG.info("set txn load info in observer, label={}, txnId={}, dbId={}, 
timeoutTimestamp={}, allSubTxnNum={}, "
                 + "subTxnStates={}", label, transactionId, dbId, 
timeoutTimestamp, allSubTxnNum, subTransactionStates);
     }
 
     private void resetByTxnInfo(TTxnLoadInfo txnLoadInfo) throws DdlException {
-        this.dbId = txnLoadInfo.getDbId();
-        this.database = 
Env.getCurrentInternalCatalog().getDbOrDdlException(dbId);
-        this.transactionId = txnLoadInfo.getTxnId();
-        this.timeoutTimestamp = txnLoadInfo.getTimeoutTimestamp();
-        this.allSubTxnNum = txnLoadInfo.getAllSubTxnNum();
+        if (txnLoadInfo.isSetDbId()) {
+            this.dbId = txnLoadInfo.getDbId();
+            this.database = 
Env.getCurrentInternalCatalog().getDbOrDdlException(dbId);
+        }
+        if (txnLoadInfo.isSetTxnId()) {
+            this.transactionId = txnLoadInfo.getTxnId();
+        }
+        if (txnLoadInfo.isSetTimeoutTimestamp()) {
+            this.timeoutTimestamp = txnLoadInfo.getTimeoutTimestamp();
+        }
+        if (txnLoadInfo.isSetAllSubTxnNum()) {
+            this.allSubTxnNum = txnLoadInfo.getAllSubTxnNum();
+        }
         if (txnLoadInfo.isSetSubTxnInfos()) {
             for (TSubTxnInfo subTxnInfo : txnLoadInfo.getSubTxnInfos()) {
                 TableIf table = 
database.getTableOrDdlException(subTxnInfo.getTableId());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to