-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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 mode #4577
feature : SAGA annotation mode #4577
Conversation
|
||
// if the TwoPhaseBusinessAction annotation's mode is SAGA, cancel the commit | ||
ModeType modeType = (ModeType) businessActionContext.getActionContext(Constants.MODE_TYPE); | ||
if(modeType != null && modeType.equals( ModeType.SAGA)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码格式化一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果spring cloud用户使用注解式SAGA的话,需要打上@LocalTCC的注解,对于用户来说这个其实比较困惑
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
您好,已经格式提交。
确实@LocalTCC会让用户迷惑,所以我定义了一个新的注解Compensable和 LocalSAGA 与TCC区分,请见#4577 (comment)
此注解也定义了向前重试机制
对于SEATA来说,要不要再多走一步,即SEATA自动向前做重试补偿 |
如果是1.5.x版本的觉得当前的pr做法是可以接受的,如果是2.x版本我觉得应该步子迈大 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外ActionInterceptorHandler#doTccActionLogStore 中应该传递branchtype注册至tc,否则到tc还是认为是tcc分支
@@ -97,6 +98,14 @@ public BranchStatus branchCommit(BranchType branchType, String xid, long branchI | |||
//BusinessActionContext | |||
BusinessActionContext businessActionContext = getBusinessActionContext(xid, branchId, resourceId, | |||
applicationData); | |||
|
|||
// if the TwoPhaseBusinessAction annotation's mode is SAGA, cancel the commit | |||
ModeType modeType = (ModeType) businessActionContext.getActionContext(Constants.MODE_TYPE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DefaultCore#doGlobalCommit 直接处理即可
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我再看一下这里DefaultCore#doGlobalCommit ,如果结合新的注解Compensable来处理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外ActionInterceptorHandler#doTccActionLogStore 中应该传递branchtype注册至tc,否则到tc还是认为是tcc分支
确实要改成SAGA的branchtype,所以对于ActionInterceptorHandler来处理SAGA,我想可能新增一个doSagaActionLogStore来处理,或者考虑可重用来在内部兼容处理SAGA的branchtype注册至tc
* | ||
* @author ruishan | ||
*/ | ||
public enum ModeType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要使用新类,直接使用BranchType 枚举类
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经去掉ModeType,改成BranchType
另外应该独立一个TwoPhaseBusinessAction给saga使用因为某些参数是不适用于saga的,如commitMethod,此外第一版可以将spring module和seata-tcc稍微改一下依赖关系,seata-tcc应该依赖spring module而不是springmodule依赖seata-tcc,可以先把相关注解挪到spring module去 |
您好,确实TCC和SAGA的注解是不适用的,所以我想为SAGA设计一个新的注解Compensable,注解的属性如下: 以上注解属性定义了SAGA的向后补偿方法,以及向前重试次数机制等。 但是我在修改的代码的时候,感觉要改动的地方好像有些多,有些不太确定是应该新增还是,在原方法修改,我总结了我的一些修改点: ● 在tcc/src/main/java/io/seata/rm/tcc/remoting/parser下增加一个 SAGARemotingParser 分析器,主要是分析一下是否接口被LocalSAGA注解,是的话说明则 ● io.seata.rm.tcc.remoting.parser.DefaultRemotingParser#parserRemotingServiceInfo ● 新增加拦截器 ● 拦截处理器,是否也要新增 还有一个问题就是我没有太准确的理解 seata-tcc如何得去依赖spring module。因为在原有依赖上,我看是在seata-spring中的io.seata.spring.annotation.GlobalTransactionScanner#wrapIfNecessary 去调用TCC包中分析器,以及上报TC都是在TCC包中的拦截器做的,能帮再指明一下吗? |
确实要改成SAGA的branchtype,所以对于ActionInterceptorHandler来处理SAGA,我想可能新增一个doSagaActionLogStore来处理,或者考虑可重用来在内部兼容处理SAGA的branchtype注册至tc |
@sunrui1225 |
seata-spirng 与 seata-tcc的依赖关系问题 pr1(迁移)
pr2(加入SAGA模式,抽象拓展)
|
…to feature_saga_annotation_mode
@@ -134,4 +136,43 @@ public static void setContext(BusinessActionContext context) { | |||
public static void clear() { | |||
CONTEXT_HOLDER.remove(); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 111, branchReport(BranchType.TCC, 这里需要区分下tcc saga,类型从参数获取
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
if (sagaResource == null) { | ||
throw new ShouldNeverHappenException(String.format("Saga resource is not exist, resourceId: %s", resourceId)); | ||
} | ||
if (sagaResource.isUseSagaAnnotationMode()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saga一阶段里面开启防悬挂后,会插入悬挂表记录,二阶段如果不更新防悬挂表,悬挂记录就无法清理了,这里检查下,需要更新防悬挂记录状态。
记录清理任务入口:io.seata.spring.fence.TCCFenceHandler#deleteFenceByDate()
清理状态:status in (" + TCCFenceConstant.STATUS_COMMITTED + " , " + TCCFenceConstant.STATUS_ROLLBACKED + " , " + TCCFenceConstant.STATUS_SUSPENDED + ")"
import io.seata.rm.tcc.store.db.TCCFenceStoreDataBaseDAO; | ||
import io.seata.spring.fence.TCCFenceHandler; | ||
import io.seata.spring.fence.exception.TCCFenceException; | ||
import io.seata.spring.fence.store.db.TCCFenceStoreDataBaseDAO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TCCFence是属于通用类型,tcc和saga可以通用,也不数据用户接触api,考虑改名
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改,检查了下通用防悬挂的名字,也做了修改
* @return the branchId | ||
*/ | ||
protected String doTccActionLogStore(Method method, Object[] arguments, TwoPhaseBusinessAction businessAction, | ||
protected String doTccActionLogStore(Method method, Object[] arguments, TwoPhaseBusinessActionParam businessActionParam, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
方法改名,其他地方也可以检查下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改,检查了下通用防悬挂的名字,也做了修改
Method[] methods = sagaInterfaceClazz.getMethods(); | ||
for (Method method : methods) { | ||
SagaTransactional sagaTransactional = method.getAnnotation(SagaTransactional.class); | ||
if (sagaTransactional != null && (Protocols.IN_JVM == remotingDesc.getProtocol() || remotingDesc.isReference())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IN_JVM 也可以通过 remotingDesc.isReference()判断
…to feature_saga_annotation_mode
…to feature_saga_annotation_mode
ruishansun seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
ruishansun seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Ⅰ. Describe what this PR did
The PR add SAGA annotation mode to seata. The current SAGA mode solution is based on state machine which is difficult to learn and operated. It's easy for the short tranction with SAGA annotation mode.
20230204 Closed. Please see pr #5300
Ⅱ. Does this pull request fix one issue?
fixes #4571
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews