incubator-seata icon indicating copy to clipboard operation
incubator-seata copied to clipboard

feature: Saga annotation

Open leezongjie opened this issue 2 years ago • 3 comments

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

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

leezongjie avatar Feb 04 '23 11:02 leezongjie

Codecov Report

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

:mega: 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           

codecov-commenter avatar Feb 11 '23 16:02 codecov-commenter

新增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

leezongjie avatar Feb 05 '24 08:02 leezongjie

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%) :arrow_up:
...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%) :arrow_up:
...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%) :arrow_up:
.../apache/seata/saga/rm/RMHandlerSagaAnnotation.java 0.00% <0.00%> (ø)
...m/tcc/interceptor/TccActionInterceptorHandler.java 67.14% <82.75%> (-1.71%) :arrow_down:
... and 2 more

... and 4 files with indirect coverage changes

codecov-commenter avatar Mar 01 '24 10:03 codecov-commenter