Skip to content

Commit

Permalink
feature: optimize TCC structure, supporting API access (#5165)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunrui1225 authored Jan 31, 2023
1 parent 4527a41 commit c7fba75
Show file tree
Hide file tree
Showing 119 changed files with 3,149 additions and 1,396 deletions.
8 changes: 4 additions & 4 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,6 @@
<artifactId>edas-sdk</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
Expand Down Expand Up @@ -600,6 +596,10 @@
<artifactId>lz4-java</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 1 addition & 1 deletion build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<properties>
<!-- seata version -->
<revision>1.7.0-SNAPSHOT</revision>
<revision>2.0.0-SNAPSHOT</revision>

<!-- Compiler settings properties -->
<java.version>1.8</java.version>
Expand Down
2 changes: 1 addition & 1 deletion changes/en-us/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Seata is an easy-to-use, high-performance, open source distributed transaction s
The version is updated as follows:

### feature:
- [[#1234](https://github.com/seata/seata/pull/1234)] Please delete the sample later
- [[#5165](https://github.com/seata/seata/pull/5165)] optimize TCC structure, supporting API access. add integration layer module(seata-integration-tx-api) for transaction process definition and proxy enhancement.

### bugfix:
- [[#1234](https://github.com/seata/seata/pull/1234)] Please delete the sample later
Expand Down
2 changes: 1 addition & 1 deletion changes/zh-cn/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
此版本更新如下:

### feature:
- [[#1234](https://github.com/seata/seata/pull/1234)] 样例,后续请删除
- [[#5165](https://github.com/seata/seata/pull/5165)] TCC结构拆分,支持API方式接入。增加集成层模块(seata-integration-tx-api),对事务流程定义以及代理部分增强。

### bugfix:
- [[#1234](https://github.com/seata/seata/pull/1234)] 样例,后续请删除
Expand Down
11 changes: 8 additions & 3 deletions common/src/main/java/io/seata/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public interface Constants {
/**
* Use TCC fence
*/
String USE_TCC_FENCE = "useTCCFence";
String USE_COMMON_FENCE = "useTCCFence";

/**
* phase one method name
Expand All @@ -94,7 +94,7 @@ public interface Constants {
/**
* branch context
*/
String TCC_ACTION_CONTEXT = "actionContext";
String TX_ACTION_CONTEXT = "actionContext";

/**
* default charset name
Expand Down Expand Up @@ -165,5 +165,10 @@ public interface Constants {
* The constant REGISTRY_TYPE_SPLIT_CHAR.
*/
String REGISTRY_TYPE_SPLIT_CHAR = ",";

/**
* phase two compensation method name
*/
String COMPENSATION_METHOD = "sys::compensation";

}
}
19 changes: 12 additions & 7 deletions common/src/main/java/io/seata/common/DefaultValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,28 @@ public interface DefaultValues {
*/
int TCC_ACTION_INTERCEPTOR_ORDER = Integer.MIN_VALUE + 1000;

/**
* the constant SAGA_ACTION_INTERCEPTOR_ORDER
*/
int SAGA_ACTION_INTERCEPTOR_ORDER = Integer.MIN_VALUE + 1000;

/**
* the constant DEFAULT_DISTRIBUTED_LOCK_EXPIRE
*/
int DEFAULT_DISTRIBUTED_LOCK_EXPIRE = 10000;

/**
* the constant DEFAULT_TCC_FENCE_CLEAN_PERIOD
* the constant DEFAULT_COMMON_FENCE_CLEAN_PERIOD
*/
int DEFAULT_TCC_FENCE_CLEAN_PERIOD = 1;
int DEFAULT_COMMON_FENCE_CLEAN_PERIOD = 1;
/**
* the constant DEFAULT_TCC_FENCE_LOG_TABLE_NAME
* the constant DEFAULT_COMMON_FENCE_LOG_TABLE_NAME
*/
String DEFAULT_TCC_FENCE_LOG_TABLE_NAME = "tcc_fence_log";
String DEFAULT_COMMON_FENCE_LOG_TABLE_NAME = "tcc_fence_log";
/**
* the constant TCC_FENCE_BEAN_NAME
* the constant COMMON_FENCE_BEAN_NAME
*/
String TCC_FENCE_BEAN_NAME = "tccFenceConfig";
String COMMON_FENCE_BEAN_NAME = "tccFenceConfig";

/**
* the constant DEFAULT_RPC_RM_REQUEST_TIMEOUT
Expand Down Expand Up @@ -286,4 +291,4 @@ public interface DefaultValues {
* Default druid location in classpath
*/
String DRUID_LOCATION = "lib/sqlparser/druid.jar";
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/io/seata/core/protocol/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Version {
/**
* The constant CURRENT.
*/
private static final String CURRENT = "1.7.0-SNAPSHOT";
private static final String CURRENT = "2.0.0-SNAPSHOT";
private static final String VERSION_0_7_1 = "0.7.1";
private static final String VERSION_1_5_0 = "1.5.0";
private static final int MAX_VERSION_DOT = 3;
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<dubbo-seata.version>1.0.2</dubbo-seata.version>
<brpc.version>2.5.9</brpc.version>
<hsf.version>1.8.3</hsf.version>
<bytebuddy.version>1.12.13</bytebuddy.version>
<dubbo.alibaba.version>2.6.10</dubbo.alibaba.version>
<sofa.rpc.version>5.5.3</sofa.rpc.version>
<fastjson.version>1.2.83</fastjson.version>
Expand Down Expand Up @@ -114,6 +113,7 @@
<mockito.version>2.23.4</mockito.version>
<assertj-core.version>3.12.2</assertj-core.version>
<jetty-version>9.4.38.v20210224</jetty-version>
<bytebuddy.version>1.12.17</bytebuddy.version>
</properties>

<dependencyManagement>
Expand Down
64 changes: 64 additions & 0 deletions integration-tx-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 1999-2019 Seata.io Group.
~
~ Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.seata</groupId>
<artifactId>seata-parent</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>seata-integration-tx-api</artifactId>
<name>seata-integration-tx-api ${project.version}</name>
<packaging>jar</packaging>


<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-tm</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-rm-datasource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-rm</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-serializer-all</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.spring.annotation;
package io.seata.integration.tx.api.annotation;

import io.seata.common.DefaultValues;
import io.seata.common.LockStrategyMode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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.integration.tx.api.annotation;

import io.seata.common.util.StringUtils;
import io.seata.rm.tcc.api.BusinessActionContextParameter;

import java.lang.annotation.Annotation;

/**
* @author leezongjie
* @date 2022/12/23
*/
public class BusinessActionContextParameterDesc {
private String paramName;
private int index;
private boolean isParamInProperty;

private BusinessActionContextParameterDesc() {
}

public static BusinessActionContextParameterDesc createFromBusinessActionContextParameter(Annotation annotation) {
if (annotation == null) {
return null;
}
BusinessActionContextParameterDesc businessActionContextParameterDesc = null;
if (annotation instanceof BusinessActionContextParameter) {
businessActionContextParameterDesc = new BusinessActionContextParameterDesc();
BusinessActionContextParameter businessActionContextParameter = (BusinessActionContextParameter) annotation;
businessActionContextParameterDesc.setIndex(businessActionContextParameter.index());
businessActionContextParameterDesc.setParamInProperty(businessActionContextParameter.isParamInProperty());
businessActionContextParameterDesc.setParamName(StringUtils.isNotBlank(businessActionContextParameter.paramName()) ? businessActionContextParameter.paramName() : businessActionContextParameter.value());
}
return businessActionContextParameterDesc;
}

public String getParamName() {
return paramName;
}

public void setParamName(String paramName) {
this.paramName = paramName;
}

public int getIndex() {
return index;
}

public void setIndex(int index) {
this.index = index;
}

public boolean isParamInProperty() {
return isParamInProperty;
}

public void setParamInProperty(boolean paramInProperty) {
isParamInProperty = paramInProperty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.spring.event;
package io.seata.integration.tx.api.event;

import io.seata.core.event.Event;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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.integration.tx.api.fence;

import io.seata.common.executor.Callback;

import java.lang.reflect.Method;
import java.util.Date;

/**
* @author leezongjie
* @date 2022/12/17
*/
public class DefaultCommonFenceHandler implements FenceHandler {

private FenceHandler fenceHandler;

private static class SingletonHolder {
private static final DefaultCommonFenceHandler INSTANCE = new DefaultCommonFenceHandler();
}

public static DefaultCommonFenceHandler get() {
return DefaultCommonFenceHandler.SingletonHolder.INSTANCE;
}

public void setFenceHandler(FenceHandler fenceHandler) {
this.fenceHandler = fenceHandler;
}

private void check() {
if (fenceHandler == null) {
throw new RuntimeException("fenceHandler is null, need to set a fenceHandler implement");
}
}

@Override
public Object prepareFence(String xid, Long branchId, String actionName, Callback<Object> targetCallback) {
check();
return fenceHandler.prepareFence(xid, branchId, actionName, targetCallback);
}

@Override
public boolean commitFence(Method commitMethod, Object targetTCCBean, String xid, Long branchId, Object[] args) {
check();
return fenceHandler.commitFence(commitMethod, targetTCCBean, xid, branchId, args);
}

@Override
public boolean rollbackFence(Method rollbackMethod, Object targetTCCBean, String xid, Long branchId, Object[] args, String actionName) {
check();
return fenceHandler.rollbackFence(rollbackMethod, targetTCCBean, xid, branchId, args, actionName);
}

@Override
public int deleteFenceByDate(Date datetime) {
check();
return fenceHandler.deleteFenceByDate(datetime);
}
}
Loading

0 comments on commit c7fba75

Please sign in to comment.