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

ET集成Seata AT模式时,EtDataSourceManager类获取不到DataSourceProxy #160

Open
hiiloveyou opened this issue Mar 11, 2021 · 0 comments

Comments

@hiiloveyou
Copy link

hiiloveyou commented Mar 11, 2021

Describe the bug

//ET要求使用Spring管控下的事务,因此本方法可以获得对应的当前连接,获取当前连接来执行时为了避免争夺连接词的连接导致死锁
        DataSourceProxy dataSourceProxy = get(resourceId);
        ConnectionProxy cp = (ConnectionProxy) DataSourceUtils.getConnection(dataSourceProxy);
        Connection targetConnection = cp.getTargetConnection();

EtDataSourceManager类代码79行,DataSourceProxy dataSourceProxy = get(resourceId); dataSourceProxy为null

EtDataSourceManager的静态方法初始化时没有把 DataSourceProxy注册到EtDataSourceManager

 public static void initEtDataSourceManager() {
        DefaultResourceManager.get();
        DefaultResourceManager.mockResourceManager(BranchType.AT, new EtDataSourceManager());
        LOGGER.info("Trigger EtSeataDataSourceManager init!");
    }

由于使用了DefaultResourceManager.mockResourceManager(BranchType.AT, new EtDataSourceManager());,因此
EtDataSourceManager从父类的dataSourceCache获取DataSourceProxy时为空.

应该需要将DataSourceProxy资源再次注入到EtDataSourceManager。我试着改为如下方式可用

public static void initEtDataSourceManager() {
        final Map<String, Resource> resourceMap = DefaultResourceManager.get().getResourceManager(BranchType.AT).getManagedResources();
        DefaultResourceManager.mockResourceManager(BranchType.AT, new EtDataSourceManager());
        for (Map.Entry<String, Resource> entry : resourceMap.entrySet()) {
            DefaultResourceManager.get().registerResource(entry.getValue());
        }

        LOGGER.info("Trigger EtSeataDataSourceManager init!");
    }

我看issue之前有人提出过这个问题,希望能得到解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant