yujun777 commented on code in PR #71199:
URL: https://github.com/apache/doris/pull/71199#discussion_r4784552558


##########
fe/fe-core/src/main/java/org/apache/doris/transaction/DatabaseTransactionMgr.java:
##########
@@ -1950,6 +1965,57 @@ protected void 
unprotectUpdateInMemoryState(TransactionState transactionState, b
         if (isReplay) {
             updateTxnLabels(transactionState);
         }
+        updateCommittedTableIndex(transactionState);
+    }
+
+    private void updateCommittedTableIndex(TransactionState transactionState) {
+        long txnId = transactionState.getTransactionId();
+        Set<Long> prevTableIds = committedTableIdsByTxn.remove(txnId);
+        if (prevTableIds != null) {
+            for (Long tableId : prevTableIds) {
+                Set<Long> txnIds = committedTxnIdsByTable.get(tableId);
+                if (txnIds != null) {
+                    txnIds.remove(txnId);
+                    if (txnIds.isEmpty()) {
+                        committedTxnIdsByTable.remove(tableId);
+                    }
+                }
+            }
+        }
+        if (transactionState.getTransactionStatus() != 
TransactionStatus.COMMITTED) {
+            return;
+        }
+        Set<Long> tableIds = collectCommittedTableIds(transactionState);
+        if (tableIds.isEmpty()) {
+            return;
+        }
+        committedTableIdsByTxn.put(txnId, tableIds);
+        for (Long tableId : tableIds) {
+            committedTxnIdsByTable.computeIfAbsent(tableId, k -> new 
HashSet<>()).add(txnId);

Review Comment:
   Fixed in 57868d8f774. Protected all reads (hasCommittedTxnForTable) and 
writes (updateCommittedTableIndex) of committedTxnIdsByTable / 
committedTableIdsByTxn with a dedicated leaf lock (committedTableIndexLock) so 
concurrent commitTransaction()/finishTransaction() calls on different tables in 
the same DB can never race on the shared maps. Added an 8-thread concurrent 
commit/publish/read unit test in DatabaseTransactionMgrTest.



##########
fe/fe-core/src/main/java/org/apache/doris/tso/TSOTransactionTracker.java:
##########
@@ -146,6 +146,57 @@ long candidateCommittedTso(long currentTso, long 
durableCommittedTso) {
         return candidate;
     }
 
+    Map<Pair<Long, Long>, Long> liveCommittedTsos(long currentTso, 
Collection<Pair<Long, Long>> dbTablePairs) {
+        Preconditions.checkState(lock.isHeldByCurrentThread());
+        if (dbTablePairs.isEmpty()) {
+            return Collections.emptyMap();
+        }
+        Map<Pair<Long, Long>, Long> result = new HashMap<>(dbTablePairs.size() 
* 2);
+        if (pendingByTso.isEmpty()) {
+            for (Pair<Long, Long> pair : dbTablePairs) {
+                result.put(pair, currentTso);
+            }
+            return result;
+        }
+        Map<Long, Set<Long>> remainingByDb = new HashMap<>();
+        for (Pair<Long, Long> pair : dbTablePairs) {
+            remainingByDb.computeIfAbsent(pair.first, k -> new 
HashSet<>()).add(pair.second);
+        }
+        for (PendingTransaction pending : pendingByTso.values()) {
+            if (pending.tso > currentTso || remainingByDb.isEmpty()) {
+                break;
+            }
+            Set<Long> tables = remainingByDb.get(pending.identity.first);
+            if (tables == null) {
+                continue;
+            }
+            long boundTso = pending.tso - 1;
+            List<Long> matched = null;
+            for (Long tableId : tables) {

Review Comment:
   Fixed in 57868d8f774. Maintained a per-(dbId, tableId) TreeSet<Long> index 
(pendingTsosByTable) inside TSOTransactionTracker (updated in register, 
replaceFenced, remove, and reset), making liveCommittedTsos() O(|requested 
tables|) instead of O(pending * requested). Extended TSOTransactionTrackerTest 
with repeated registration, reset, and a 1,000-txn unrelated pending set.



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