Skip to content

Commit

Permalink
[improve](cloud-mow) print the queue length of committing txn on FE
Browse files Browse the repository at this point in the history
  • Loading branch information
hust-hhb committed Sep 11, 2024
1 parent b7e8d82 commit 0cbe9fd
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class CloudGlobalTransactionMgr implements GlobalTransactionMgrIface {
Expand All @@ -150,6 +151,7 @@ public class CloudGlobalTransactionMgr implements GlobalTransactionMgrIface {

private TxnStateCallbackFactory callbackFactory;
private final Map<Long, Long> subTxnIdToTxnId = new ConcurrentHashMap<>();
private Map<Long, AtomicInteger> countMap = new ConcurrentHashMap<>();

public CloudGlobalTransactionMgr() {
this.callbackFactory = new TxnStateCallbackFactory();
Expand Down Expand Up @@ -959,7 +961,19 @@ public boolean commitAndPublishTransaction(DatabaseIf db, long transactionId,
public boolean commitAndPublishTransaction(DatabaseIf db, List<Table> tableList, long transactionId,
List<TabletCommitInfo> tabletCommitInfos, long timeoutMillis,
TxnCommitAttachment txnCommitAttachment) throws UserException {
for (int i = 0; i < tableList.size(); i++) {
long tableId = tableList.get(i).getId();
LOG.info("start commit txn=" + transactionId + ",table=" + tableId);
}
for (Map.Entry<Long, AtomicInteger> entry : countMap.entrySet()) {
if (entry.getValue().get() > 5) {
LOG.info("now table {} commitAndPublishTransaction queue is {}", entry.getKey(),
entry.getValue().get());
}
}
increaseCount(tableList);
if (!MetaLockUtils.tryCommitLockTables(tableList, timeoutMillis, TimeUnit.MILLISECONDS)) {
decreaseCount(tableList);
// DELETE_BITMAP_LOCK_ERR will be retried on be
throw new UserException(InternalErrorCode.DELETE_BITMAP_LOCK_ERR,
"get table cloud commit lock timeout, tableList=("
Expand All @@ -968,6 +982,7 @@ public boolean commitAndPublishTransaction(DatabaseIf db, List<Table> tableList,
try {
commitTransaction(db.getId(), tableList, transactionId, tabletCommitInfos, txnCommitAttachment);
} finally {
decreaseCount(tableList);
MetaLockUtils.commitUnlockTables(tableList);
}
return true;
Expand Down Expand Up @@ -1721,4 +1736,23 @@ public TransactionState abortSubTxn(long txnId, long subTxnId, long dbId, Set<Lo
}
return TxnUtil.transactionStateFromPb(response.getTxnInfo());
}

private void increaseCount(List<Table> tableList) {
for (int i = 0; i < tableList.size(); i++) {
long tableId = tableList.get(i).getId();
if (countMap.containsKey(tableId)) {
countMap.get(tableId).addAndGet(1);
} else {
countMap.put(tableId, new AtomicInteger());
countMap.get(tableId).addAndGet(1);
}
}
}

private void decreaseCount(List<Table> tableList) {
for (int i = 0; i < tableList.size(); i++) {
long tableId = tableList.get(i).getId();
countMap.get(tableId).decrementAndGet();
}
}
}

0 comments on commit 0cbe9fd

Please sign in to comment.