Skip to content

Commit b2d4584

Browse files
authored
bugfix: fix log in participant transaction role (#5594)
1 parent d0d012c commit b2d4584

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

changes/en-us/2.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The version is updated as follows:
5757
- [[#5558](https://github.com/seata/seata/pull/5558)] fix mariadb rollback failed
5858
- [[#5556](https://github.com/seata/seata/pull/5556)] fix oracle insert undolog failed
5959
- [[#5577](https://github.com/seata/seata/pull/5577)] fix grpc interceptor xid unbinding problem
60+
- [[#5594](https://github.com/seata/seata/pull/5594)] fix log in participant transaction role
6061

6162
### optimize:
6263
- [[#5208](https://github.com/seata/seata/pull/5208)] optimize throwable getCause once more

changes/zh-cn/2.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
5555
- [[#5558](https://github.com/seata/seata/pull/5558)] 修复mariadb回滚失败的问题
5656
- [[#5556](https://github.com/seata/seata/pull/5556)] 修复 oracle 插入 undolog 失败问题
5757
- [[#5577](https://github.com/seata/seata/pull/5577)] 修复 grpc拦截器解绑xid失败问题
58+
- [[#5594](https://github.com/seata/seata/pull/5594)] 修复participant情况下的重复日志
5859

5960
### optimize:
6061
- [[#5208](https://github.com/seata/seata/pull/5208)] 优化多次重复获取Throwable#getCause问题

tm/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public void commit() throws TransactionException {
129129
return;
130130
}
131131
assertXIDNotNull();
132+
if (LOGGER.isInfoEnabled()) {
133+
LOGGER.info("transaction {} will be commit", xid);
134+
}
132135
int retry = COMMIT_RETRY_COUNT <= 0 ? DEFAULT_TM_COMMIT_RETRY_COUNT : COMMIT_RETRY_COUNT;
133136
try {
134137
while (retry > 0) {
@@ -164,6 +167,9 @@ public void rollback() throws TransactionException {
164167
return;
165168
}
166169
assertXIDNotNull();
170+
if (LOGGER.isInfoEnabled()) {
171+
LOGGER.info("transaction {} will be rollback", xid);
172+
}
167173

168174
int retry = ROLLBACK_RETRY_COUNT <= 0 ? DEFAULT_TM_ROLLBACK_RETRY_COUNT : ROLLBACK_RETRY_COUNT;
169175
try {

tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public Object execute(TransactionalExecutor business) throws Throwable {
7474
// If transaction is existing, suspend it, and then begin new transaction.
7575
if (existingTransaction(tx)) {
7676
suspendedResourcesHolder = tx.suspend(false);
77-
tx = GlobalTransactionContext.createNew();
7877
}
78+
tx = GlobalTransactionContext.createNew();
7979
// Continue and execute with new transaction
8080
break;
8181
case SUPPORTS:
@@ -86,8 +86,8 @@ public Object execute(TransactionalExecutor business) throws Throwable {
8686
// Continue and execute with new transaction
8787
break;
8888
case REQUIRED:
89-
// If current transaction is existing, execute with current transaction,
90-
// else continue and execute with new transaction.
89+
// If current transaction is existing, execute with current transaction,else create
90+
tx = GlobalTransactionContext.getCurrentOrCreate();
9191
break;
9292
case NEVER:
9393
// If transaction is existing, throw exception.
@@ -110,13 +110,12 @@ public Object execute(TransactionalExecutor business) throws Throwable {
110110
throw new TransactionException("Not Supported Propagation:" + propagation);
111111
}
112112

113-
// 1.3 If null, create new transaction with role 'GlobalTransactionRole.Launcher'.
114-
if (tx == null) {
115-
tx = GlobalTransactionContext.createNew();
116-
}
117-
118113
// set current tx config to holder
119114
GlobalLockConfig previousConfig = replaceGlobalLockConfig(txInfo);
115+
116+
if (tx.getGlobalTransactionRole() == GlobalTransactionRole.Participant) {
117+
LOGGER.info("join into a existing global transaction,xid={}", tx.getXid());
118+
}
120119

121120
try {
122121
// 2. If the tx role is 'GlobalTransactionRole.Launcher', send the request of beginTransaction to TC,
@@ -211,9 +210,6 @@ private void commitTransaction(GlobalTransaction tx, TransactionInfo txInfo)
211210

212211
try {
213212
triggerBeforeCommit();
214-
if (LOGGER.isInfoEnabled()) {
215-
LOGGER.info("transaction {} will be commit", tx.getXid());
216-
}
217213
tx.commit();
218214
GlobalStatus afterCommitStatus = tx.getLocalStatus();
219215
TransactionalExecutor.Code code = TransactionalExecutor.Code.Unknown;
@@ -252,10 +248,6 @@ private void rollbackTransaction(GlobalTransaction tx, Throwable originalExcepti
252248

253249
try {
254250
triggerBeforeRollback();
255-
if (LOGGER.isInfoEnabled()) {
256-
LOGGER.info("transaction {} will be rollback, cause by:{}", tx.getXid(),
257-
originalException.getMessage());
258-
}
259251
tx.rollback();
260252
triggerAfterRollback();
261253
} catch (TransactionException txe) {

0 commit comments

Comments
 (0)