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

bugfix: can't integrate dubbo with spring #6015

Merged
merged 17 commits into from
Nov 14, 2023

Conversation

xxxcrel
Copy link
Contributor

@xxxcrel xxxcrel commented Nov 10, 2023

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

fix(#6014)

Ⅱ. Does this pull request fix one issue?

fixes #6014

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@CLAassistant
Copy link

CLAassistant commented Nov 10, 2023

CLA assistant check
All committers have signed the CLA.

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Merging #6015 (770b77d) into 2.x (bbbbec7) will increase coverage by 0.00%.
The diff coverage is 26.08%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                2.x    #6015   +/-   ##
=========================================
  Coverage     49.57%   49.58%           
- Complexity     4747     4751    +4     
=========================================
  Files           907      907           
  Lines         31275    31284    +9     
  Branches       3770     3770           
=========================================
+ Hits          15506    15513    +7     
- Misses        14238    14244    +6     
+ Partials       1531     1527    -4     
Files Coverage Δ
...api/interceptor/parser/DefaultInterfaceParser.java 68.75% <100.00%> (ø)
...r/parser/GlobalTransactionalInterceptorParser.java 35.71% <ø> (ø)
...va/io/seata/integration/tx/api/util/ProxyUtil.java 66.66% <100.00%> (+1.66%) ⬆️
...interceptor/parser/TccActionInterceptorParser.java 64.51% <100.00%> (ø)
...tcc/resource/parser/TccRegisterResourceParser.java 84.90% <100.00%> (ø)
...erceptor/parser/DefaultResourceRegisterParser.java 0.00% <0.00%> (ø)
...va/io/seata/spring/tcc/TccAnnotationProcessor.java 0.00% <0.00%> (ø)
.../tx/api/remoting/parser/DefaultRemotingParser.java 0.00% <0.00%> (ø)
...ta/spring/annotation/GlobalTransactionScanner.java 10.79% <0.00%> (-0.13%) ⬇️
...ing/remoting/parser/RemotingFactoryBeanParser.java 0.00% <0.00%> (ø)

... and 6 files with indirect coverage changes

@funky-eyes funky-eyes added this to the 2.0.0 milestone Nov 11, 2023
@funky-eyes funky-eyes added type: bug Category issues or prs related to bug. module/spring spring module labels Nov 11, 2023
@funky-eyes funky-eyes added the first-time contributor first-time contributor label Nov 11, 2023
@xxxcrel
Copy link
Contributor Author

xxxcrel commented Nov 12, 2023

RemotingFactoryBeanParser的一些问题讨论
描述:目前2.x版本在集成spring的时候,因为spring和一些RPC框架机制的原因,有可能会需要拿到他的FactoryBean(因为原始的bean可能是生成的代理)再去交由其他的解析器进行真正的解析判断并获取相关RPC的信息,所以RemotingFactoryBeanParser需要先拿到FactoryBean再交给剩下的Parser去解析, 但是目前的设计中RemotingFactoryBeanParser还会被重新调用一次解析,这会造成一个死循环调用。
基于跟社区的讨论,目前有两种方案:

  1. 在RemotingFactoryBeanParser中增加一个缓存,当重新调用的时候快速判断并跳出,然后继续剩下的Parser的逻辑
  2. DefaultRemotingParser中增加isReference,isService, getServiceDesc的重构方法,后面都加上一个RemotingParser参数processedParser, 然后在后续Parser的遍历中跳过这个parser
    image

@xxxcrel
Copy link
Contributor Author

xxxcrel commented Nov 12, 2023

RemotingFactoryBeanParser的一些问题讨论 描述:目前2.x版本在集成spring的时候,因为spring和一些RPC框架机制的原因,有可能会需要拿到他的FactoryBean(因为原始的bean可能是生成的代理)再去交由其他的解析器进行真正的解析判断并获取相关RPC的信息,所以RemotingFactoryBeanParser需要先拿到FactoryBean再交给剩下的Parser去解析, 但是目前的设计中RemotingFactoryBeanParser还会被重新调用一次解析,这会造成一个死循环调用。 基于跟社区的讨论,目前有两种方案:

  1. 在RemotingFactoryBeanParser中增加一个缓存,当重新调用的时候快速判断并跳出,然后继续剩下的Parser的逻辑
  2. DefaultRemotingParser中增加isReference,isService, getServiceDesc的重构方法,后面都加上一个RemotingParser参数processedParser, 然后在后续Parser的遍历中跳过这个parser
    image

使用第一种方案目前能规避spring集成的这个问题, 但是之后可能其他的实现也会有类似的需求, 那就需要开发者时刻注意到这个问题

@xxxcrel xxxcrel changed the title bugfix: can't integrated dubbo with spring bugfix: can't integrate dubbo with spring Nov 13, 2023
Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.RemotingFactoryBeanParser 删除它的spi加载,改为在GlobalTransactionScanner#setApplicationContext中创建并赋值
2.DefaultRemotingParser增加addRemotingParser方法,将RemotingFactoryBeanParser放入allRemotingParsers
3.RemotingFactoryBeanParser#isReference中的 DefaultRemotingParser.get().isReference(bean, beanName); 改为 DefaultRemotingParser.get().isReference(factoryBean, factoryBeanName); 进行测试,是否会出现死循环,如果会则要进行接下来第四点的改造
4. RemotingFactoryBeanParser实例化的时候通过spi将其它4种实现加载,去除直接使用DefaultRemotingParser.get().isReference/isService方法,而是直接遍历4种实现的isReference/isService

import io.seata.integration.tx.api.remoting.RemotingDesc;
import io.seata.integration.tx.api.remoting.parser.AbstractedRemotingParser;
import io.seata.integration.tx.api.remoting.parser.DefaultRemotingParser;
import io.seata.spring.util.SpringProxyUtils;
import org.springframework.context.ApplicationContext;

import java.util.Collections;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introducing java-related packages should be placed at the top

@xxxcrel
Copy link
Contributor Author

xxxcrel commented Nov 13, 2023

1.RemotingFactoryBeanParser 删除它的spi加载,改为在GlobalTransactionScanner#setApplicationContext中创建并赋值 2.DefaultRemotingParser增加addRemotingParser方法,将RemotingFactoryBeanParser放入allRemotingParsers 3.RemotingFactoryBeanParser#isReference中的 DefaultRemotingParser.get().isReference(bean, beanName); 改为 DefaultRemotingParser.get().isReference(factoryBean, factoryBeanName); 进行测试,是否会出现死循环,如果会则要进行接下来第四点的改造 4. RemotingFactoryBeanParser实例化的时候通过spi将其它4种实现加载,去除直接使用DefaultRemotingParser.get().isReference/isService方法,而是直接遍历4种实现的isReference/isService

  1. 经过测试,使用beanFactoryName可以跳出循环

Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -22,7 +22,7 @@
*/
public interface InterfaceParser {

ProxyInvocationHandler parserInterfaceToProxy(Object target) throws Exception;
ProxyInvocationHandler parserInterfaceToProxy(Object target, String beanName) throws Exception;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.x 目前和spring解耦的,beanName是spring的定义。我们这里设置成objectName是不是更好,在spring的场景下:objectName = beanName

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* register custom remoting parser
* @param remotingParser
*/
public void registerRemotingParser(RemotingParser remotingParser) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注册方法最好加锁(因为可以牵扯到并发注册),或者使用copyOnwrite的方式

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -36,7 +40,7 @@ public class RemotingFactoryBeanParser extends AbstractedRemotingParser {
* @param beanName the bean name
* @return boolean boolean
*/
protected static Object getRemotingFactoryBean(Object bean, String beanName) {
protected Object getRemotingFactoryBean(Object bean, String beanName) {
Copy link
Contributor

@wt-better wt-better Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们是不是在构造方法里面加一个applicationContext!=null的check(防止一些spring异常场景,applicationContext没set进去),那么getRemotingFactoryBean里面的applicationContext!=null是可以去除掉的。

另外factoryBeanName的构建落在多个方法里面,是否能够抽出一个统一的方法

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@leezongjie leezongjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GLTM

@wt-better
Copy link
Contributor

LGTM

@funky-eyes funky-eyes merged commit abfafc3 into apache:2.x Nov 14, 2023
8 checks passed
@xxxcrel xxxcrel deleted the fix-spring-integration branch November 27, 2023 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first-time contributor first-time contributor module/spring spring module type: bug Category issues or prs related to bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can't integrated dubbo with spring in new seata version
5 participants