Skip to content

Commit

Permalink
optimize: compatible with tcc (apache#6345)
Browse files Browse the repository at this point in the history
  • Loading branch information
xingfudeshi committed Mar 1, 2024
1 parent 709bd30 commit 575ac12
Show file tree
Hide file tree
Showing 12 changed files with 669 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6254](https://github.com/apache/incubator-seata/pull/6254)] optimize Hessian Serialize
- [[#6332](https://github.com/apache/incubator-seata/pull/6332)] remove mysql dependency from the distribution package
- [[#6343](https://github.com/apache/incubator-seata/pull/6343)] compatible with tm module and rm-datasource module
- [[#6345](https://github.com/apache/incubator-seata/pull/6345)] compatible with tcc module
- [[#6356](https://github.com/apache/incubator-seata/pull/6356)] remove authentication from the health check page
- [[#6360](https://github.com/apache/incubator-seata/pull/6360)] optimize 401 issues for some links
- [[#6369](https://github.com/apache/incubator-seata/pull/6369)] optimize arm64 ci
Expand Down
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
- [[#6330](https://github.com/apache/incubator-seata/pull/6330)] 去除 mariadb API
- [[#6329](https://github.com/apache/incubator-seata/pull/6312)] 添加 saga 子组件的 io.seata 兼容性 API
- [[#6254](https://github.com/apache/incubator-seata/pull/6254)] 优化Hessian 序列化
- [[#6343](https://github.com/apache/incubator-seata/pull/6343)] 兼容tm 模块和rm-datasource模块
- [[#6345](https://github.com/apache/incubator-seata/pull/6345)] 兼容tcc模块
- [[#6332](https://github.com/apache/incubator-seata/pull/6332)] 分发包中移除 mysql 依赖
- [[#6343](https://github.com/apache/incubator-seata/pull/6343)] 兼容 TM 模块和 rm-datasource 模块
- [[#6349](https://github.com/apache/incubator-seata/pull/6349)] 迁移 dockerhub 仓库
Expand Down
15 changes: 15 additions & 0 deletions compatible/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-saga-engine</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-saga-engine-store</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-saga-spring</artifactId>
Expand Down Expand Up @@ -101,5 +111,10 @@
<version>1.27.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-tcc</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import org.apache.seata.common.util.CollectionUtils;
import org.apache.seata.common.util.StringUtils;
import org.apache.seata.rm.tcc.api.ParamType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;

import static org.apache.seata.integration.tx.api.interceptor.ActionContextUtil.getByIndex;

/**
* Extracting TCC Context from Method
*/
Expand All @@ -36,6 +37,8 @@ public final class ActionContextUtil {
private ActionContextUtil() {
}

private static final Logger LOGGER = LoggerFactory.getLogger(ActionContextUtil.class);

/**
* Extracting context data from parameters
*
Expand Down Expand Up @@ -86,6 +89,29 @@ public static void loadParamByAnnotationAndPutToContext(@Nonnull final ParamType
}
}

@Nullable
private static Object getByIndex(@Nonnull ParamType paramType, @Nonnull String paramName, @Nonnull Object paramValue, int index) {
if (paramValue instanceof List) {
@SuppressWarnings("unchecked")
List<Object> list = (List<Object>) paramValue;
if (list.isEmpty()) {
return null;
}
if (list.size() <= index) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("The index '{}' is out of bounds for the list {} named '{}'," +
" whose size is '{}', so pass this {}", index, paramType.getCode(), paramName, list.size(), paramType.getCode());
}
return null;
}
paramValue = list.get(index);
} else {
LOGGER.warn("the {} named '{}' is not a `List`, so the 'index' field of '@{}' cannot be used on it",
paramType.getCode(), paramName, BusinessActionContextParameter.class.getSimpleName());
}

return paramValue;
}

public static String getParamNameFromAnnotation(@Nonnull BusinessActionContextParameter annotation) {
String paramName = annotation.paramName();
Expand Down
30 changes: 30 additions & 0 deletions compatible/src/main/java/io/seata/rm/tcc/api/LocalTCC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.rm.tcc.api;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface LocalTCC {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.rm.tcc.api;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Inherited
public @interface TwoPhaseBusinessAction {

/**
* TCC bean name, must be unique
*
* @return the string
*/
String name();

/**
* commit method name
*
* @return the string
*/
String commitMethod() default "commit";

/**
* rollback method name
*
* @return the string
*/
String rollbackMethod() default "rollback";

/**
* delay branch report while sharing params to tcc phase 2 to enhance performance
*
* @return isDelayReport
*/
boolean isDelayReport() default false;

/**
* whether use TCC fence (idempotent,non_rollback,suspend)
*
* @return the boolean
*/
boolean useTCCFence() default false;

/**
* commit method's args
*
* @return the Class[]
*/
Class<?>[] commitArgsClasses() default {BusinessActionContext.class};

/**
* rollback method's args
*
* @return the Class[]
*/
Class<?>[] rollbackArgsClasses() default {BusinessActionContext.class};
}

0 comments on commit 575ac12

Please sign in to comment.