Skip to content

Commit 1035495

Browse files
sollhuipull[bot]
authored andcommitted
[improve](transaction) lightweight transaction lock logic (#27564)
1 parent 0583e36 commit 1035495

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/transaction/DatabaseTransactionMgr.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,13 @@ public long beginTransaction(List<Long> tableIdList, String label, TUniqueId req
310310
throws DuplicatedRequestException, LabelAlreadyUsedException, BeginTransactionException,
311311
AnalysisException, QuotaExceedException, MetaNotFoundException {
312312
checkDatabaseDataQuota();
313+
Preconditions.checkNotNull(coordinator);
314+
Preconditions.checkNotNull(label);
315+
FeNameFormat.checkLabel(label);
316+
317+
long tid = 0L;
313318
writeLock();
314319
try {
315-
Preconditions.checkNotNull(coordinator);
316-
Preconditions.checkNotNull(label);
317-
FeNameFormat.checkLabel(label);
318-
319320
/*
320321
* Check if label already used, by following steps
321322
* 1. get all existing transactions
@@ -350,9 +351,7 @@ public long beginTransaction(List<Long> tableIdList, String label, TUniqueId req
350351

351352
checkRunningTxnExceedLimit(sourceType);
352353

353-
long tid = idGenerator.getNextTransactionId();
354-
LOG.info("begin transaction: txn id {} with label {} from coordinator {}, listener id: {}",
355-
tid, label, coordinator, listenerId);
354+
tid = idGenerator.getNextTransactionId();
356355
TransactionState transactionState = new TransactionState(dbId, tableIdList,
357356
tid, label, requestId, sourceType, coordinator, listenerId, timeoutSecond * 1000);
358357
transactionState.setPrepareTime(System.currentTimeMillis());
@@ -361,11 +360,12 @@ public long beginTransaction(List<Long> tableIdList, String label, TUniqueId req
361360
if (MetricRepo.isInit) {
362361
MetricRepo.COUNTER_TXN_BEGIN.increase(1L);
363362
}
364-
365-
return tid;
366363
} finally {
367364
writeUnlock();
368365
}
366+
LOG.info("begin transaction: txn id {} with label {} from coordinator {}, listener id: {}",
367+
tid, label, coordinator, listenerId);
368+
return tid;
369369
}
370370

371371
private void checkDatabaseDataQuota() throws MetaNotFoundException, QuotaExceedException {
@@ -1983,15 +1983,15 @@ public void replayUpsertTransactionState(TransactionState transactionState) thro
19831983
// set transaction status will call txn state change listener
19841984
transactionState.replaySetTransactionStatus();
19851985
if (transactionState.getTransactionStatus() == TransactionStatus.COMMITTED) {
1986-
LOG.info("replay a committed transaction {}", transactionState);
19871986
updateCatalogAfterCommitted(transactionState, db);
19881987
} else if (transactionState.getTransactionStatus() == TransactionStatus.VISIBLE) {
1989-
LOG.info("replay a visible transaction {}", transactionState);
19901988
updateCatalogAfterVisible(transactionState, db);
19911989
}
19921990
unprotectUpsertTransactionState(transactionState, true);
19931991
} finally {
19941992
writeUnlock();
1993+
LOG.info("replay a {} transaction {}",
1994+
transactionState.getTransactionStatus(), transactionState);
19951995
if (shouldAddTableListLock) {
19961996
MetaLockUtils.writeUnlockTables(tableList);
19971997
}

0 commit comments

Comments
 (0)