Skip to content

Commit

Permalink
optimize: do not execute triggerAfterCommit() in case of timeout (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
miaoxueyu authored Oct 12, 2022
1 parent 6c1c857 commit e7fe7f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changes/en-us/1.5.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ The version is updated as follows:
- [[#4626](https://github.com/seata/seata/pull/4626)] Replace `flatten-maven-plugin` with `easyj-maven-plugin` to fix the conflict between `shade` and `flatten`
- [[#4629](https://github.com/seata/seata/pull/4629)] check relation of before status and after status when updating global session
- [[#4662](https://github.com/seata/seata/pull/4662)] make EnhancedServiceLoader more readable
- [[#4445](https://github.com/seata/seata/pull/4445)] optimize transaction timeout judgment
- [[#4958](https://github.com/seata/seata/pull/4958)] do not execute triggerAfterCommit() in case of timeout

### test:

Expand All @@ -73,6 +75,7 @@ Thanks to these contributors for their code commits. Please report an unintended
- [AYue-94](https://github.com/AYue-94)
- [lingxiao-wu](https://github.com/lingxiao-wu)
- [caohdgege](https://github.com/caohdgege)
- [miaoxueyu](https://github.com/miaoxueyu)


Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
Expand Down
3 changes: 3 additions & 0 deletions changes/zh-cn/1.5.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [[#4626](https://github.com/seata/seata/pull/4626)] 使用 `easyj-maven-plugin` 插件代替 `flatten-maven-plugin`插件,以修复`shade` 插件与 `flatten` 插件不兼容的问题
- [[#4629](https://github.com/seata/seata/pull/4629)] 更新globalSession状态时检查更改前后的约束关系
- [[#4662](https://github.com/seata/seata/pull/4662)] 优化 EnhancedServiceLoader 可读性
- [[#4445](https://github.com/seata/seata/pull/4445)] 优化事务超时判断
- [[#4958](https://github.com/seata/seata/pull/4958)] 优化当本地事务超时回滚后after commit事件被调用


### test:
Expand Down Expand Up @@ -75,6 +77,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [AYue-94](https://github.com/AYue-94)
- [lingxiao-wu](https://github.com/lingxiao-wu)
- [caohdgege](https://github.com/caohdgege)
- [miaoxueyu](https://github.com/miaoxueyu)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。

Expand Down
15 changes: 8 additions & 7 deletions tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,19 @@ private void commitTransaction(GlobalTransaction tx, TransactionInfo txInfo)
try {
triggerBeforeCommit();
tx.commit();

if (Arrays.asList(GlobalStatus.TimeoutRollbacking, GlobalStatus.TimeoutRollbacked).contains(tx.getLocalStatus())) {
throw new TransactionalExecutor.ExecutionException(tx,
new TimeoutException(String.format("Global transaction[%s] is timeout and will be rollback[TC].", tx.getXid())),
TransactionalExecutor.Code.TimeoutRollback);
}

triggerAfterCommit();
} catch (TransactionException txe) {
// 4.1 Failed to commit
throw new TransactionalExecutor.ExecutionException(tx, txe,
TransactionalExecutor.Code.CommitFailure);
}

if (Arrays.asList(GlobalStatus.TimeoutRollbacking, GlobalStatus.TimeoutRollbacked).contains(tx.getLocalStatus())) {
throw new TransactionalExecutor.ExecutionException(tx,
new TimeoutException(String.format("Global transaction[%s] is timeout and will be rollback[TC].", tx.getXid())),
TransactionalExecutor.Code.TimeoutRollback);
}
}

private void rollbackTransaction(GlobalTransaction tx, Throwable originalException) throws TransactionException, TransactionalExecutor.ExecutionException {
Expand Down Expand Up @@ -331,4 +332,4 @@ private void cleanUp() {
private List<TransactionHook> getCurrentHooks() {
return TransactionHookManager.getHooks();
}
}
}

0 comments on commit e7fe7f8

Please sign in to comment.