Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Saga annotation #5300

Open
wants to merge 9 commits into
base: 2.x
Choose a base branch
from

Conversation

leezongjie
Copy link
Contributor

@leezongjie leezongjie commented Feb 4, 2023

支持saga注解的两阶段事务提交方式。

1、saga分支事务也分为两阶段,和tcc类似,区别在于,当saga事务提交时,一阶段直接提交,无需二阶段,即退化了tcc的二阶段提交,只有事务需要回滚时才会执行二阶段对一阶段提交的事务数据进行补偿。
2、新增saga注解CompensationBusinessAction,对需要使用saga模式的分支事务服务接口或者实现添加该注解。
3、由于和tcc流程类似,saga-annotation模式复用了大部分tcc的流程,对其中特殊的地方做了重写。
4、saga注解模式相比状态机暂时不支持向前重试能力。
5、防悬挂可复用tcc防悬挂,当前防悬挂问题另开PR处理。

@funky-eyes funky-eyes added type: feature Category issues or prs related to feature request. mode: SAGA SAGA transaction mode labels Feb 4, 2023
@funky-eyes funky-eyes added this to the 2.0.0 milestone Feb 4, 2023
@leezongjie leezongjie changed the title Saga annotation feature: Saga annotation Feb 4, 2023
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (2.x@3097fd6). Click here to learn what that means.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Impacted file tree graph

@@          Coverage Diff           @@
##             2.x    #5300   +/-   ##
======================================
  Coverage       ?   48.81%           
  Complexity     ?     4251           
======================================
  Files          ?      772           
  Lines          ?    27011           
  Branches       ?     3356           
======================================
  Hits           ?    13185           
  Misses         ?    12444           
  Partials       ?     1382           

# Conflicts:
#	tcc/src/main/java/org/apache/seata/rm/tcc/interceptor/TccActionInterceptorHandler.java
@leezongjie
Copy link
Contributor Author

leezongjie commented Feb 5, 2024

新增seata-saga-annotation模块,继承自seata-tcc,seata-saga-annotation主要是覆盖了tcc的部分逻辑,以适配saga模式。

新建saga注解:

image

扩展SagaActionInterceptorParser,支持Saga-annotation切面解析器。

image

扩展SagaActionInterceptorHandler,saga两阶段注解切面,继承自TccActionInterceptorHandler,覆盖重写了类型,参数生成,注解类部分方法。

image

seata-server扩展SagaAnnotationCore,执行SAGA-ANNOTATION的提交时忽略。

image

扩展SagaAnnotationResourceManager,继承自TCCResourceManager,二阶段回滚复用tcc逻辑,主要是覆盖了branchCommit,执行空提交方法,实际上TC会忽略SAGA-ANNOTATION的提交过程,不会走到RM端。

image

# Conflicts:
#	saga/pom.xml
#	tcc/src/main/java/org/apache/seata/rm/tcc/interceptor/TccActionInterceptorHandler.java
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 80.83832% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 51.10%. Comparing base (575ac12) to head (99e1792).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #5300      +/-   ##
============================================
+ Coverage     51.01%   51.10%   +0.09%     
- Complexity     5261     5301      +40     
============================================
  Files           934      941       +7     
  Lines         33029    33133     +104     
  Branches       4002     4002              
============================================
+ Hits          16849    16932      +83     
- Misses        14511    14531      +20     
- Partials       1669     1670       +1     
Files Coverage Δ
...n/java/org/apache/seata/core/model/BranchType.java 80.00% <100.00%> (+1.42%) ⬆️
...a/rm/interceptor/SagaActionInterceptorHandler.java 100.00% <100.00%> (ø)
...nterceptor/parser/SagaActionInterceptorParser.java 100.00% <100.00%> (ø)
...ata/saga/rm/parser/SagaRegisterResourceParser.java 100.00% <100.00%> (ø)
...interceptor/parser/TccActionInterceptorParser.java 68.75% <100.00%> (+4.46%) ⬆️
...ta/server/transaction/saga/SagaAnnotationCore.java 75.00% <75.00%> (ø)
...e/seata/saga/rm/SagaAnnotationResourceManager.java 81.81% <81.81%> (ø)
...tcc/resource/parser/TccRegisterResourceParser.java 92.15% <92.00%> (+0.66%) ⬆️
.../apache/seata/saga/rm/RMHandlerSagaAnnotation.java 0.00% <0.00%> (ø)
...m/tcc/interceptor/TccActionInterceptorHandler.java 67.14% <82.75%> (-1.71%) ⬇️
... and 2 more

... and 4 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mode: SAGA SAGA transaction mode type: feature Category issues or prs related to feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants