Skip to content

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

@hiiloveyou

Description

@hiiloveyou

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之前有人提出过这个问题,希望能得到解决

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions