Skip to content

Commit 575ac12

Browse files
authored
optimize: compatible with tcc (#6345)
1 parent 709bd30 commit 575ac12

File tree

12 files changed

+669
-5
lines changed

12 files changed

+669
-5
lines changed

changes/en-us/2.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Add changes here for all PR submitted to the 2.x branch.
9595
- [[#6254](https://github.com/apache/incubator-seata/pull/6254)] optimize Hessian Serialize
9696
- [[#6332](https://github.com/apache/incubator-seata/pull/6332)] remove mysql dependency from the distribution package
9797
- [[#6343](https://github.com/apache/incubator-seata/pull/6343)] compatible with tm module and rm-datasource module
98+
- [[#6345](https://github.com/apache/incubator-seata/pull/6345)] compatible with tcc module
9899
- [[#6356](https://github.com/apache/incubator-seata/pull/6356)] remove authentication from the health check page
99100
- [[#6360](https://github.com/apache/incubator-seata/pull/6360)] optimize 401 issues for some links
100101
- [[#6369](https://github.com/apache/incubator-seata/pull/6369)] optimize arm64 ci

changes/zh-cn/2.x.md

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
- [[#6330](https://github.com/apache/incubator-seata/pull/6330)] 去除 mariadb API
9595
- [[#6329](https://github.com/apache/incubator-seata/pull/6312)] 添加 saga 子组件的 io.seata 兼容性 API
9696
- [[#6254](https://github.com/apache/incubator-seata/pull/6254)] 优化Hessian 序列化
97+
- [[#6343](https://github.com/apache/incubator-seata/pull/6343)] 兼容tm 模块和rm-datasource模块
98+
- [[#6345](https://github.com/apache/incubator-seata/pull/6345)] 兼容tcc模块
9799
- [[#6332](https://github.com/apache/incubator-seata/pull/6332)] 分发包中移除 mysql 依赖
98100
- [[#6343](https://github.com/apache/incubator-seata/pull/6343)] 兼容 TM 模块和 rm-datasource 模块
99101
- [[#6349](https://github.com/apache/incubator-seata/pull/6349)] 迁移 dockerhub 仓库

compatible/pom.xml

+15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<maven.compiler.target>8</maven.compiler.target>
3333
</properties>
3434
<dependencies>
35+
<dependency>
36+
<groupId>org.apache.seata</groupId>
37+
<artifactId>seata-saga-engine</artifactId>
38+
<version>${project.version}</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.apache.seata</groupId>
42+
<artifactId>seata-saga-engine-store</artifactId>
43+
<version>${project.version}</version>
44+
</dependency>
3545
<dependency>
3646
<groupId>org.apache.seata</groupId>
3747
<artifactId>seata-saga-spring</artifactId>
@@ -101,5 +111,10 @@
101111
<version>1.27.1</version>
102112
<scope>provided</scope>
103113
</dependency>
114+
<dependency>
115+
<groupId>org.apache.seata</groupId>
116+
<artifactId>seata-tcc</artifactId>
117+
<version>${project.version}</version>
118+
</dependency>
104119
</dependencies>
105120
</project>

compatible/src/main/java/io/seata/integration/tx/api/interceptor/ActionContextUtil.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
import org.apache.seata.common.util.CollectionUtils;
2222
import org.apache.seata.common.util.StringUtils;
2323
import org.apache.seata.rm.tcc.api.ParamType;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
2426

2527
import javax.annotation.Nonnull;
2628
import javax.annotation.Nullable;
29+
import java.util.List;
2730
import java.util.Map;
2831

29-
import static org.apache.seata.integration.tx.api.interceptor.ActionContextUtil.getByIndex;
30-
3132
/**
3233
* Extracting TCC Context from Method
3334
*/
@@ -36,6 +37,8 @@ public final class ActionContextUtil {
3637
private ActionContextUtil() {
3738
}
3839

40+
private static final Logger LOGGER = LoggerFactory.getLogger(ActionContextUtil.class);
41+
3942
/**
4043
* Extracting context data from parameters
4144
*
@@ -86,6 +89,29 @@ public static void loadParamByAnnotationAndPutToContext(@Nonnull final ParamType
8689
}
8790
}
8891

92+
@Nullable
93+
private static Object getByIndex(@Nonnull ParamType paramType, @Nonnull String paramName, @Nonnull Object paramValue, int index) {
94+
if (paramValue instanceof List) {
95+
@SuppressWarnings("unchecked")
96+
List<Object> list = (List<Object>) paramValue;
97+
if (list.isEmpty()) {
98+
return null;
99+
}
100+
if (list.size() <= index) {
101+
if (LOGGER.isDebugEnabled()) {
102+
LOGGER.debug("The index '{}' is out of bounds for the list {} named '{}'," +
103+
" whose size is '{}', so pass this {}", index, paramType.getCode(), paramName, list.size(), paramType.getCode());
104+
}
105+
return null;
106+
}
107+
paramValue = list.get(index);
108+
} else {
109+
LOGGER.warn("the {} named '{}' is not a `List`, so the 'index' field of '@{}' cannot be used on it",
110+
paramType.getCode(), paramName, BusinessActionContextParameter.class.getSimpleName());
111+
}
112+
113+
return paramValue;
114+
}
89115

90116
public static String getParamNameFromAnnotation(@Nonnull BusinessActionContextParameter annotation) {
91117
String paramName = annotation.paramName();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.seata.rm.tcc.api;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Inherited;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
26+
@Retention(RetentionPolicy.RUNTIME)
27+
@Target(ElementType.TYPE)
28+
@Inherited
29+
public @interface LocalTCC {
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.seata.rm.tcc.api;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Inherited;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
26+
@Retention(RetentionPolicy.RUNTIME)
27+
@Target({ElementType.METHOD})
28+
@Inherited
29+
public @interface TwoPhaseBusinessAction {
30+
31+
/**
32+
* TCC bean name, must be unique
33+
*
34+
* @return the string
35+
*/
36+
String name();
37+
38+
/**
39+
* commit method name
40+
*
41+
* @return the string
42+
*/
43+
String commitMethod() default "commit";
44+
45+
/**
46+
* rollback method name
47+
*
48+
* @return the string
49+
*/
50+
String rollbackMethod() default "rollback";
51+
52+
/**
53+
* delay branch report while sharing params to tcc phase 2 to enhance performance
54+
*
55+
* @return isDelayReport
56+
*/
57+
boolean isDelayReport() default false;
58+
59+
/**
60+
* whether use TCC fence (idempotent,non_rollback,suspend)
61+
*
62+
* @return the boolean
63+
*/
64+
boolean useTCCFence() default false;
65+
66+
/**
67+
* commit method's args
68+
*
69+
* @return the Class[]
70+
*/
71+
Class<?>[] commitArgsClasses() default {BusinessActionContext.class};
72+
73+
/**
74+
* rollback method's args
75+
*
76+
* @return the Class[]
77+
*/
78+
Class<?>[] rollbackArgsClasses() default {BusinessActionContext.class};
79+
}

0 commit comments

Comments
 (0)