apache / apache/incubator-seata

增加 saga注解模式

Open
#4,571 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
26k
Forks
8.8k
Avg merge
1d 8h
Merged PRs (30d)
4

Description

## Why you need it?
seata的saga模式,目前只有基于状态机引擎实现的,利用控制台提供的状态设计器,编排状态图,定义各节点的详细信息和属性配置。但是学习成本和操作难度比较大。相对于简单的分布式事务来讲,配置相对复杂。缺乏可读性。
因此对于流程相对短的分布式事务,更适合于使用saga基于注解模式。

saga注解模式优点:
1. 配置简单,只需在两阶段提交的注解中加一个属性mode。来区分saga还是tcc。
2. 与tcc使用区别。两阶段提交注解TwoPhaseBusinessAction。对于tcc,需要定义三个接口方法,被标注的方法本身为一阶段try方法,注解中的commit属性为二阶段提交方法,cancel属性为二阶段撤销方法。对于saga,被标注的方法本身为一阶段提交commit,注解中的属性cancel为二阶段撤销方法,属性commit为空。

## How it could be?
实现方式目前有两种方案:
方案一
1,对于seata-spring的改造,以SPI方式分别加载tcc和saga的拦截器实现。
2,需要对拦截器定义抽象。
2,新增saga两阶段提交的注解。
3,新增saga的scaner,parser。
方案二
1,目前tcc也是使用的两阶段提交注解TwoPhaseBusinessAction,在这个注解中加入新的属性mode=tcc/saga。
2,可以重用tcc下的scaner,parser,放悬挂机制等。

经过讨论,选择方案二。

具体方案二的现实逻辑为:
1,TwoPhaseBusinessAction注解增加mode,类型为枚举,值为tcc/saga,以后可新增加新的模式。
2,在二阶段提交的时候做判断,如果saga模式的话,不提交。
3,在spring启动扫描的时候,对saga模式的方法做检查。

## Other related information

Contributor guide

Open the contributing guide

Research direction

Start with the TwoPhaseBusinessAction annotation and the seata-spring startup scanner/parser, then trace the existing TCC interceptor and second-phase handling. Confirm how annotation attributes and mode values are validated during Spring startup. Done means saga and TCC modes are distinguished, saga skips the second-phase commit, and invalid saga methods are rejected consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, distributed-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.