Skip to content
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

optimize: solve spring and tcc dependency #4644

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f6f1b9e
solve spring and tcc dependency issue
sunrui1225 May 26, 2022
3b116b5
Merge branch 'develop' into feature_spring_tcc_dependency
sunrui1225 May 26, 2022
444e478
add Copyright
sunrui1225 May 28, 2022
6805106
Merge branch 'develop' into feature_spring_tcc_dependency
sunrui1225 Jun 2, 2022
b89d3a5
Merge branch 'develop' into feature_spring_tcc_dependency
sunrui1225 Jun 7, 2022
07e1a94
Merge branch 'develop' into feature_spring_tcc_dependency
funky-eyes Jul 4, 2022
927af96
fix add final to static method.
sunrui1225 Jul 5, 2022
ff7980d
fix check style.
sunrui1225 Jul 5, 2022
d88d30e
Merge branch 'develop' into feature_spring_tcc_dependency
wangliang181230 Jul 8, 2022
b717343
remove no used codes. rename method name.
sunrui1225 Jul 8, 2022
f8fbe59
Merge branch 'develop' into feature_spring_tcc_dependency
sunrui1225 Jul 8, 2022
cd17b70
Merge branch 'develop' into feature_spring_tcc_dependency
funky-eyes Jul 15, 2022
c08d092
Merge branch 'develop' into feature_spring_tcc_dependency
wangliang181230 Jul 21, 2022
cc48ff0
Merge branch 'develop' into feature_spring_tcc_dependency
wangliang181230 Jul 21, 2022
d7e5254
Merge remote-tracking branch 'origin/feature_spring_tcc_dependency' i…
sunrui1225 Jul 24, 2022
787d747
Merge branch 'develop' into feature_spring_tcc_dependency
sunrui1225 Jul 24, 2022
21b3054
Merge remote-tracking branch 'origin/feature_spring_tcc_dependency' i…
sunrui1225 Jul 24, 2022
14fe43a
syn update from saga annotation to this pr
sunrui1225 Jul 24, 2022
ae69922
Merge branch 'develop' into feature_spring_tcc_dependency
wangliang181230 Jul 26, 2022
912c925
Merge branch 'develop' into feature_spring_tcc_dependency
sunrui1225 Jul 29, 2022
df24269
Merge branch 'develop' into feature_spring_tcc_dependency
sunrui1225 Aug 3, 2022
d6cb132
Merge remote-tracking branch 'origin/develop' into spring_tcc_depende…
sunrui1225 Sep 22, 2022
06475ac
merge
sunrui1225 Sep 22, 2022
21a7a88
manual api draft
sunrui1225 Sep 24, 2022
067659b
fix RemotingParser file issue
sunrui1225 Sep 30, 2022
0904a1b
add java doc
sunrui1225 Oct 15, 2022
fbc3f24
add temporary TCCFenceHandler to resolve conflict
sunrui1225 Oct 15, 2022
a022866
Merge branch 'develop' into feature_spring_tcc_dependency
sunrui1225 Oct 15, 2022
b9b1f90
delite temporary TCCFenceHandler
sunrui1225 Oct 15, 2022
afbd0ae
Merge remote-tracking branch 'origin/feature_spring_tcc_dependency' i…
sunrui1225 Oct 15, 2022
119488e
add copyright
sunrui1225 Oct 15, 2022
30d759d
check style
sunrui1225 Oct 15, 2022
00e7666
check style
sunrui1225 Oct 15, 2022
a4d3eb8
fix build error
sunrui1225 Oct 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
<artifactId>seata-rm-datasource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-tcc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-rm</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
import io.seata.core.rpc.netty.TmNettyRemotingClient;
import io.seata.rm.RMClient;
import io.seata.spring.annotation.scannercheckers.PackageScannerChecker;
import io.seata.spring.tcc.TccActionInterceptor;
import io.seata.spring.autoproxy.DefaultTransactionAutoProxy;
import io.seata.spring.util.OrderUtil;
import io.seata.spring.util.SpringProxyUtils;
import io.seata.spring.util.TCCBeanParserUtils;
import io.seata.tm.TMClient;
import io.seata.tm.api.FailureHandler;
import org.aopalliance.aop.Advice;
Expand Down Expand Up @@ -261,7 +260,7 @@ private void registerSpringShutdownHook() {
* @see io.seata.rm.tcc.api.TwoPhaseBusinessAction // TCC annotation on try method
* @see io.seata.rm.tcc.remoting.RemotingParser // Remote TCC service parser
* Corresponding interceptor:
* @see io.seata.spring.tcc.TccActionInterceptor // the interceptor of TCC mode
* @see io.seata.rm.tcc.interceptor.TccActionInterceptor // the interceptor of TCC mode
*/
@Override
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
Expand All @@ -276,14 +275,11 @@ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey)
return bean;
}
interceptor = null;
wangliang181230 marked this conversation as resolved.
Show resolved Hide resolved
//check TCC proxy
if (TCCBeanParserUtils.isTccAutoProxy(bean, beanName, applicationContext)) {
// init tcc fence clean task if enable useTccFence
TCCBeanParserUtils.initTccFenceCleanTask(TCCBeanParserUtils.getRemotingDesc(beanName), applicationContext);
//TCC interceptor, proxy bean of sofa:reference/dubbo:reference, and LocalTCC
interceptor = new TccActionInterceptor(TCCBeanParserUtils.getRemotingDesc(beanName));
//check Transaction proxy
interceptor = DefaultTransactionAutoProxy.get().isTransactionAutoProxy(bean, beanName, applicationContext);
if (interceptor != null) {
ConfigurationCache.addConfigListener(ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION,
(ConfigurationChangeListener)interceptor);
(ConfigurationChangeListener) interceptor);
} else {
Class<?> serviceInterface = SpringProxyUtils.findTargetClass(bean);
Class<?>[] interfacesIfJdk = SpringProxyUtils.findInterfaces(bean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @see io.seata.spring.annotation.datasource.SeataAutoDataSourceProxyAdvice#invoke(MethodInvocation) io.seata.spring
* .annotation.datasource.SeataAutoDataSourceProxyAdvice#invoke(MethodInvocation)// RM: the interceptor of
* GlobalLockLogic and AT/XA mode
* @see io.seata.spring.tcc.TccActionInterceptor#invoke(MethodInvocation) io.seata.spring.tcc
* @see io.seata.rm.tcc.interceptor.TccActionInterceptor#invoke(MethodInvocation) io.seata.spring.tcc
* .TccActionInterceptor#invoke(MethodInvocation)// RM: the interceptor of TCC mode
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.spring.autoproxy;

import io.seata.common.loader.EnhancedServiceLoader;
import io.seata.common.util.CollectionUtils;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
* the default transaction auto proxy
*
* @author ruishansun
*/
public class DefaultTransactionAutoProxy {

/**
* all the transaction auto proxy
*/
protected static final List<TransactionAutoProxy> ALL_TRANSACTION_AUTO_PROXIES = new ArrayList<>();

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

/**
* Get the default transaction auto proxy
*
* @return the default transaction auto proxy
*/
public static DefaultTransactionAutoProxy get() {
return SingletonHolder.INSTANCE;
}

/**
* Instantiates a new default transaction auto proxy
*/
protected DefaultTransactionAutoProxy() {
initTransactionAutoProxy();
}

/**
* init transaction auto proxy
*/
private void initTransactionAutoProxy() {
List<TransactionAutoProxy> proxies = EnhancedServiceLoader.loadAll(TransactionAutoProxy.class);
if (CollectionUtils.isNotEmpty(proxies)) {
ALL_TRANSACTION_AUTO_PROXIES.addAll(proxies);
}
}

/**
* is transaction auto proxy ?
*
* @param bean the bean
* @param beanName the beanName
* @param applicationContext the applicationContext
* @return the MethodInterceptor or null
*/
public MethodInterceptor isTransactionAutoProxy(Object bean, String beanName, ApplicationContext applicationContext) {
for (TransactionAutoProxy proxy : ALL_TRANSACTION_AUTO_PROXIES) {
MethodInterceptor methodInterceptor = proxy.isTransactionAutoProxy(bean, beanName, applicationContext);
if (methodInterceptor != null) {
return methodInterceptor;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.spring.autoproxy;

import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.context.ApplicationContext;

/**
* The interface Transaction Auto Proxy.
* if result is not null, then proxied by tcc/saga with SPI.
*
* @author ruishansun
*/
public interface TransactionAutoProxy {

/**
* if it is transaction auto proxy? (tcc or saga)
*
* @param bean the bean
* @param beanName the beanName
* @param applicationContext the applicationContext
* @return the MethodInterceptor
*/
MethodInterceptor isTransactionAutoProxy(Object bean, String beanName, ApplicationContext applicationContext);
funky-eyes marked this conversation as resolved.
Show resolved Hide resolved
}
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.rm.tcc.remoting.parser;
package io.seata.spring.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Set;

import io.seata.common.util.CollectionUtils;
import io.seata.rm.tcc.remoting.parser.DubboUtil;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.AdvisedSupport;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.seata.rm.tcc.autoproxy.TccTransactionAutoProxy
5 changes: 5 additions & 0 deletions tcc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<artifactId>seata-rm</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.seata.rm.tcc.api;

import io.seata.rm.tcc.interceptor.TccActionInterceptor;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
Expand All @@ -29,7 +31,7 @@
* @author zhangsen
* @see io.seata.rm.tcc.api.LocalTCC // TCC annotation, which added on the TCC interface. It can't be left out.
* @see io.seata.spring.annotation.GlobalTransactionScanner#wrapIfNecessary(Object, String, Object) // the scanner for TM, GlobalLock, and TCC mode
* @see io.seata.spring.tcc.TccActionInterceptor // the interceptor of TCC mode
* @see TccActionInterceptor // the interceptor of TCC mode
* @see BusinessActionContext
* @see BusinessActionContextUtil
* @see BusinessActionContextParameter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.rm.tcc.autoproxy;

import io.seata.rm.tcc.interceptor.TCCBeanParserUtils;
import io.seata.rm.tcc.interceptor.TccActionInterceptor;
import io.seata.spring.autoproxy.TransactionAutoProxy;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.context.ApplicationContext;

/**
* the tcc implements of TransactionAutoProxy
*
* @author ruishansun
*/
public class TccTransactionAutoProxy implements TransactionAutoProxy {

@Override
public MethodInterceptor isTransactionAutoProxy(Object bean, String beanName, ApplicationContext applicationContext) {
if (TCCBeanParserUtils.isTccAutoProxy(bean, beanName, applicationContext)) {
// init tcc fence clean task if enable useTccFence
TCCBeanParserUtils.initTccFenceCleanTask(TCCBeanParserUtils.getRemotingDesc(beanName), applicationContext);
//TCC interceptor, proxy bean of sofa:reference/dubbo:reference, and LocalTCC
return new TccActionInterceptor(TCCBeanParserUtils.getRemotingDesc(beanName));
}
return null;
}
}
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.util;
package io.seata.rm.tcc.interceptor;

import io.seata.common.DefaultValues;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
Expand All @@ -22,7 +22,7 @@
import io.seata.rm.tcc.remoting.RemotingDesc;
import io.seata.rm.tcc.remoting.RemotingParser;
import io.seata.rm.tcc.remoting.parser.DefaultRemotingParser;
import io.seata.spring.tcc.TccActionInterceptor;
import io.seata.spring.util.SpringProxyUtils;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.context.ApplicationContext;

Expand Down
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.tcc;
package io.seata.rm.tcc.interceptor;

import java.lang.reflect.Method;
import javax.annotation.Nullable;
Expand All @@ -26,9 +26,8 @@
import io.seata.core.context.RootContext;
import io.seata.core.model.BranchType;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import io.seata.rm.tcc.interceptor.ActionInterceptorHandler;
import io.seata.rm.tcc.remoting.RemotingDesc;
import io.seata.rm.tcc.remoting.parser.DubboUtil;
import io.seata.spring.util.DubboUtil;
import io.seata.spring.util.SpringProxyUtils;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.spring.tcc;
package io.seata.rm.tcc.interceptor;

import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import io.seata.rm.tcc.remoting.RemotingDesc;
import io.seata.spring.util.TCCBeanParserUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
Expand Down
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.rm.tcc.spring;

/**
* The interface Business.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.spring.annotation;
package io.seata.rm.tcc.spring;

import io.seata.spring.annotation.GlobalTransactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
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.rm.tcc.spring;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.seata.rm.tcc.spring;

import io.seata.spring.annotation.GlobalTransactionScanner;

/**
* the subclass of GlobalTransactionScanner for test public method wrapIfNecessary
*/
public class GlobalTransactionScannerSub extends GlobalTransactionScanner {


public GlobalTransactionScannerSub(String txServiceGroup) {
super(txServiceGroup);
}

public Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
return super.wrapIfNecessary(bean, beanName, cacheKey);
}
}
Loading