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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 4014c62f96518a34b71822b7c5be89afd8bdfbf8
Author: Mingyu Chen <morning...@163.com>
AuthorDate: Sun Mar 12 22:12:07 2023 +0800

    [fix](meta) fix concurrent modification exception and potential NPE (#17602)
---
 .../java/org/apache/doris/analysis/DescriptorTable.java | 12 ++++++------
 .../apache/doris/transaction/GlobalTransactionMgr.java  | 17 +++++++++++++++--
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/DescriptorTable.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DescriptorTable.java
index 7c1b62dcc5..c069337772 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DescriptorTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DescriptorTable.java
@@ -27,14 +27,12 @@ import org.apache.doris.thrift.TDescriptorTable;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -181,7 +179,7 @@ public class DescriptorTable {
 
     public TDescriptorTable toThrift() {
         TDescriptorTable result = new TDescriptorTable();
-        HashSet<TableIf> referencedTbls = Sets.newHashSet();
+        Map<Long, TableIf> referencedTbls = Maps.newHashMap();
         for (TupleDescriptor tupleD : tupleDescs.values()) {
             // inline view of a non-constant select has a non-materialized 
tuple descriptor
             // in the descriptor table just for type checking, which we need 
to skip
@@ -191,7 +189,7 @@ public class DescriptorTable {
                 // but its table has no id
                 if (tupleD.getTable() != null
                         && tupleD.getTable().getId() >= 0) {
-                    referencedTbls.add(tupleD.getTable());
+                    referencedTbls.put(tupleD.getTable().getId(), 
tupleD.getTable());
                 }
                 for (SlotDescriptor slotD : tupleD.getMaterializedSlots()) {
                     result.addToSlotDescriptors(slotD.toThrift());
@@ -199,9 +197,11 @@ public class DescriptorTable {
             }
         }
 
-        referencedTbls.addAll(referencedTables);
+        for (TableIf tbl : referencedTables) {
+            referencedTbls.put(tbl.getId(), tbl);
+        }
 
-        for (TableIf tbl : referencedTbls) {
+        for (TableIf tbl : referencedTbls.values()) {
             result.addToTableDescriptors(tbl.toThrift());
         }
         return result;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java
 
b/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java
index cb6c5e7c23..4621f08700 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java
@@ -335,11 +335,24 @@ public class GlobalTransactionMgr implements Writable {
             return !dbTransactionMgr.getCommittedTxnList().isEmpty();
         }
 
-        for (TransactionState transactionState : 
dbTransactionMgr.getCommittedTxnList()) {
+        List<TransactionState> committedTxnList = 
dbTransactionMgr.getCommittedTxnList();
+        for (TransactionState transactionState : committedTxnList) {
             if (transactionState.getTableIdList().contains(tableId)) {
                 if (partitionId == null) {
                     return true;
-                } else if 
(transactionState.getTableCommitInfo(tableId).getPartitionCommitInfo(partitionId)
 != null) {
+                }
+                TableCommitInfo tableCommitInfo = 
transactionState.getTableCommitInfo(tableId);
+                if (tableCommitInfo == null) {
+                    // FIXME: this is a bug, should not happen
+                    // If table id is in transaction state's table list, and 
it is COMMITTED,
+                    // table commit info should not be null.
+                    // return true to avoid following process.
+                    LOG.warn("unexpected error. tableCommitInfo is null. dbId: 
{} tableId: {}, partitionId: {},"
+                                    + " transactionState: {}",
+                            dbId, tableId, partitionId, transactionState);
+                    return true;
+                }
+                if (tableCommitInfo.getPartitionCommitInfo(partitionId) != 
null) {
                     return true;
                 }
             }


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

Reply via email to