[improve](transaction) lightweight transaction lock logic (#27564)

This commit is contained in:
HHoflittlefish777
2023-11-25 23:24:36 +08:00
committed by GitHub
parent d4f2db74f9
commit 7a1b4267d5

View File

@ -310,12 +310,13 @@ public class DatabaseTransactionMgr {
throws DuplicatedRequestException, LabelAlreadyUsedException, BeginTransactionException,
AnalysisException, QuotaExceedException, MetaNotFoundException {
checkDatabaseDataQuota();
Preconditions.checkNotNull(coordinator);
Preconditions.checkNotNull(label);
FeNameFormat.checkLabel(label);
long tid = 0L;
writeLock();
try {
Preconditions.checkNotNull(coordinator);
Preconditions.checkNotNull(label);
FeNameFormat.checkLabel(label);
/*
* Check if label already used, by following steps
* 1. get all existing transactions
@ -350,9 +351,7 @@ public class DatabaseTransactionMgr {
checkRunningTxnExceedLimit(sourceType);
long tid = idGenerator.getNextTransactionId();
LOG.info("begin transaction: txn id {} with label {} from coordinator {}, listener id: {}",
tid, label, coordinator, listenerId);
tid = idGenerator.getNextTransactionId();
TransactionState transactionState = new TransactionState(dbId, tableIdList,
tid, label, requestId, sourceType, coordinator, listenerId, timeoutSecond * 1000);
transactionState.setPrepareTime(System.currentTimeMillis());
@ -361,11 +360,12 @@ public class DatabaseTransactionMgr {
if (MetricRepo.isInit) {
MetricRepo.COUNTER_TXN_BEGIN.increase(1L);
}
return tid;
} finally {
writeUnlock();
}
LOG.info("begin transaction: txn id {} with label {} from coordinator {}, listener id: {}",
tid, label, coordinator, listenerId);
return tid;
}
private void checkDatabaseDataQuota() throws MetaNotFoundException, QuotaExceedException {
@ -1983,15 +1983,15 @@ public class DatabaseTransactionMgr {
// set transaction status will call txn state change listener
transactionState.replaySetTransactionStatus();
if (transactionState.getTransactionStatus() == TransactionStatus.COMMITTED) {
LOG.info("replay a committed transaction {}", transactionState);
updateCatalogAfterCommitted(transactionState, db);
} else if (transactionState.getTransactionStatus() == TransactionStatus.VISIBLE) {
LOG.info("replay a visible transaction {}", transactionState);
updateCatalogAfterVisible(transactionState, db);
}
unprotectUpsertTransactionState(transactionState, true);
} finally {
writeUnlock();
LOG.info("replay a {} transaction {}",
transactionState.getTransactionStatus(), transactionState);
if (shouldAddTableListLock) {
MetaLockUtils.writeUnlockTables(tableList);
}